@livekit/rtc-node 0.9.1 → 0.10.0
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_frame.d.ts +10 -0
- package/dist/audio_frame.d.ts.map +1 -1
- package/dist/audio_frame.js +32 -0
- package/dist/audio_frame.js.map +1 -1
- package/dist/audio_resampler.d.ts +51 -0
- package/dist/audio_resampler.d.ts.map +1 -0
- package/dist/audio_resampler.js +138 -0
- package/dist/audio_resampler.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/proto/audio_frame_pb.d.ts +281 -0
- package/dist/proto/audio_frame_pb.d.ts.map +1 -1
- package/dist/proto/audio_frame_pb.js +398 -0
- package/dist/proto/audio_frame_pb.js.map +1 -1
- package/dist/proto/ffi_pb.d.ts +37 -1
- package/dist/proto/ffi_pb.d.ts.map +1 -1
- package/dist/proto/ffi_pb.js +7 -1
- package/dist/proto/ffi_pb.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -4
- package/dist/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/audio_frame.ts +39 -0
- package/src/audio_resampler.ts +166 -0
- package/src/index.ts +1 -1
- package/src/proto/audio_frame_pb.ts +502 -0
- package/src/proto/ffi_pb.ts +43 -1
- package/src/utils.test.ts +47 -0
- package/src/utils.ts +12 -4
package/src/proto/ffi_pb.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { Message, proto3, protoInt64 } from "@bufbuild/protobuf";
|
|
|
22
22
|
import { ConnectCallback, ConnectRequest, ConnectResponse, DisconnectCallback, DisconnectRequest, DisconnectResponse, GetSessionStatsCallback, GetSessionStatsRequest, GetSessionStatsResponse, PublishDataCallback, PublishDataRequest, PublishDataResponse, PublishSipDtmfCallback, PublishSipDtmfRequest, PublishSipDtmfResponse, PublishTrackCallback, PublishTrackRequest, PublishTrackResponse, PublishTranscriptionCallback, PublishTranscriptionRequest, PublishTranscriptionResponse, RoomEvent, SetLocalAttributesCallback, SetLocalAttributesRequest, SetLocalAttributesResponse, SetLocalMetadataCallback, SetLocalMetadataRequest, SetLocalMetadataResponse, SetLocalNameCallback, SetLocalNameRequest, SetLocalNameResponse, SetSubscribedRequest, SetSubscribedResponse, UnpublishTrackCallback, UnpublishTrackRequest, UnpublishTrackResponse } from "./room_pb.js";
|
|
23
23
|
import { CreateAudioTrackRequest, CreateAudioTrackResponse, CreateVideoTrackRequest, CreateVideoTrackResponse, EnableRemoteTrackRequest, EnableRemoteTrackResponse, GetStatsCallback, GetStatsRequest, GetStatsResponse, LocalTrackMuteRequest, LocalTrackMuteResponse, TrackEvent } from "./track_pb.js";
|
|
24
24
|
import { CaptureVideoFrameRequest, CaptureVideoFrameResponse, NewVideoSourceRequest, NewVideoSourceResponse, NewVideoStreamRequest, NewVideoStreamResponse, VideoConvertRequest, VideoConvertResponse, VideoStreamEvent, VideoStreamFromParticipantRequest, VideoStreamFromParticipantResponse } from "./video_frame_pb.js";
|
|
25
|
-
import { AudioStreamEvent, AudioStreamFromParticipantRequest, AudioStreamFromParticipantResponse, CaptureAudioFrameCallback, CaptureAudioFrameRequest, CaptureAudioFrameResponse, ClearAudioBufferRequest, ClearAudioBufferResponse, NewAudioResamplerRequest, NewAudioResamplerResponse, NewAudioSourceRequest, NewAudioSourceResponse, NewAudioStreamRequest, NewAudioStreamResponse, RemixAndResampleRequest, RemixAndResampleResponse } from "./audio_frame_pb.js";
|
|
25
|
+
import { AudioStreamEvent, AudioStreamFromParticipantRequest, AudioStreamFromParticipantResponse, CaptureAudioFrameCallback, CaptureAudioFrameRequest, CaptureAudioFrameResponse, ClearAudioBufferRequest, ClearAudioBufferResponse, FlushSoxResamplerRequest, FlushSoxResamplerResponse, NewAudioResamplerRequest, NewAudioResamplerResponse, NewAudioSourceRequest, NewAudioSourceResponse, NewAudioStreamRequest, NewAudioStreamResponse, NewSoxResamplerRequest, NewSoxResamplerResponse, PushSoxResamplerRequest, PushSoxResamplerResponse, RemixAndResampleRequest, RemixAndResampleResponse } from "./audio_frame_pb.js";
|
|
26
26
|
import { E2eeRequest, E2eeResponse } from "./e2ee_pb.js";
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -267,6 +267,24 @@ export class FfiRequest extends Message<FfiRequest> {
|
|
|
267
267
|
*/
|
|
268
268
|
value: AudioStreamFromParticipantRequest;
|
|
269
269
|
case: "audioStreamFromParticipant";
|
|
270
|
+
} | {
|
|
271
|
+
/**
|
|
272
|
+
* @generated from field: livekit.proto.NewSoxResamplerRequest new_sox_resampler = 33;
|
|
273
|
+
*/
|
|
274
|
+
value: NewSoxResamplerRequest;
|
|
275
|
+
case: "newSoxResampler";
|
|
276
|
+
} | {
|
|
277
|
+
/**
|
|
278
|
+
* @generated from field: livekit.proto.PushSoxResamplerRequest push_sox_resampler = 34;
|
|
279
|
+
*/
|
|
280
|
+
value: PushSoxResamplerRequest;
|
|
281
|
+
case: "pushSoxResampler";
|
|
282
|
+
} | {
|
|
283
|
+
/**
|
|
284
|
+
* @generated from field: livekit.proto.FlushSoxResamplerRequest flush_sox_resampler = 35;
|
|
285
|
+
*/
|
|
286
|
+
value: FlushSoxResamplerRequest;
|
|
287
|
+
case: "flushSoxResampler";
|
|
270
288
|
} | { case: undefined; value?: undefined } = { case: undefined };
|
|
271
289
|
|
|
272
290
|
constructor(data?: PartialMessage<FfiRequest>) {
|
|
@@ -308,6 +326,9 @@ export class FfiRequest extends Message<FfiRequest> {
|
|
|
308
326
|
{ no: 30, name: "remix_and_resample", kind: "message", T: RemixAndResampleRequest, oneof: "message" },
|
|
309
327
|
{ no: 31, name: "e2ee", kind: "message", T: E2eeRequest, oneof: "message" },
|
|
310
328
|
{ no: 32, name: "audio_stream_from_participant", kind: "message", T: AudioStreamFromParticipantRequest, oneof: "message" },
|
|
329
|
+
{ no: 33, name: "new_sox_resampler", kind: "message", T: NewSoxResamplerRequest, oneof: "message" },
|
|
330
|
+
{ no: 34, name: "push_sox_resampler", kind: "message", T: PushSoxResamplerRequest, oneof: "message" },
|
|
331
|
+
{ no: 35, name: "flush_sox_resampler", kind: "message", T: FlushSoxResamplerRequest, oneof: "message" },
|
|
311
332
|
]);
|
|
312
333
|
|
|
313
334
|
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FfiRequest {
|
|
@@ -530,6 +551,24 @@ export class FfiResponse extends Message<FfiResponse> {
|
|
|
530
551
|
*/
|
|
531
552
|
value: E2eeResponse;
|
|
532
553
|
case: "e2ee";
|
|
554
|
+
} | {
|
|
555
|
+
/**
|
|
556
|
+
* @generated from field: livekit.proto.NewSoxResamplerResponse new_sox_resampler = 33;
|
|
557
|
+
*/
|
|
558
|
+
value: NewSoxResamplerResponse;
|
|
559
|
+
case: "newSoxResampler";
|
|
560
|
+
} | {
|
|
561
|
+
/**
|
|
562
|
+
* @generated from field: livekit.proto.PushSoxResamplerResponse push_sox_resampler = 34;
|
|
563
|
+
*/
|
|
564
|
+
value: PushSoxResamplerResponse;
|
|
565
|
+
case: "pushSoxResampler";
|
|
566
|
+
} | {
|
|
567
|
+
/**
|
|
568
|
+
* @generated from field: livekit.proto.FlushSoxResamplerResponse flush_sox_resampler = 35;
|
|
569
|
+
*/
|
|
570
|
+
value: FlushSoxResamplerResponse;
|
|
571
|
+
case: "flushSoxResampler";
|
|
533
572
|
} | { case: undefined; value?: undefined } = { case: undefined };
|
|
534
573
|
|
|
535
574
|
constructor(data?: PartialMessage<FfiResponse>) {
|
|
@@ -571,6 +610,9 @@ export class FfiResponse extends Message<FfiResponse> {
|
|
|
571
610
|
{ no: 30, name: "remix_and_resample", kind: "message", T: RemixAndResampleResponse, oneof: "message" },
|
|
572
611
|
{ no: 31, name: "audio_stream_from_participant", kind: "message", T: AudioStreamFromParticipantResponse, oneof: "message" },
|
|
573
612
|
{ no: 32, name: "e2ee", kind: "message", T: E2eeResponse, oneof: "message" },
|
|
613
|
+
{ no: 33, name: "new_sox_resampler", kind: "message", T: NewSoxResamplerResponse, oneof: "message" },
|
|
614
|
+
{ no: 34, name: "push_sox_resampler", kind: "message", T: PushSoxResamplerResponse, oneof: "message" },
|
|
615
|
+
{ no: 35, name: "flush_sox_resampler", kind: "message", T: FlushSoxResamplerResponse, oneof: "message" },
|
|
574
616
|
]);
|
|
575
617
|
|
|
576
618
|
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FfiResponse {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { Mutex } from './utils';
|
|
6
|
+
|
|
7
|
+
describe('Mutex', () => {
|
|
8
|
+
it('should not be locked initially', () => {
|
|
9
|
+
const mutex = new Mutex();
|
|
10
|
+
expect(mutex.isLocked()).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should lock and unlock correctly', async () => {
|
|
14
|
+
const mutex = new Mutex();
|
|
15
|
+
const unlock = await mutex.lock();
|
|
16
|
+
expect(mutex.isLocked()).toBe(true);
|
|
17
|
+
unlock();
|
|
18
|
+
expect(mutex.isLocked()).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should handle multiple locks', async () => {
|
|
22
|
+
const mutex = new Mutex(2);
|
|
23
|
+
const unlock1 = await mutex.lock();
|
|
24
|
+
const unlock2 = await mutex.lock();
|
|
25
|
+
expect(mutex.isLocked()).toBe(true);
|
|
26
|
+
unlock1();
|
|
27
|
+
expect(mutex.isLocked()).toBe(false);
|
|
28
|
+
const unlock3 = await mutex.lock();
|
|
29
|
+
expect(mutex.isLocked()).toBe(true);
|
|
30
|
+
unlock2();
|
|
31
|
+
expect(mutex.isLocked()).toBe(false);
|
|
32
|
+
unlock3();
|
|
33
|
+
expect(mutex.isLocked()).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should throw an error when unlocking the same lock twice', async () => {
|
|
37
|
+
const mutex = new Mutex(2);
|
|
38
|
+
const unlock1 = await mutex.lock();
|
|
39
|
+
const unlock2 = await mutex.lock();
|
|
40
|
+
expect(mutex.isLocked()).toBe(true);
|
|
41
|
+
unlock1();
|
|
42
|
+
expect(mutex.isLocked()).toBe(false);
|
|
43
|
+
expect(() => unlock1()).toThrow('This unlock method has already been called');
|
|
44
|
+
unlock2();
|
|
45
|
+
expect(mutex.isLocked()).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/utils.ts
CHANGED
|
@@ -17,20 +17,28 @@ export class Mutex {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async lock(): Promise<() => void> {
|
|
20
|
+
if (this.#locks >= this.#limit) {
|
|
21
|
+
await this.#locking;
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
this.#locks += 1;
|
|
21
25
|
|
|
22
|
-
let
|
|
26
|
+
let unlock: () => void;
|
|
27
|
+
let unlocked = false;
|
|
23
28
|
|
|
24
29
|
const willLock = new Promise<void>(
|
|
25
30
|
(resolve) =>
|
|
26
|
-
(
|
|
31
|
+
(unlock = () => {
|
|
32
|
+
if (unlocked) {
|
|
33
|
+
throw new Error('This unlock method has already been called');
|
|
34
|
+
}
|
|
35
|
+
unlocked = true;
|
|
27
36
|
this.#locks -= 1;
|
|
28
37
|
resolve();
|
|
29
38
|
}),
|
|
30
39
|
);
|
|
31
40
|
|
|
32
|
-
const willUnlock = this.#locking.then(() => unlockNext);
|
|
33
41
|
this.#locking = this.#locking.then(() => willLock);
|
|
34
|
-
return
|
|
42
|
+
return unlock;
|
|
35
43
|
}
|
|
36
44
|
}
|