Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhao committed Dec 4, 2024
1 parent 28e64ef commit 92dda3b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions examples/room_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
TOKEN = os.environ.get("LIVEKIT_TOKEN")
URL = os.environ.get("LIVEKIT_URL")


async def main():
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
room = rtc.Room()

@room.on("participant_connected")
def on_participant_connected(participant: rtc.RemoteParticipant):
logging.info(
"participant connected: %s %s", participant.sid, participant.identity)
logger.info(
"participant connected: %s %s", participant.sid, participant.identity
)

async def receive_frames(stream: rtc.VideoStream):
async for frame in stream:
Expand All @@ -24,16 +26,20 @@ async def receive_frames(stream: rtc.VideoStream):

# track_subscribed is emitted whenever the local participant is subscribed to a new track
@room.on("track_subscribed")
def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant):
logging.info("track subscribed: %s", publication.sid)
def on_track_subscribed(
track: rtc.Track,
publication: rtc.RemoteTrackPublication,
participant: rtc.RemoteParticipant,
):
logger.info("track subscribed: %s", publication.sid)
if track.kind == rtc.TrackKind.KIND_VIDEO:
video_stream = rtc.VideoStream(track)
asyncio.ensure_future(receive_frames(video_stream))

# By default, autosubscribe is enabled. The participant will be subscribed to
# all published tracks in the room
await room.connect(URL, TOKEN)
logging.info("connected to room %s", room.name)
logger.info("connected to room %s", room.name)

for identity, participant in room.remote_participants.items():
print(f"identity: {identity}")
Expand All @@ -43,7 +49,8 @@ def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublicatio
print(f"participant identity: {participant.identity}")
print(f"participant name: {participant.name}")
print(f"participant kind: {participant.kind}")
print(f"participant track publications: {participant.track_publications}")
print(f"participant track publications: {
participant.track_publications}")
for tid, publication in participant.track_publications.items():
print(f"\ttrack id: {tid}")
print(f"\t\ttrack publication: {publication}")
Expand All @@ -52,7 +59,6 @@ def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublicatio
print(f"\t\ttrack source: {publication.source}")

print(f"participant metadata: {participant.metadata}")



if __name__ == "__main__":
Expand All @@ -62,4 +68,3 @@ def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublicatio
exit(1)

asyncio.run(main())

0 comments on commit 92dda3b

Please sign in to comment.