Skip to content

Add LocalTrackRecorder helper #1430

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 43 commits into from
May 23, 2025
Merged

Add LocalTrackRecorder helper #1430

merged 43 commits into from
May 23, 2025

Conversation

lukasIO
Copy link
Contributor

@lukasIO lukasIO commented Mar 6, 2025

built on top of MediaRecorder APIs, exposing the same base methods while wrapping it so that LocalTracks can be consumed directly with it.

Forshadowing that users might want to use it together with datastreams, we expose a byteStream on the LocalTrackRecorder.

standalone recorder usage

const recorder = new LocalTrackRecorder(state.microphoneTrack);
recorder.start();
const audioChunks = []

for await (const chunk of recorder.byteStream) {
  audioChunks.push(chunk);
  // loop completes once `recorder.stop()` is called or an error occurs
}

preconnect buffer usage

async function instantAudioConnect() {
  await Promise.all(room.connect(...), room.localParticipant.setMicrophoneEnabled(true, undefined, { preConnectBuffer: true }));
}

Copy link

changeset-bot bot commented Mar 6, 2025

🦋 Changeset detected

Latest commit: f20f7cf

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

This PR includes changesets to release 1 package
Name Type
livekit-client 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

Copy link
Contributor

github-actions bot commented Mar 6, 2025

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 78.01 KB (+1.19% 🔺)
dist/livekit-client.umd.js 83.82 KB (+1.1% 🔺)

@lukasIO lukasIO changed the title Add LocalAudioRecorder helper Add LocalTrackRecorder helper Mar 6, 2025
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.

this makes a lot of sense. can you also sync up with @pblazej who is going to start looking at the data stream side of it in swift so we can get this up to agents. more spec/description in the linear project

@pblazej
Copy link

pblazej commented Mar 7, 2025

@bcherry IMO, we can replicate this quite easily in Swift as the basic building block for pre-recording.

Sending via data streams is also doable, I already started playing with it.

We need 3 layers here:

  • LocalTrackRecorder as described here
  • PreConnectRecorder that wraps track recorder + handles the room/participant state machine (recording/sending etc.) - if we really need it as a built-in abstraction in the SDK
  • a way to expose PreConnectRecorder it via Room.connect

All of them internal for now till we solidify the API.

The hard part is what I called PreConnectRecorder, we need all the backend questions asked by @lukasIO answered first to make it happen. I already did a very naive version "on connect", but that's not what we want in production.

@bcherry
Copy link
Contributor

bcherry commented Mar 7, 2025

@pblazej yeah the goal is definitely make as much of this "built-in" as possible, both here and in agents.

@lukasIO lukasIO marked this pull request as ready for review April 8, 2025 14:53
@lukasIO lukasIO requested review from bcherry and pblazej May 15, 2025 14:23
@lukasIO lukasIO requested a review from davidzhao May 15, 2025 15:36
@lukasIO lukasIO merged commit e37ed3d into main May 23, 2025
6 checks passed
@lukasIO lukasIO deleted the lukas/local-record branch May 23, 2025 07:06
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.

3 participants