@livekit/rtc-node 0.13.29 → 0.13.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audio_stream-B4hGVcKz.d.cts +498 -0
- package/dist/audio_stream-DEG1JKge.d.ts +498 -0
- package/dist/audio_stream.cjs +21 -6
- package/dist/audio_stream.cjs.map +1 -1
- package/dist/audio_stream.d.cts +12 -22
- package/dist/audio_stream.d.ts +12 -22
- package/dist/audio_stream.d.ts.map +1 -1
- package/dist/audio_stream.js +19 -5
- package/dist/audio_stream.js.map +1 -1
- package/dist/data_streams/index.d.cts +1 -1
- package/dist/data_streams/index.d.ts +1 -1
- package/dist/data_streams/stream_reader.d.cts +1 -1
- package/dist/data_streams/stream_reader.d.ts +1 -1
- package/dist/data_streams/stream_writer.d.cts +1 -1
- package/dist/data_streams/stream_writer.d.ts +1 -1
- package/dist/data_streams/types.d.cts +1 -1
- package/dist/data_streams/types.d.ts +1 -1
- package/dist/frame_processor.cjs +6 -0
- package/dist/frame_processor.cjs.map +1 -1
- package/dist/frame_processor.d.cts +2 -0
- package/dist/frame_processor.d.ts +2 -0
- package/dist/frame_processor.d.ts.map +1 -1
- package/dist/frame_processor.js +6 -0
- package/dist/frame_processor.js.map +1 -1
- package/dist/index.d.cts +4 -7
- package/dist/index.d.ts +4 -7
- package/dist/participant.cjs +6 -0
- package/dist/participant.cjs.map +1 -1
- package/dist/participant.d.cts +14 -153
- package/dist/participant.d.ts +14 -153
- package/dist/participant.d.ts.map +1 -1
- package/dist/participant.js +6 -0
- package/dist/participant.js.map +1 -1
- package/dist/room.cjs +28 -0
- package/dist/room.cjs.map +1 -1
- package/dist/room.d.cts +12 -221
- package/dist/room.d.ts +12 -221
- package/dist/room.d.ts.map +1 -1
- package/dist/room.js +28 -0
- package/dist/room.js.map +1 -1
- package/dist/track.cjs +123 -0
- package/dist/track.cjs.map +1 -1
- package/dist/track.d.cts +15 -42
- package/dist/track.d.ts +15 -42
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +123 -0
- package/dist/track.js.map +1 -1
- package/dist/track_publication.d.cts +14 -47
- package/dist/track_publication.d.ts +14 -47
- package/dist/{stream_reader-CuG4b8Y-.d.cts → types-_PdPVish.d.cts} +40 -40
- package/dist/{stream_reader-CuG4b8Y-.d.ts → types-_PdPVish.d.ts} +40 -40
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/video_stream.d.cts +12 -2
- package/dist/video_stream.d.ts +12 -2
- package/package.json +3 -3
- package/src/audio_stream.ts +28 -4
- package/src/audio_stream_room_lifecycle.test.ts +753 -0
- package/src/bun_runtime.test.ts +27 -0
- package/src/frame_processor.ts +4 -0
- package/src/participant.ts +17 -0
- package/src/room.ts +44 -0
- package/src/track.ts +141 -0
- package/src/version.ts +1 -1
package/src/audio_stream.ts
CHANGED
|
@@ -13,6 +13,13 @@ import type { Track } from './track.js';
|
|
|
13
13
|
|
|
14
14
|
export interface AudioStreamOptions {
|
|
15
15
|
noiseCancellation?: NoiseCancellationOptions | FrameProcessor<AudioFrame>;
|
|
16
|
+
/**
|
|
17
|
+
* When the audio stream closes, whether to run the {@link FrameProcessor}'s
|
|
18
|
+
* `close()` method. If `false`, the processor is left open so it can be
|
|
19
|
+
* reused with another {@link AudioStream}. Only relevant when
|
|
20
|
+
* `noiseCancellation` is a {@link FrameProcessor}. Defaults to `true`.
|
|
21
|
+
*/
|
|
22
|
+
autoCloseNoiseCancellation?: boolean;
|
|
16
23
|
sampleRate?: number;
|
|
17
24
|
numChannels?: number;
|
|
18
25
|
frameSizeMs?: number;
|
|
@@ -24,26 +31,31 @@ export interface NoiseCancellationOptions {
|
|
|
24
31
|
options: Record<string, any>;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
/** @internal */
|
|
35
|
+
export class AudioStreamSource implements UnderlyingSource<AudioFrame> {
|
|
28
36
|
private controller?: ReadableStreamDefaultController<AudioFrame>;
|
|
29
37
|
private ffiHandle: FfiHandle;
|
|
30
38
|
private disposed = false;
|
|
31
39
|
private sampleRate: number;
|
|
32
40
|
private numChannels: number;
|
|
33
41
|
private legacyNcOptions?: NoiseCancellationOptions;
|
|
34
|
-
private frameProcessor
|
|
42
|
+
private frameProcessor: FrameProcessor<AudioFrame> | null = null;
|
|
43
|
+
private autoCloseProcessor = true;
|
|
35
44
|
private frameSizeMs?: number;
|
|
45
|
+
private track: Track;
|
|
36
46
|
|
|
37
47
|
constructor(
|
|
38
48
|
track: Track,
|
|
39
49
|
sampleRateOrOptions?: number | AudioStreamOptions,
|
|
40
50
|
numChannels?: number,
|
|
41
51
|
) {
|
|
52
|
+
this.track = track;
|
|
42
53
|
if (sampleRateOrOptions !== undefined && typeof sampleRateOrOptions !== 'number') {
|
|
43
54
|
this.sampleRate = sampleRateOrOptions.sampleRate ?? 48000;
|
|
44
55
|
this.numChannels = sampleRateOrOptions.numChannels ?? 1;
|
|
45
56
|
if (isFrameProcessor(sampleRateOrOptions.noiseCancellation)) {
|
|
46
57
|
this.frameProcessor = sampleRateOrOptions.noiseCancellation;
|
|
58
|
+
this.autoCloseProcessor = sampleRateOrOptions.autoCloseNoiseCancellation ?? true;
|
|
47
59
|
} else {
|
|
48
60
|
this.legacyNcOptions = sampleRateOrOptions.noiseCancellation;
|
|
49
61
|
}
|
|
@@ -77,6 +89,12 @@ class AudioStreamSource implements UnderlyingSource<AudioFrame> {
|
|
|
77
89
|
this.ffiHandle = new FfiHandle(res.stream!.handle!.id!);
|
|
78
90
|
|
|
79
91
|
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);
|
|
92
|
+
track.registerAudioStream(this);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** @internal */
|
|
96
|
+
get processor(): FrameProcessor<AudioFrame> | null {
|
|
97
|
+
return this.frameProcessor;
|
|
80
98
|
}
|
|
81
99
|
|
|
82
100
|
private onEvent = (ev: FfiEvent) => {
|
|
@@ -113,8 +131,11 @@ class AudioStreamSource implements UnderlyingSource<AudioFrame> {
|
|
|
113
131
|
// while buffered frames are still in the ReadableStream queue.
|
|
114
132
|
if (!this.disposed) {
|
|
115
133
|
this.disposed = true;
|
|
134
|
+
this.track.unregisterAudioStream(this);
|
|
116
135
|
this.ffiHandle.dispose();
|
|
117
|
-
this.frameProcessor
|
|
136
|
+
if (this.frameProcessor && this.autoCloseProcessor) {
|
|
137
|
+
this.frameProcessor.close();
|
|
138
|
+
}
|
|
118
139
|
}
|
|
119
140
|
break;
|
|
120
141
|
}
|
|
@@ -128,10 +149,13 @@ class AudioStreamSource implements UnderlyingSource<AudioFrame> {
|
|
|
128
149
|
FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);
|
|
129
150
|
if (!this.disposed) {
|
|
130
151
|
this.disposed = true;
|
|
152
|
+
this.track.unregisterAudioStream(this);
|
|
131
153
|
this.ffiHandle.dispose();
|
|
132
154
|
// Also close the frame processor on cancel for symmetry with the EOS path,
|
|
133
155
|
// so resources are released regardless of how the stream ends.
|
|
134
|
-
this.frameProcessor
|
|
156
|
+
if (this.frameProcessor && this.autoCloseProcessor) {
|
|
157
|
+
this.frameProcessor.close();
|
|
158
|
+
}
|
|
135
159
|
}
|
|
136
160
|
}
|
|
137
161
|
}
|