-
Notifications
You must be signed in to change notification settings - Fork 134
Data streams #593
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
Data streams #593
Conversation
Public wrappers around protocol-level types
Use protocol default implementations instead
Throw errors as appropriate
- When possible, prefer using compiler synthesized methods for async/throwing methods - Also mark deprecated instead of unavailable
for JS the We don't want to depend on when the reader is being awaited as a signal to accept/discard the stream. Registering the handler on the room is showing a user's intent to process the streams already. |
That makes sense, thanks for the clarification. I’ll update the Swift implementation to match this behavior. |
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.
lgtm and thank you for including thorough docstrings!
- Open streams immediately after header is received instead of waiting for handler. - Run handler in a detached task. - Simplify handler resolution.
The issue is now fixed. @lukasIO, I would appreciate your feedback on the new method I added to stream reader. This method allows the user to incrementally write a file to disk as it is received, returning its path once the entire file is received: try await room.localParticipant
.registerByteStreamHandler(for: "my-topic") { reader, participantIdentity in
let fileURL = try await reader.readToFile()
print("Wrote file to: \(fileURL)")
} By default, this method writes to the system temporary directory, and chooses the file name and extension by inspecting the name and MIME type fields from the stream header. Additional overloads also exist which allow the user to customize the destination directory and override the file name. |
that's a nice addition! |
I agree; I've renamed it to |
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.
linting CI seems to be failing still, but lgtm otherwise! nice job!
Call send method on room which waits for data channel to become open.
Parent task is already detached
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.
Nice, tested it with the example app. ✅
/// cannot be sent to remote participants. | ||
/// | ||
public func write(_ text: String) async throws { | ||
try await destination.write(Data(text.utf8)) |
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.
@ladvoc sorry, missed this before, this is missing utf8 multi byte character splitting.
We want to ensure that for text, a utf8 character isn't arbitrarily split in half by chunking it. JS does this here https://github.com/livekit/client-sdk-js/blob/main/src/room/utils.ts#L629-L652
Summary of changes
Differences from other SDKs
IncomingStreamManager
andOutgoingStreamManager
to allow detection of errors (e.g. duplicate stream ID).