-
Notifications
You must be signed in to change notification settings - Fork 311
Move frame processor url/token/stream info to client sdk #1881
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,15 @@ | |
| import { | ||
| type AudioFrame, | ||
| AudioStream, | ||
| FrameProcessor, | ||
| type FrameProcessor, | ||
| type NoiseCancellationOptions, | ||
| RemoteParticipant, | ||
| type RemoteTrack, | ||
| type RemoteTrackPublication, | ||
| type Room, | ||
| RoomEvent, | ||
| TrackSource, | ||
| isFrameProcessor, | ||
| } from '@livekit/rtc-node'; | ||
| import type { ReadableStream } from 'node:stream/web'; | ||
| import { log } from '../../log.js'; | ||
|
|
@@ -44,15 +45,14 @@ export class ParticipantAudioInputStream extends AudioInput { | |
| this.room = room; | ||
| this.sampleRate = sampleRate; | ||
| this.numChannels = numChannels; | ||
| if (noiseCancellation instanceof FrameProcessor) { | ||
| if (isFrameProcessor<FrameProcessor<AudioFrame>>(noiseCancellation)) { | ||
| this.frameProcessor = noiseCancellation; | ||
| } else { | ||
| this.noiseCancellation = noiseCancellation; | ||
| } | ||
|
|
||
| this.room.on(RoomEvent.TrackSubscribed, this.onTrackSubscribed); | ||
| this.room.on(RoomEvent.TrackUnpublished, this.onTrackUnpublished); | ||
| this.room.on(RoomEvent.TokenRefreshed, this.onTokenRefreshed); | ||
| } | ||
|
|
||
| setParticipant(participant: RemoteParticipant | string | null) { | ||
|
|
@@ -153,40 +153,25 @@ export class ParticipantAudioInputStream extends AudioInput { | |
| outputRate: this.sampleRate, | ||
| }), | ||
| ); | ||
| this.frameProcessor?.onStreamInfoUpdated({ | ||
| participantIdentity: participant.identity, | ||
| roomName: this.room.name!, | ||
| publicationSid: publication.sid!, | ||
| }); | ||
| this.frameProcessor?.onCredentialsUpdated({ | ||
| token: this.room.token!, | ||
| url: this.room.serverUrl!, | ||
| }); | ||
| return true; | ||
| }; | ||
|
|
||
| private onTokenRefreshed = () => { | ||
| if (this.room.token && this.room.serverUrl) { | ||
| this.frameProcessor?.onCredentialsUpdated({ | ||
| token: this.room.token, | ||
| url: this.room.serverUrl, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| private createStream(track: RemoteTrack): ReadableStream<AudioFrame> { | ||
| return new AudioStream(track, { | ||
| sampleRate: this.sampleRate, | ||
| numChannels: this.numChannels, | ||
| noiseCancellation: this.frameProcessor || this.noiseCancellation, | ||
| // Don't let the AudioStream close the processor when the track switches — | ||
| // this input stream owns the processor across track changes and closes it | ||
| // itself in close(). | ||
| autoCloseNoiseCancellation: false, | ||
| // TODO(AJS-269): resolve compatibility issue with node-sdk to remove the forced type casting | ||
| }) as unknown as ReadableStream<AudioFrame>; | ||
|
Comment on lines
159
to
169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Removal of onStreamInfoUpdated/onCredentialsUpdated depends on rtc-node handling them internally The old code explicitly called Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| override async close() { | ||
| this.room.off(RoomEvent.TrackSubscribed, this.onTrackSubscribed); | ||
| this.room.off(RoomEvent.TrackUnpublished, this.onTrackUnpublished); | ||
| this.room.off(RoomEvent.TokenRefreshed, this.onTokenRefreshed); | ||
| this.closeStream(); | ||
| await super.close(); | ||
|
|
||
|
|
||
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.
🚩 autoCloseNoiseCancellation is a new option that must be supported by the rtc-node SDK
The
autoCloseNoiseCancellation: falseoption at_input.ts:167is passed to theAudioStreamconstructor. This option doesn't appear anywhere else in this repository — it's a new SDK feature. The catalog pins@livekit/rtc-nodeto^0.13.27. If this option was only added in a newer minor/patch version not yet published, the option would be silently ignored (since JS doesn't validate extra constructor options), and theAudioStreamwould still auto-close the processor on track switches, leading to a use-after-close when the next track tries to use the same processor. Worth confirming the SDK version supports this flag.Was this helpful? React with 👍 or 👎 to provide feedback.