@livekit/rtc-node 0.11.1 → 0.12.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.cjs +94 -0
- package/dist/audio_frame.cjs.map +1 -0
- package/dist/audio_frame.js +64 -67
- package/dist/audio_frame.js.map +1 -1
- package/dist/audio_resampler.cjs +153 -0
- package/dist/audio_resampler.cjs.map +1 -0
- package/dist/audio_resampler.js +129 -134
- package/dist/audio_resampler.js.map +1 -1
- package/dist/audio_source.cjs +116 -0
- package/dist/audio_source.cjs.map +1 -0
- package/dist/audio_source.js +92 -85
- package/dist/audio_source.js.map +1 -1
- package/dist/audio_stream.cjs +104 -0
- package/dist/audio_stream.cjs.map +1 -0
- package/dist/audio_stream.js +77 -78
- package/dist/audio_stream.js.map +1 -1
- package/dist/e2ee.cjs +268 -0
- package/dist/e2ee.cjs.map +1 -0
- package/dist/e2ee.d.ts.map +1 -1
- package/dist/e2ee.js +244 -221
- package/dist/e2ee.js.map +1 -1
- package/dist/ffi_client.cjs +101 -0
- package/dist/ffi_client.cjs.map +1 -0
- package/dist/ffi_client.js +73 -48
- package/dist/ffi_client.js.map +1 -1
- package/dist/index.cjs +188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +130 -48
- package/dist/index.js.map +1 -1
- package/dist/napi/native.d.cjs +17 -0
- package/dist/napi/native.d.cjs.map +1 -0
- package/dist/napi/native.d.js +1 -0
- package/dist/napi/native.d.js.map +1 -0
- package/dist/napi/native.d.ts +5 -5
- package/dist/native.cjs +301 -0
- package/dist/native.d.ts +19 -0
- package/dist/native.js +15 -0
- package/dist/participant.cjs +388 -0
- package/dist/participant.cjs.map +1 -0
- package/dist/participant.js +363 -339
- package/dist/participant.js.map +1 -1
- package/dist/proto/audio_frame_pb.cjs +193 -0
- package/dist/proto/audio_frame_pb.cjs.map +1 -0
- package/dist/proto/audio_frame_pb.js +120 -320
- package/dist/proto/audio_frame_pb.js.map +1 -1
- package/dist/proto/e2ee_pb.cjs +131 -0
- package/dist/proto/e2ee_pb.cjs.map +1 -0
- package/dist/proto/e2ee_pb.js +76 -202
- package/dist/proto/e2ee_pb.js.map +1 -1
- package/dist/proto/ffi_pb.cjs +76 -0
- package/dist/proto/ffi_pb.cjs.map +1 -0
- package/dist/proto/ffi_pb.js +33 -92
- package/dist/proto/ffi_pb.js.map +1 -1
- package/dist/proto/handle_pb.cjs +33 -0
- package/dist/proto/handle_pb.cjs.map +1 -0
- package/dist/proto/handle_pb.js +6 -22
- package/dist/proto/handle_pb.js.map +1 -1
- package/dist/proto/participant_pb.cjs +50 -0
- package/dist/proto/participant_pb.cjs.map +1 -0
- package/dist/proto/participant_pb.js +19 -57
- package/dist/proto/participant_pb.js.map +1 -1
- package/dist/proto/room_pb.cjs +370 -0
- package/dist/proto/room_pb.cjs.map +1 -0
- package/dist/proto/room_pb.js +239 -632
- package/dist/proto/room_pb.js.map +1 -1
- package/dist/proto/rpc_pb.cjs +63 -0
- package/dist/proto/rpc_pb.cjs.map +1 -0
- package/dist/proto/rpc_pb.js +26 -72
- package/dist/proto/rpc_pb.js.map +1 -1
- package/dist/proto/stats_pb.cjs +256 -0
- package/dist/proto/stats_pb.cjs.map +1 -0
- package/dist/proto/stats_pb.js +175 -456
- package/dist/proto/stats_pb.js.map +1 -1
- package/dist/proto/track_pb.cjs +116 -0
- package/dist/proto/track_pb.cjs.map +1 -0
- package/dist/proto/track_pb.js +65 -171
- package/dist/proto/track_pb.js.map +1 -1
- package/dist/proto/video_frame_pb.cjs +161 -0
- package/dist/proto/video_frame_pb.cjs.map +1 -0
- package/dist/proto/video_frame_pb.js +101 -269
- package/dist/proto/video_frame_pb.js.map +1 -1
- package/dist/room.cjs +440 -0
- package/dist/room.cjs.map +1 -0
- package/dist/room.js +384 -373
- package/dist/room.js.map +1 -1
- package/dist/rpc.cjs +89 -0
- package/dist/rpc.cjs.map +1 -0
- package/dist/rpc.js +59 -63
- package/dist/rpc.js.map +1 -1
- package/dist/track.cjs +100 -0
- package/dist/track.cjs.map +1 -0
- package/dist/track.js +66 -62
- package/dist/track.js.map +1 -1
- package/dist/track_publication.cjs +106 -0
- package/dist/track_publication.cjs.map +1 -0
- package/dist/track_publication.js +76 -74
- package/dist/track_publication.js.map +1 -1
- package/dist/transcription.cjs +17 -0
- package/dist/transcription.cjs.map +1 -0
- package/dist/transcription.js +0 -1
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs +17 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/dist/version.cjs +29 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +4 -1
- package/dist/version.js.map +1 -1
- package/dist/video_frame.cjs +242 -0
- package/dist/video_frame.cjs.map +1 -0
- package/dist/video_frame.js +212 -201
- package/dist/video_frame.js.map +1 -1
- package/dist/video_source.cjs +63 -0
- package/dist/video_source.cjs.map +1 -0
- package/dist/video_source.d.ts.map +1 -1
- package/dist/video_source.js +42 -37
- package/dist/video_source.js.map +1 -1
- package/dist/video_stream.cjs +103 -0
- package/dist/video_stream.cjs.map +1 -0
- package/dist/video_stream.js +76 -77
- package/dist/video_stream.js.map +1 -1
- package/package.json +18 -9
- package/src/audio_frame.ts +2 -2
- package/src/audio_source.ts +2 -2
- package/src/e2ee.ts +2 -2
- package/src/napi/native.d.ts +5 -5
- package/src/version.ts +1 -1
- package/src/video_frame.ts +1 -1
- package/src/video_source.ts +5 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var video_stream_exports = {};
|
|
20
|
+
__export(video_stream_exports, {
|
|
21
|
+
VideoStream: () => VideoStream
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(video_stream_exports);
|
|
24
|
+
var import_protobuf = require("@bufbuild/protobuf");
|
|
25
|
+
var import_mutex = require("@livekit/mutex");
|
|
26
|
+
var import_ffi_client = require("./ffi_client.cjs");
|
|
27
|
+
var import_video_frame_pb = require("./proto/video_frame_pb.cjs");
|
|
28
|
+
var import_video_frame = require("./video_frame.cjs");
|
|
29
|
+
class VideoStream {
|
|
30
|
+
constructor(track) {
|
|
31
|
+
/** @internal */
|
|
32
|
+
this.eventQueue = [];
|
|
33
|
+
/** @internal */
|
|
34
|
+
this.queueResolve = null;
|
|
35
|
+
/** @internal */
|
|
36
|
+
this.mutex = new import_mutex.Mutex();
|
|
37
|
+
this.onEvent = (ev) => {
|
|
38
|
+
if (ev.message.case != "videoStreamEvent" || ev.message.value.streamHandle != this.ffiHandle.handle) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const streamEvent = ev.message.value.message;
|
|
42
|
+
switch (streamEvent.case) {
|
|
43
|
+
case "frameReceived":
|
|
44
|
+
const rotation = streamEvent.value.rotation;
|
|
45
|
+
const timestampUs = streamEvent.value.timestampUs;
|
|
46
|
+
const frame = import_video_frame.VideoFrame.fromOwnedInfo(streamEvent.value.buffer);
|
|
47
|
+
const value = { rotation, timestampUs, frame };
|
|
48
|
+
if (this.queueResolve) {
|
|
49
|
+
this.queueResolve({ done: false, value });
|
|
50
|
+
} else {
|
|
51
|
+
this.eventQueue.push(value);
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case "eos":
|
|
55
|
+
import_ffi_client.FfiClient.instance.off(import_ffi_client.FfiClientEvent.FfiEvent, this.onEvent);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
this.track = track;
|
|
60
|
+
const req = (0, import_protobuf.create)(import_video_frame_pb.NewVideoStreamRequestSchema, {
|
|
61
|
+
type: import_video_frame_pb.VideoStreamType.VIDEO_STREAM_NATIVE,
|
|
62
|
+
trackHandle: track.ffi_handle.handle
|
|
63
|
+
});
|
|
64
|
+
const res = import_ffi_client.FfiClient.instance.request({
|
|
65
|
+
message: {
|
|
66
|
+
case: "newVideoStream",
|
|
67
|
+
value: req
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.info = res.stream.info;
|
|
71
|
+
this.ffiHandle = new import_ffi_client.FfiHandle(res.stream.handle.id);
|
|
72
|
+
import_ffi_client.FfiClient.instance.on(import_ffi_client.FfiClientEvent.FfiEvent, this.onEvent);
|
|
73
|
+
}
|
|
74
|
+
async next() {
|
|
75
|
+
const unlock = await this.mutex.lock();
|
|
76
|
+
if (this.eventQueue.length > 0) {
|
|
77
|
+
unlock();
|
|
78
|
+
const value = this.eventQueue.shift();
|
|
79
|
+
if (value) {
|
|
80
|
+
return { done: false, value };
|
|
81
|
+
} else {
|
|
82
|
+
return { done: true, value: void 0 };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const promise = new Promise(
|
|
86
|
+
(resolve) => this.queueResolve = resolve
|
|
87
|
+
);
|
|
88
|
+
unlock();
|
|
89
|
+
return promise;
|
|
90
|
+
}
|
|
91
|
+
close() {
|
|
92
|
+
this.eventQueue.push(null);
|
|
93
|
+
this.ffiHandle.dispose();
|
|
94
|
+
}
|
|
95
|
+
[Symbol.asyncIterator]() {
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
VideoStream
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=video_stream.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/video_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { create } from '@bufbuild/protobuf';\nimport { Mutex } from '@livekit/mutex';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type {\n NewVideoStreamResponse,\n VideoRotation,\n VideoStreamInfo,\n} from './proto/video_frame_pb.js';\nimport { NewVideoStreamRequestSchema, VideoStreamType } from './proto/video_frame_pb.js';\nimport type { Track } from './track.js';\nimport { VideoFrame } from './video_frame.js';\n\nexport type VideoFrameEvent = {\n frame: VideoFrame;\n timestampUs: bigint;\n rotation: VideoRotation;\n};\n\nexport class VideoStream implements AsyncIterableIterator<VideoFrameEvent> {\n /** @internal */\n info: VideoStreamInfo;\n /** @internal */\n ffiHandle: FfiHandle;\n /** @internal */\n eventQueue: (VideoFrameEvent | null)[] = [];\n /** @internal */\n queueResolve: ((value: IteratorResult<VideoFrameEvent>) => void) | null = null;\n /** @internal */\n mutex = new Mutex();\n\n track: Track;\n\n constructor(track: Track) {\n this.track = track;\n\n const req = create(NewVideoStreamRequestSchema, {\n type: VideoStreamType.VIDEO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n });\n\n const res = FfiClient.instance.request<NewVideoStreamResponse>({\n message: {\n case: 'newVideoStream',\n value: req,\n },\n });\n\n this.info = res.stream!.info!;\n this.ffiHandle = new FfiHandle(res.stream!.handle!.id);\n\n FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);\n }\n\n private onEvent = (ev: FfiEvent) => {\n if (\n ev.message.case != 'videoStreamEvent' ||\n ev.message.value.streamHandle != this.ffiHandle.handle\n ) {\n return;\n }\n\n const streamEvent = ev.message.value.message;\n switch (streamEvent.case) {\n case 'frameReceived':\n const rotation = streamEvent.value.rotation;\n const timestampUs = streamEvent.value.timestampUs;\n const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer!);\n const value = { rotation, timestampUs, frame };\n if (this.queueResolve) {\n this.queueResolve({ done: false, value });\n } else {\n this.eventQueue.push(value);\n }\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n break;\n }\n };\n\n async next(): Promise<IteratorResult<VideoFrameEvent>> {\n const unlock = await this.mutex.lock();\n if (this.eventQueue.length > 0) {\n unlock();\n const value = this.eventQueue.shift();\n if (value) {\n return { done: false, value };\n } else {\n return { done: true, value: undefined };\n }\n }\n const promise = new Promise<IteratorResult<VideoFrameEvent>>(\n (resolve) => (this.queueResolve = resolve),\n );\n unlock();\n return promise;\n }\n\n close() {\n this.eventQueue.push(null);\n this.ffiHandle.dispose();\n }\n\n [Symbol.asyncIterator](): VideoStream {\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAuB;AACvB,mBAAsB;AAEtB,wBAAqD;AAMrD,4BAA6D;AAE7D,yBAA2B;AAQpB,MAAM,YAA8D;AAAA,EAczE,YAAY,OAAc;AAR1B;AAAA,sBAAyC,CAAC;AAE1C;AAAA,wBAA0E;AAE1E;AAAA,iBAAQ,IAAI,mBAAM;AAyBlB,SAAQ,UAAU,CAAC,OAAiB;AAClC,UACE,GAAG,QAAQ,QAAQ,sBACnB,GAAG,QAAQ,MAAM,gBAAgB,KAAK,UAAU,QAChD;AACA;AAAA,MACF;AAEA,YAAM,cAAc,GAAG,QAAQ,MAAM;AACrC,cAAQ,YAAY,MAAM;AAAA,QACxB,KAAK;AACH,gBAAM,WAAW,YAAY,MAAM;AACnC,gBAAM,cAAc,YAAY,MAAM;AACtC,gBAAM,QAAQ,8BAAW,cAAc,YAAY,MAAM,MAAO;AAChE,gBAAM,QAAQ,EAAE,UAAU,aAAa,MAAM;AAC7C,cAAI,KAAK,cAAc;AACrB,iBAAK,aAAa,EAAE,MAAM,OAAO,MAAM,CAAC;AAAA,UAC1C,OAAO;AACL,iBAAK,WAAW,KAAK,KAAK;AAAA,UAC5B;AACA;AAAA,QACF,KAAK;AACH,sCAAU,SAAS,IAAI,iCAAe,UAAU,KAAK,OAAO;AAC5D;AAAA,MACJ;AAAA,IACF;AA7CE,SAAK,QAAQ;AAEb,UAAM,UAAM,wBAAO,mDAA6B;AAAA,MAC9C,MAAM,sCAAgB;AAAA,MACtB,aAAa,MAAM,WAAW;AAAA,IAChC,CAAC;AAED,UAAM,MAAM,4BAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,OAAO,IAAI,OAAQ;AACxB,SAAK,YAAY,IAAI,4BAAU,IAAI,OAAQ,OAAQ,EAAE;AAErD,gCAAU,SAAS,GAAG,iCAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EA6BA,MAAM,OAAiD;AACrD,UAAM,SAAS,MAAM,KAAK,MAAM,KAAK;AACrC,QAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAO;AACP,YAAM,QAAQ,KAAK,WAAW,MAAM;AACpC,UAAI,OAAO;AACT,eAAO,EAAE,MAAM,OAAO,MAAM;AAAA,MAC9B,OAAO;AACL,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AACA,UAAM,UAAU,IAAI;AAAA,MAClB,CAAC,YAAa,KAAK,eAAe;AAAA,IACpC;AACA,WAAO;AACP,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,WAAW,KAAK,IAAI;AACzB,SAAK,UAAU,QAAQ;AAAA,EACzB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAiB;AACpC,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/video_stream.js
CHANGED
|
@@ -1,80 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (value) {
|
|
62
|
-
return { done: false, value };
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
return { done: true, value: undefined };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const promise = new Promise((resolve) => (this.queueResolve = resolve));
|
|
69
|
-
unlock();
|
|
70
|
-
return promise;
|
|
71
|
-
}
|
|
72
|
-
close() {
|
|
73
|
-
this.eventQueue.push(null);
|
|
74
|
-
this.ffiHandle.dispose();
|
|
75
|
-
}
|
|
76
|
-
[Symbol.asyncIterator]() {
|
|
77
|
-
return this;
|
|
1
|
+
import { create } from "@bufbuild/protobuf";
|
|
2
|
+
import { Mutex } from "@livekit/mutex";
|
|
3
|
+
import { FfiClient, FfiClientEvent, FfiHandle } from "./ffi_client.js";
|
|
4
|
+
import { NewVideoStreamRequestSchema, VideoStreamType } from "./proto/video_frame_pb.js";
|
|
5
|
+
import { VideoFrame } from "./video_frame.js";
|
|
6
|
+
class VideoStream {
|
|
7
|
+
constructor(track) {
|
|
8
|
+
/** @internal */
|
|
9
|
+
this.eventQueue = [];
|
|
10
|
+
/** @internal */
|
|
11
|
+
this.queueResolve = null;
|
|
12
|
+
/** @internal */
|
|
13
|
+
this.mutex = new Mutex();
|
|
14
|
+
this.onEvent = (ev) => {
|
|
15
|
+
if (ev.message.case != "videoStreamEvent" || ev.message.value.streamHandle != this.ffiHandle.handle) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const streamEvent = ev.message.value.message;
|
|
19
|
+
switch (streamEvent.case) {
|
|
20
|
+
case "frameReceived":
|
|
21
|
+
const rotation = streamEvent.value.rotation;
|
|
22
|
+
const timestampUs = streamEvent.value.timestampUs;
|
|
23
|
+
const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer);
|
|
24
|
+
const value = { rotation, timestampUs, frame };
|
|
25
|
+
if (this.queueResolve) {
|
|
26
|
+
this.queueResolve({ done: false, value });
|
|
27
|
+
} else {
|
|
28
|
+
this.eventQueue.push(value);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case "eos":
|
|
32
|
+
FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.track = track;
|
|
37
|
+
const req = create(NewVideoStreamRequestSchema, {
|
|
38
|
+
type: VideoStreamType.VIDEO_STREAM_NATIVE,
|
|
39
|
+
trackHandle: track.ffi_handle.handle
|
|
40
|
+
});
|
|
41
|
+
const res = FfiClient.instance.request({
|
|
42
|
+
message: {
|
|
43
|
+
case: "newVideoStream",
|
|
44
|
+
value: req
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.info = res.stream.info;
|
|
48
|
+
this.ffiHandle = new FfiHandle(res.stream.handle.id);
|
|
49
|
+
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);
|
|
50
|
+
}
|
|
51
|
+
async next() {
|
|
52
|
+
const unlock = await this.mutex.lock();
|
|
53
|
+
if (this.eventQueue.length > 0) {
|
|
54
|
+
unlock();
|
|
55
|
+
const value = this.eventQueue.shift();
|
|
56
|
+
if (value) {
|
|
57
|
+
return { done: false, value };
|
|
58
|
+
} else {
|
|
59
|
+
return { done: true, value: void 0 };
|
|
60
|
+
}
|
|
78
61
|
}
|
|
62
|
+
const promise = new Promise(
|
|
63
|
+
(resolve) => this.queueResolve = resolve
|
|
64
|
+
);
|
|
65
|
+
unlock();
|
|
66
|
+
return promise;
|
|
67
|
+
}
|
|
68
|
+
close() {
|
|
69
|
+
this.eventQueue.push(null);
|
|
70
|
+
this.ffiHandle.dispose();
|
|
71
|
+
}
|
|
72
|
+
[Symbol.asyncIterator]() {
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
79
75
|
}
|
|
76
|
+
export {
|
|
77
|
+
VideoStream
|
|
78
|
+
};
|
|
80
79
|
//# sourceMappingURL=video_stream.js.map
|
package/dist/video_stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/video_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { create } from '@bufbuild/protobuf';\nimport { Mutex } from '@livekit/mutex';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type {\n NewVideoStreamResponse,\n VideoRotation,\n VideoStreamInfo,\n} from './proto/video_frame_pb.js';\nimport { NewVideoStreamRequestSchema, VideoStreamType } from './proto/video_frame_pb.js';\nimport type { Track } from './track.js';\nimport { VideoFrame } from './video_frame.js';\n\nexport type VideoFrameEvent = {\n frame: VideoFrame;\n timestampUs: bigint;\n rotation: VideoRotation;\n};\n\nexport class VideoStream implements AsyncIterableIterator<VideoFrameEvent> {\n /** @internal */\n info: VideoStreamInfo;\n /** @internal */\n ffiHandle: FfiHandle;\n /** @internal */\n eventQueue: (VideoFrameEvent | null)[] = [];\n /** @internal */\n queueResolve: ((value: IteratorResult<VideoFrameEvent>) => void) | null = null;\n /** @internal */\n mutex = new Mutex();\n\n track: Track;\n\n constructor(track: Track) {\n this.track = track;\n\n const req = create(NewVideoStreamRequestSchema, {\n type: VideoStreamType.VIDEO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n });\n\n const res = FfiClient.instance.request<NewVideoStreamResponse>({\n message: {\n case: 'newVideoStream',\n value: req,\n },\n });\n\n this.info = res.stream!.info!;\n this.ffiHandle = new FfiHandle(res.stream!.handle!.id);\n\n FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);\n }\n\n private onEvent = (ev: FfiEvent) => {\n if (\n ev.message.case != 'videoStreamEvent' ||\n ev.message.value.streamHandle != this.ffiHandle.handle\n ) {\n return;\n }\n\n const streamEvent = ev.message.value.message;\n switch (streamEvent.case) {\n case 'frameReceived':\n const rotation = streamEvent.value.rotation;\n const timestampUs = streamEvent.value.timestampUs;\n const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer!);\n const value = { rotation, timestampUs, frame };\n if (this.queueResolve) {\n this.queueResolve({ done: false, value });\n } else {\n this.eventQueue.push(value);\n }\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n break;\n }\n };\n\n async next(): Promise<IteratorResult<VideoFrameEvent>> {\n const unlock = await this.mutex.lock();\n if (this.eventQueue.length > 0) {\n unlock();\n const value = this.eventQueue.shift();\n if (value) {\n return { done: false, value };\n } else {\n return { done: true, value: undefined };\n }\n }\n const promise = new Promise<IteratorResult<VideoFrameEvent>>(\n (resolve) => (this.queueResolve = resolve),\n );\n unlock();\n return promise;\n }\n\n close() {\n this.eventQueue.push(null);\n this.ffiHandle.dispose();\n }\n\n [Symbol.asyncIterator](): VideoStream {\n return this;\n }\n}\n"],"mappings":"AAGA,SAAS,cAAc;AACvB,SAAS,aAAa;AAEtB,SAAS,WAAW,gBAAgB,iBAAiB;AAMrD,SAAS,6BAA6B,uBAAuB;AAE7D,SAAS,kBAAkB;AAQpB,MAAM,YAA8D;AAAA,EAczE,YAAY,OAAc;AAR1B;AAAA,sBAAyC,CAAC;AAE1C;AAAA,wBAA0E;AAE1E;AAAA,iBAAQ,IAAI,MAAM;AAyBlB,SAAQ,UAAU,CAAC,OAAiB;AAClC,UACE,GAAG,QAAQ,QAAQ,sBACnB,GAAG,QAAQ,MAAM,gBAAgB,KAAK,UAAU,QAChD;AACA;AAAA,MACF;AAEA,YAAM,cAAc,GAAG,QAAQ,MAAM;AACrC,cAAQ,YAAY,MAAM;AAAA,QACxB,KAAK;AACH,gBAAM,WAAW,YAAY,MAAM;AACnC,gBAAM,cAAc,YAAY,MAAM;AACtC,gBAAM,QAAQ,WAAW,cAAc,YAAY,MAAM,MAAO;AAChE,gBAAM,QAAQ,EAAE,UAAU,aAAa,MAAM;AAC7C,cAAI,KAAK,cAAc;AACrB,iBAAK,aAAa,EAAE,MAAM,OAAO,MAAM,CAAC;AAAA,UAC1C,OAAO;AACL,iBAAK,WAAW,KAAK,KAAK;AAAA,UAC5B;AACA;AAAA,QACF,KAAK;AACH,oBAAU,SAAS,IAAI,eAAe,UAAU,KAAK,OAAO;AAC5D;AAAA,MACJ;AAAA,IACF;AA7CE,SAAK,QAAQ;AAEb,UAAM,MAAM,OAAO,6BAA6B;AAAA,MAC9C,MAAM,gBAAgB;AAAA,MACtB,aAAa,MAAM,WAAW;AAAA,IAChC,CAAC;AAED,UAAM,MAAM,UAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,OAAO,IAAI,OAAQ;AACxB,SAAK,YAAY,IAAI,UAAU,IAAI,OAAQ,OAAQ,EAAE;AAErD,cAAU,SAAS,GAAG,eAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EA6BA,MAAM,OAAiD;AACrD,UAAM,SAAS,MAAM,KAAK,MAAM,KAAK;AACrC,QAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAO;AACP,YAAM,QAAQ,KAAK,WAAW,MAAM;AACpC,UAAI,OAAO;AACT,eAAO,EAAE,MAAM,OAAO,MAAM;AAAA,MAC9B,OAAO;AACL,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AACA,UAAM,UAAU,IAAI;AAAA,MAClB,CAAC,YAAa,KAAK,eAAe;AAAA,IACpC;AACA,WAAO;AACP,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,WAAW,KAAK,IAAI;AACzB,SAAK,UAAU,QAAQ;AAAA,EACzB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAiB;AACpC,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
"description": "LiveKit RTC Node",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "LiveKit",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.12.0",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
+
"require": "dist/index.cjs",
|
|
8
9
|
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
9
17
|
"type": "module",
|
|
10
18
|
"repository": {
|
|
11
19
|
"type": "git",
|
|
@@ -42,23 +50,24 @@
|
|
|
42
50
|
"@napi-rs/cli": "^2.18.0",
|
|
43
51
|
"@types/node": "^20.9.2",
|
|
44
52
|
"prettier": "^3.0.3",
|
|
53
|
+
"tsup": "^8.3.5",
|
|
45
54
|
"typescript": "^5.2.2"
|
|
46
55
|
},
|
|
47
56
|
"optionalDependencies": {
|
|
48
|
-
"@livekit/rtc-node-darwin-arm64": "0.
|
|
49
|
-
"@livekit/rtc-node-darwin-x64": "0.
|
|
50
|
-
"@livekit/rtc-node-linux-arm64-gnu": "0.
|
|
51
|
-
"@livekit/rtc-node-linux-x64-gnu": "0.
|
|
52
|
-
"@livekit/rtc-node-win32-x64-msvc": "0.
|
|
57
|
+
"@livekit/rtc-node-darwin-arm64": "0.12.0",
|
|
58
|
+
"@livekit/rtc-node-darwin-x64": "0.12.0",
|
|
59
|
+
"@livekit/rtc-node-linux-arm64-gnu": "0.12.0",
|
|
60
|
+
"@livekit/rtc-node-linux-x64-gnu": "0.12.0",
|
|
61
|
+
"@livekit/rtc-node-win32-x64-msvc": "0.12.0"
|
|
53
62
|
},
|
|
54
63
|
"engines": {
|
|
55
64
|
"node": ">= 18"
|
|
56
65
|
},
|
|
57
66
|
"scripts": {
|
|
58
67
|
"prebuild": "node -p \"'export const SDK_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
|
|
59
|
-
"build:
|
|
60
|
-
"build": "pnpm build:
|
|
61
|
-
"artifacts": "pnpm build:
|
|
68
|
+
"build:ts": "pnpm prebuild && tsup --onSuccess \"tsc --declaration --emitDeclarationOnly\" && cp -r src/napi dist/ && cp -r src/napi/* dist/",
|
|
69
|
+
"build": "pnpm build:ts && napi build --platform --release --dts native.d.ts --js native.cjs --pipe \"prettier -w\" src/napi",
|
|
70
|
+
"artifacts": "pnpm build:ts && napi artifacts",
|
|
62
71
|
"build:debug": "napi build --platform",
|
|
63
72
|
"lint": "eslint -f unix \"src/**/*.ts\" --ignore-pattern \"src/proto/*\"",
|
|
64
73
|
"universal": "napi universal",
|
package/src/audio_frame.ts
CHANGED
|
@@ -72,8 +72,8 @@ export const combineAudioFrames = (buffer: AudioFrame | AudioFrame[]): AudioFram
|
|
|
72
72
|
throw new Error('buffer is empty');
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const sampleRate = buffer[0]
|
|
76
|
-
const channels = buffer[0]
|
|
75
|
+
const sampleRate = buffer[0]!.sampleRate;
|
|
76
|
+
const channels = buffer[0]!.channels;
|
|
77
77
|
|
|
78
78
|
let totalSamplesPerChannel = 0;
|
|
79
79
|
for (const frame of buffer) {
|
package/src/audio_source.ts
CHANGED
|
@@ -66,7 +66,7 @@ export class AudioSource {
|
|
|
66
66
|
|
|
67
67
|
get queuedDuration(): number {
|
|
68
68
|
return Math.max(
|
|
69
|
-
this.currentQueueSize - Number(process.hrtime.bigint() /
|
|
69
|
+
this.currentQueueSize - Number(process.hrtime.bigint() / BigInt(1000000)) + this.lastCapture,
|
|
70
70
|
0,
|
|
71
71
|
);
|
|
72
72
|
}
|
|
@@ -102,7 +102,7 @@ export class AudioSource {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
async captureFrame(frame: AudioFrame) {
|
|
105
|
-
const now = Number(process.hrtime.bigint() /
|
|
105
|
+
const now = Number(process.hrtime.bigint() / BigInt(1000000));
|
|
106
106
|
const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture;
|
|
107
107
|
const frameDurationMs = (frame.samplesPerChannel / frame.sampleRate) * 1000;
|
|
108
108
|
this.currentQueueSize += frameDurationMs - elapsed;
|
package/src/e2ee.ts
CHANGED
|
@@ -190,7 +190,7 @@ export class KeyProvider {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
export class FrameCryptor {
|
|
193
|
-
private roomHandle =
|
|
193
|
+
private roomHandle = BigInt(0);
|
|
194
194
|
participantIdentity: string;
|
|
195
195
|
keyIndex: number;
|
|
196
196
|
enabled: boolean;
|
|
@@ -246,7 +246,7 @@ export class FrameCryptor {
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
export class E2EEManager {
|
|
249
|
-
private roomHandle =
|
|
249
|
+
private roomHandle = BigInt(0);
|
|
250
250
|
private options: E2EEOptions;
|
|
251
251
|
private keyProvider?: KeyProvider;
|
|
252
252
|
|
package/src/napi/native.d.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export function livekitInitialize(
|
|
7
7
|
callback: (data: Uint8Array) => void,
|
|
8
8
|
captureLogs: boolean,
|
|
9
9
|
sdkVersion: string,
|
|
10
10
|
): void;
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
11
|
+
export function livekitFfiRequest(data: Uint8Array): Uint8Array;
|
|
12
|
+
export function livekitRetrievePtr(handle: Uint8Array): bigint;
|
|
13
|
+
export function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array;
|
|
14
|
+
export function livekitDispose(): Promise<void>;
|
|
15
15
|
export declare class FfiHandle {
|
|
16
16
|
constructor(handle: bigint);
|
|
17
17
|
dispose(): void;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.12.0";
|
package/src/video_frame.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class VideoFrame {
|
|
|
78
78
|
const planeInfos = getPlaneInfos(this.dataPtr, this.type, this.width, this.height);
|
|
79
79
|
if (planeNth >= planeInfos.length) return;
|
|
80
80
|
|
|
81
|
-
const planeInfo = planeInfos[planeNth]
|
|
81
|
+
const planeInfo = planeInfos[planeNth]!;
|
|
82
82
|
return FfiClient.instance.copyBuffer(planeInfo.dataPtr, planeInfo.size);
|
|
83
83
|
}
|
|
84
84
|
|
package/src/video_source.ts
CHANGED
|
@@ -48,7 +48,11 @@ export class VideoSource {
|
|
|
48
48
|
this.ffiHandle = new FfiHandle(res.source!.handle!.id);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
captureFrame(
|
|
51
|
+
captureFrame(
|
|
52
|
+
frame: VideoFrame,
|
|
53
|
+
timestampUs = BigInt(0),
|
|
54
|
+
rotation = VideoRotation.VIDEO_ROTATION_0,
|
|
55
|
+
) {
|
|
52
56
|
const req = create(CaptureVideoFrameRequestSchema, {
|
|
53
57
|
sourceHandle: this.ffiHandle.handle,
|
|
54
58
|
buffer: frame.protoInfo(),
|