Skip to content

Commit 6b3bf8e

Browse files
debug participant
1 parent 03744fb commit 6b3bf8e

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ async def main():
139139
print(f"\ttrack id: {publication}")
140140
```
141141

142+
### Debug participant
143+
144+
Use [`debug_participant.py`](debug_participant.py) to connect to a room from the
145+
command line and log participant and data track events.
146+
147+
Run it with:
148+
149+
```shell
150+
$ python debug_participant.py --url "$LIVEKIT_URL" --token "$LIVEKIT_TOKEN"
151+
```
152+
142153
### RPC
143154

144155
Perform your own predefined method calls from one participant to another.

debug_participant.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import argparse
2+
import asyncio
3+
import logging
4+
import signal
5+
6+
from livekit import rtc
7+
8+
9+
async def main() -> None:
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("--url", required=True, help="LiveKit server URL")
12+
parser.add_argument("--token", required=True, help="LiveKit access token")
13+
args = parser.parse_args()
14+
15+
logging.basicConfig(level=logging.INFO)
16+
logger = logging.getLogger("debug-participant")
17+
18+
room = rtc.Room()
19+
stop_event = asyncio.Event()
20+
21+
@room.on("participant_connected")
22+
def on_participant_connected(participant: rtc.RemoteParticipant) -> None:
23+
logger.info(
24+
"participant connected: sid=%s identity=%s",
25+
participant.sid,
26+
participant.identity,
27+
)
28+
29+
@room.on("participant_disconnected")
30+
def on_participant_disconnected(participant: rtc.RemoteParticipant) -> None:
31+
logger.info(
32+
"participant disconnected: sid=%s identity=%s",
33+
participant.sid,
34+
participant.identity,
35+
)
36+
37+
@room.on("data_track_published")
38+
def on_data_track_published(track: rtc.RemoteDataTrack) -> None:
39+
logger.info(
40+
"data track published: sid=%s name=%s publisher=%s",
41+
track.info.sid,
42+
track.info.name,
43+
track.publisher_identity,
44+
)
45+
46+
@room.on("data_track_unpublished")
47+
def on_data_track_unpublished(track_sid: str) -> None:
48+
logger.info("data track unpublished: sid=%s", track_sid)
49+
50+
loop = asyncio.get_running_loop()
51+
for sig in (signal.SIGINT, signal.SIGTERM):
52+
loop.add_signal_handler(sig, stop_event.set)
53+
54+
await room.connect(args.url, args.token)
55+
logger.info("connected to room: %s", room.name)
56+
57+
for participant in room.remote_participants.values():
58+
logger.info(
59+
"participant already in room: sid=%s identity=%s",
60+
participant.sid,
61+
participant.identity,
62+
)
63+
64+
try:
65+
await stop_event.wait()
66+
finally:
67+
await room.disconnect()
68+
69+
70+
if __name__ == "__main__":
71+
asyncio.run(main())

0 commit comments

Comments
 (0)