Skip to content

Commit be8fa59

Browse files
committed
write to disk in example and fix asyncio bug
1 parent b134299 commit be8fa59

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

examples/data-streams/data_streams.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ async def on_welcome_image_received(
4141
logger.info(
4242
"Received image from %s: '%s'", participant_identity, reader.info["name"]
4343
)
44+
with open(reader.info["name"], mode="wb") as f:
45+
async for chunk in reader:
46+
f.write(chunk)
47+
48+
f.close()
4449

4550
@room.on("participant_connected")
4651
def on_participant_connected(participant: rtc.RemoteParticipant):
@@ -76,7 +81,10 @@ def on_participant_connected(participant: rtc.RemoteParticipant):
7681
if __name__ == "__main__":
7782
logging.basicConfig(
7883
level=logging.INFO,
79-
handlers=[logging.FileHandler("basic_room.log"), logging.StreamHandler()],
84+
handlers=[
85+
logging.FileHandler("data_stream_example.log"),
86+
logging.StreamHandler(),
87+
],
8088
)
8189

8290
loop = asyncio.get_event_loop()

livekit-rtc/livekit/rtc/room.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,9 @@ def _on_room_event(self, event: proto_room.RoomEvent):
747747
event.stream_header_received.participant_identity,
748748
)
749749
elif which == "stream_chunk_received":
750-
asyncio.run(self._handle_stream_chunk(event.stream_chunk_received.chunk))
750+
asyncio.gather(self._handle_stream_chunk(event.stream_chunk_received.chunk))
751751
elif which == "stream_trailer_received":
752-
asyncio.run(
752+
asyncio.gather(
753753
self._handle_stream_trailer(event.stream_trailer_received.trailer)
754754
)
755755

0 commit comments

Comments
 (0)