-
Notifications
You must be signed in to change notification settings - Fork 112
Add data stream support #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
a3aa0a0
Add data stream support
lukasIO b32ebc9
generated protobuf
github-actions[bot] f3dc6b6
return info on file send
lukasIO e04c6e3
expose stream_file
lukasIO 0fa62f9
split written data into chunks
lukasIO 758060a
intendation
lukasIO 8db05c2
fix chunk size
lukasIO e311a53
fix imports
lukasIO 61eb7fd
add write lock to file streams
lukasIO 318b8d4
add send_file method
lukasIO 15f100c
add explicit return types
lukasIO a506295
Add index to textstreamupdate
lukasIO ed2d981
add aiofiles to setup requirements
lukasIO 585a220
fix protocol trailer implementation
lukasIO 521179d
add read_all method for text streams
lukasIO df4de63
fix bugs and add text stream example
lukasIO 0eeaa3f
generated protobuf
github-actions[bot] 84f286c
update rust sdk
lukasIO 6da1b83
fix proto
lukasIO 3c2a980
generated protobuf
github-actions[bot] ff8aa7b
bump rust-ffi and split utf8 string properly
lukasIO 8942fea
Merge branch 'lukas/data-streams' of https://github.com/livekit/pytho…
lukasIO b68d21a
Update naming
lukasIO e6c6576
generated protobuf
github-actions[bot] 1b6f3a2
stream handlers and address comments
lukasIO 5d16a05
Merge branch 'lukas/data-streams' of https://github.com/livekit/pytho…
lukasIO 5ef54c8
fix interop
lukasIO cb8c32e
update lfs settings
lukasIO a3b34f6
add example asset
lukasIO bc5e695
point submodule to latest ffi release
lukasIO 0989149
dedicated method to remove handlers
lukasIO 464a6f8
Update livekit-rtc/livekit/rtc/data_stream.py
lukasIO ad21259
Update livekit-rtc/livekit/rtc/data_stream.py
lukasIO fde9e30
Update livekit-rtc/livekit/rtc/participant.py
lukasIO c5e6c3c
replace RingQueue with asyncio.Queue
lukasIO 9e7974a
Merge branch 'lukas/data-streams' of https://github.com/livekit/pytho…
lukasIO b134299
update async stuff
lukasIO be8fa59
write to disk in example and fix asyncio bug
lukasIO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| **/*.dll filter=lfs diff=lfs merge=lfs -text | ||
| **/*.so filter=lfs diff=lfs merge=lfs -text | ||
| **/*.dylib filter=lfs diff=lfs merge=lfs -text | ||
| **/*.jpg filter=lfs diff=lfs merge=lfs -text | ||
| livekit-protocol/livekit/protocol/** linguist-generated=true | ||
| livekit-rtc/livekit/rtc/_proto/** linguist-generated=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import os | ||
| import logging | ||
| import asyncio | ||
| from signal import SIGINT, SIGTERM | ||
| from livekit import rtc | ||
|
|
||
| # Set the following environment variables with your own values | ||
| TOKEN = os.environ.get("LIVEKIT_TOKEN") | ||
| URL = os.environ.get("LIVEKIT_URL") | ||
|
|
||
|
|
||
| async def main(room: rtc.Room): | ||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| async def greetParticipant(identity: str): | ||
| text_writer = await room.local_participant.stream_text( | ||
| destination_identities=[identity], topic="chat" | ||
| ) | ||
| for char in "Hi! Just a friendly message": | ||
| await text_writer.write(char) | ||
| await text_writer.aclose() | ||
|
|
||
| await room.local_participant.send_file( | ||
| "./green_tree_python.jpg", | ||
| destination_identities=[identity], | ||
| topic="welcome", | ||
| ) | ||
|
|
||
| async def on_chat_message_received( | ||
| reader: rtc.TextStreamReader, participant_identity: str | ||
| ): | ||
| full_text = await reader.read_all() | ||
| logger.info( | ||
| "Received chat message from %s: '%s'", participant_identity, full_text | ||
| ) | ||
|
|
||
| async def on_welcome_image_received( | ||
| reader: rtc.ByteStreamReader, participant_identity: str | ||
| ): | ||
| logger.info( | ||
| "Received image from %s: '%s'", participant_identity, reader.info["name"] | ||
| ) | ||
| with open(reader.info["name"], mode="wb") as f: | ||
| async for chunk in reader: | ||
| f.write(chunk) | ||
|
|
||
| f.close() | ||
|
|
||
| @room.on("participant_connected") | ||
| def on_participant_connected(participant: rtc.RemoteParticipant): | ||
| logger.info( | ||
| "participant connected: %s %s", participant.sid, participant.identity | ||
| ) | ||
| asyncio.create_task(greetParticipant(participant.identity)) | ||
|
|
||
| room.set_text_stream_handler( | ||
| lambda reader, participant_identity: asyncio.create_task( | ||
| on_chat_message_received(reader, participant_identity) | ||
| ), | ||
| "chat", | ||
| ) | ||
|
|
||
| room.set_byte_stream_handler( | ||
| lambda reader, participant_identity: asyncio.create_task( | ||
| on_welcome_image_received(reader, participant_identity) | ||
| ), | ||
| "welcome", | ||
| ) | ||
|
|
||
| # By default, autosubscribe is enabled. The participant will be subscribed to | ||
| # all published tracks in the room | ||
| await room.connect(URL, TOKEN) | ||
| logger.info("connected to room %s", room.name) | ||
|
|
||
| for identity, participant in room.remote_participants.items(): | ||
| logger.info("Sending a welcome message to %s", identity) | ||
| await greetParticipant(participant.identity) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| logging.basicConfig( | ||
| level=logging.INFO, | ||
| handlers=[ | ||
| logging.FileHandler("data_stream_example.log"), | ||
| logging.StreamHandler(), | ||
| ], | ||
| ) | ||
|
|
||
| loop = asyncio.get_event_loop() | ||
| room = rtc.Room(loop=loop) | ||
|
|
||
| async def cleanup(): | ||
| await room.disconnect() | ||
| loop.stop() | ||
|
|
||
| asyncio.ensure_future(main(room)) | ||
| for signal in [SIGINT, SIGTERM]: | ||
| loop.add_signal_handler(signal, lambda: asyncio.ensure_future(cleanup())) | ||
|
|
||
| try: | ||
| loop.run_forever() | ||
| finally: | ||
| loop.close() | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be good to include some comments on what this example demonstrates, and what other components the user should prepare for in order to see a demo.
it seems like it's built to work with the JS example?