Skip to content
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

Add data stream support #361

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Add data stream support #361

wants to merge 35 commits into from

Conversation

lukasIO
Copy link
Contributor

@lukasIO lukasIO commented Dec 17, 2024

depends on livekit/rust-sdks#533

writing stream:

thoughts about writing: for STT we need a way to optionally also override the chunk index with this API

const greeting = 'Hi this is just a text sample';
  const streamWriter = await room.localParticipant?.streamText({
    destinationIdentities: [recipient.identity],
    topic: "chat"
  });

  for (const c of greeting) {
    await streamWriter.write(c);
// for overriding the chunk Id, you'd simply have a second value in the write method
//     await streamWriter.write(c, myChunkIndex);

  }

  await streamWriter?.close();

reading stream:

room.setTextStreamHandler(async (reader: TextStreamReader) => 
    for await (const { current } of reader) {
      console.log(current);
    }
    // whole stream content
    console.log(await reader.readAll());
  }, "chat");

Copy link

changeset-bot bot commented Dec 17, 2024

🦋 Changeset detected

Latest commit: 2918189

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@livekit/rtc-node Patch
@livekit/rtc-node-darwin-arm64 Patch
@livekit/rtc-node-darwin-x64 Patch
@livekit/rtc-node-linux-arm64-gnu Patch
@livekit/rtc-node-linux-x64-gnu Patch
@livekit/rtc-node-win32-x64-msvc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lukasIO lukasIO marked this pull request as draft December 17, 2024 14:43
@lukasIO lukasIO changed the title Add data stream receiving Add data stream support Dec 20, 2024
@lukasIO lukasIO marked this pull request as ready for review December 20, 2024 15:17
Copy link
Contributor

@bcherry bcherry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add docstrings to all of the exported classes? There's also at least one error handling TODO left in here still.

Looks good and thank you for including an example!

@lukasIO
Copy link
Contributor Author

lukasIO commented Dec 22, 2024

Can you add docstrings to all of the exported classes?

added some, the annoying thing however is that docstrings don't show up on class instances. And we're only returning class instances to users, so they won't really profit from them.

There's also at least one error handling TODO left in here still

errors are currently being logged to console, the TODO is in there for later improvements around re-requesting missing chunks or similar repair mechanisms. Deleted the TODOs

@lukasIO lukasIO requested a review from bcherry January 8, 2025 09:48
examples/data-streams/index.ts Outdated Show resolved Hide resolved
examples/data-streams/index.ts Outdated Show resolved Hide resolved
examples/data-streams/index.ts Show resolved Hide resolved

const sendFile = async (room: Room, recipient: RemoteParticipant) => {
console.log('sending file');
await room.localParticipant?.sendFile('./assets/maybemexico.png', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file doesn't exist, but when i added one and ran the example i got a rust panic

sending file
thread '<unnamed>' panicked at src/nodejs.rs:55:13:
failed to handle request: invalid request: message is empty
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants