77TOKEN = os .environ .get ("LIVEKIT_TOKEN" )
88URL = os .environ .get ("LIVEKIT_URL" )
99
10+
1011async def main ():
1112 logging .basicConfig (level = logging .INFO )
1213 logger = logging .getLogger (__name__ )
1314 room = rtc .Room ()
1415
1516 @room .on ("participant_connected" )
1617 def on_participant_connected (participant : rtc .RemoteParticipant ):
17- logging .info (
18- "participant connected: %s %s" , participant .sid , participant .identity )
18+ logger .info (
19+ "participant connected: %s %s" , participant .sid , participant .identity
20+ )
1921
2022 async def receive_frames (stream : rtc .VideoStream ):
2123 async for frame in stream :
@@ -24,16 +26,20 @@ async def receive_frames(stream: rtc.VideoStream):
2426
2527 # track_subscribed is emitted whenever the local participant is subscribed to a new track
2628 @room .on ("track_subscribed" )
27- def on_track_subscribed (track : rtc .Track , publication : rtc .RemoteTrackPublication , participant : rtc .RemoteParticipant ):
28- logging .info ("track subscribed: %s" , publication .sid )
29+ def on_track_subscribed (
30+ track : rtc .Track ,
31+ publication : rtc .RemoteTrackPublication ,
32+ participant : rtc .RemoteParticipant ,
33+ ):
34+ logger .info ("track subscribed: %s" , publication .sid )
2935 if track .kind == rtc .TrackKind .KIND_VIDEO :
3036 video_stream = rtc .VideoStream (track )
3137 asyncio .ensure_future (receive_frames (video_stream ))
3238
3339 # By default, autosubscribe is enabled. The participant will be subscribed to
3440 # all published tracks in the room
3541 await room .connect (URL , TOKEN )
36- logging .info ("connected to room %s" , room .name )
42+ logger .info ("connected to room %s" , room .name )
3743
3844 for identity , participant in room .remote_participants .items ():
3945 print (f"identity: { identity } " )
@@ -43,7 +49,8 @@ def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublicatio
4349 print (f"participant identity: { participant .identity } " )
4450 print (f"participant name: { participant .name } " )
4551 print (f"participant kind: { participant .kind } " )
46- print (f"participant track publications: { participant .track_publications } " )
52+ print (f"participant track publications: {
53+ participant .track_publications } " )
4754 for tid , publication in participant .track_publications .items ():
4855 print (f"\t track id: { tid } " )
4956 print (f"\t \t track publication: { publication } " )
@@ -52,7 +59,6 @@ def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublicatio
5259 print (f"\t \t track source: { publication .source } " )
5360
5461 print (f"participant metadata: { participant .metadata } " )
55-
5662
5763
5864if __name__ == "__main__" :
@@ -62,4 +68,3 @@ def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublicatio
6268 exit (1 )
6369
6470 asyncio .run (main ())
65-
0 commit comments