@livekit/rtc-node 0.11.1 → 0.12.1

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.
Files changed (135) hide show
  1. package/dist/audio_frame.cjs +94 -0
  2. package/dist/audio_frame.cjs.map +1 -0
  3. package/dist/audio_frame.js +64 -67
  4. package/dist/audio_frame.js.map +1 -1
  5. package/dist/audio_resampler.cjs +153 -0
  6. package/dist/audio_resampler.cjs.map +1 -0
  7. package/dist/audio_resampler.js +129 -134
  8. package/dist/audio_resampler.js.map +1 -1
  9. package/dist/audio_source.cjs +116 -0
  10. package/dist/audio_source.cjs.map +1 -0
  11. package/dist/audio_source.js +92 -85
  12. package/dist/audio_source.js.map +1 -1
  13. package/dist/audio_stream.cjs +104 -0
  14. package/dist/audio_stream.cjs.map +1 -0
  15. package/dist/audio_stream.js +77 -78
  16. package/dist/audio_stream.js.map +1 -1
  17. package/dist/e2ee.cjs +268 -0
  18. package/dist/e2ee.cjs.map +1 -0
  19. package/dist/e2ee.d.ts.map +1 -1
  20. package/dist/e2ee.js +244 -221
  21. package/dist/e2ee.js.map +1 -1
  22. package/dist/ffi_client.cjs +95 -0
  23. package/dist/ffi_client.cjs.map +1 -0
  24. package/dist/ffi_client.d.ts +2 -2
  25. package/dist/ffi_client.d.ts.map +1 -1
  26. package/dist/ffi_client.js +67 -48
  27. package/dist/ffi_client.js.map +1 -1
  28. package/dist/index.cjs +166 -0
  29. package/dist/index.cjs.map +1 -0
  30. package/dist/index.d.ts +5 -5
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +119 -48
  33. package/dist/index.js.map +1 -1
  34. package/dist/napi/native.d.cjs +17 -0
  35. package/dist/napi/native.d.cjs.map +1 -0
  36. package/dist/napi/native.d.js +1 -0
  37. package/dist/napi/native.d.js.map +1 -0
  38. package/dist/native.cjs +301 -0
  39. package/dist/native.d.ts +19 -0
  40. package/dist/native.js +15 -0
  41. package/dist/participant.cjs +388 -0
  42. package/dist/participant.cjs.map +1 -0
  43. package/dist/participant.js +363 -339
  44. package/dist/participant.js.map +1 -1
  45. package/dist/proto/audio_frame_pb.cjs +193 -0
  46. package/dist/proto/audio_frame_pb.cjs.map +1 -0
  47. package/dist/proto/audio_frame_pb.js +120 -320
  48. package/dist/proto/audio_frame_pb.js.map +1 -1
  49. package/dist/proto/e2ee_pb.cjs +131 -0
  50. package/dist/proto/e2ee_pb.cjs.map +1 -0
  51. package/dist/proto/e2ee_pb.js +76 -202
  52. package/dist/proto/e2ee_pb.js.map +1 -1
  53. package/dist/proto/ffi_pb.cjs +76 -0
  54. package/dist/proto/ffi_pb.cjs.map +1 -0
  55. package/dist/proto/ffi_pb.js +33 -92
  56. package/dist/proto/ffi_pb.js.map +1 -1
  57. package/dist/proto/handle_pb.cjs +33 -0
  58. package/dist/proto/handle_pb.cjs.map +1 -0
  59. package/dist/proto/handle_pb.js +6 -22
  60. package/dist/proto/handle_pb.js.map +1 -1
  61. package/dist/proto/participant_pb.cjs +50 -0
  62. package/dist/proto/participant_pb.cjs.map +1 -0
  63. package/dist/proto/participant_pb.js +19 -57
  64. package/dist/proto/participant_pb.js.map +1 -1
  65. package/dist/proto/room_pb.cjs +370 -0
  66. package/dist/proto/room_pb.cjs.map +1 -0
  67. package/dist/proto/room_pb.js +239 -632
  68. package/dist/proto/room_pb.js.map +1 -1
  69. package/dist/proto/rpc_pb.cjs +63 -0
  70. package/dist/proto/rpc_pb.cjs.map +1 -0
  71. package/dist/proto/rpc_pb.js +26 -72
  72. package/dist/proto/rpc_pb.js.map +1 -1
  73. package/dist/proto/stats_pb.cjs +256 -0
  74. package/dist/proto/stats_pb.cjs.map +1 -0
  75. package/dist/proto/stats_pb.js +175 -456
  76. package/dist/proto/stats_pb.js.map +1 -1
  77. package/dist/proto/track_pb.cjs +116 -0
  78. package/dist/proto/track_pb.cjs.map +1 -0
  79. package/dist/proto/track_pb.js +65 -171
  80. package/dist/proto/track_pb.js.map +1 -1
  81. package/dist/proto/video_frame_pb.cjs +161 -0
  82. package/dist/proto/video_frame_pb.cjs.map +1 -0
  83. package/dist/proto/video_frame_pb.js +101 -269
  84. package/dist/proto/video_frame_pb.js.map +1 -1
  85. package/dist/room.cjs +440 -0
  86. package/dist/room.cjs.map +1 -0
  87. package/dist/room.js +384 -373
  88. package/dist/room.js.map +1 -1
  89. package/dist/rpc.cjs +89 -0
  90. package/dist/rpc.cjs.map +1 -0
  91. package/dist/rpc.js +59 -63
  92. package/dist/rpc.js.map +1 -1
  93. package/dist/track.cjs +100 -0
  94. package/dist/track.cjs.map +1 -0
  95. package/dist/track.js +66 -62
  96. package/dist/track.js.map +1 -1
  97. package/dist/track_publication.cjs +106 -0
  98. package/dist/track_publication.cjs.map +1 -0
  99. package/dist/track_publication.js +76 -74
  100. package/dist/track_publication.js.map +1 -1
  101. package/dist/transcription.cjs +17 -0
  102. package/dist/transcription.cjs.map +1 -0
  103. package/dist/transcription.js +0 -1
  104. package/dist/transcription.js.map +1 -1
  105. package/dist/types.cjs +17 -0
  106. package/dist/types.cjs.map +1 -0
  107. package/dist/types.js +0 -1
  108. package/dist/types.js.map +1 -1
  109. package/dist/version.cjs +29 -0
  110. package/dist/version.cjs.map +1 -0
  111. package/dist/version.d.ts +1 -1
  112. package/dist/version.js +4 -1
  113. package/dist/version.js.map +1 -1
  114. package/dist/video_frame.cjs +242 -0
  115. package/dist/video_frame.cjs.map +1 -0
  116. package/dist/video_frame.js +212 -201
  117. package/dist/video_frame.js.map +1 -1
  118. package/dist/video_source.cjs +63 -0
  119. package/dist/video_source.cjs.map +1 -0
  120. package/dist/video_source.d.ts.map +1 -1
  121. package/dist/video_source.js +42 -37
  122. package/dist/video_source.js.map +1 -1
  123. package/dist/video_stream.cjs +103 -0
  124. package/dist/video_stream.cjs.map +1 -0
  125. package/dist/video_stream.js +76 -77
  126. package/dist/video_stream.js.map +1 -1
  127. package/package.json +18 -9
  128. package/src/audio_frame.ts +2 -2
  129. package/src/audio_source.ts +2 -2
  130. package/src/e2ee.ts +2 -2
  131. package/src/ffi_client.ts +4 -4
  132. package/src/index.ts +14 -8
  133. package/src/version.ts +1 -1
  134. package/src/video_frame.ts +1 -1
  135. 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":[]}
@@ -1,80 +1,79 @@
1
- // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
- //
3
- // SPDX-License-Identifier: Apache-2.0
4
- import { create } from '@bufbuild/protobuf';
5
- import { Mutex } from '@livekit/mutex';
6
- import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
7
- import { NewVideoStreamRequestSchema, VideoStreamType } from './proto/video_frame_pb.js';
8
- import { VideoFrame } from './video_frame.js';
9
- export class VideoStream {
10
- constructor(track) {
11
- /** @internal */
12
- this.eventQueue = [];
13
- /** @internal */
14
- this.queueResolve = null;
15
- /** @internal */
16
- this.mutex = new Mutex();
17
- this.onEvent = (ev) => {
18
- if (ev.message.case != 'videoStreamEvent' ||
19
- ev.message.value.streamHandle != this.ffiHandle.handle) {
20
- return;
21
- }
22
- const streamEvent = ev.message.value.message;
23
- switch (streamEvent.case) {
24
- case 'frameReceived':
25
- const rotation = streamEvent.value.rotation;
26
- const timestampUs = streamEvent.value.timestampUs;
27
- const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer);
28
- const value = { rotation, timestampUs, frame };
29
- if (this.queueResolve) {
30
- this.queueResolve({ done: false, value });
31
- }
32
- else {
33
- this.eventQueue.push(value);
34
- }
35
- break;
36
- case 'eos':
37
- FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);
38
- break;
39
- }
40
- };
41
- this.track = track;
42
- const req = create(NewVideoStreamRequestSchema, {
43
- type: VideoStreamType.VIDEO_STREAM_NATIVE,
44
- trackHandle: track.ffi_handle.handle,
45
- });
46
- const res = FfiClient.instance.request({
47
- message: {
48
- case: 'newVideoStream',
49
- value: req,
50
- },
51
- });
52
- this.info = res.stream.info;
53
- this.ffiHandle = new FfiHandle(res.stream.handle.id);
54
- FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);
55
- }
56
- async next() {
57
- const unlock = await this.mutex.lock();
58
- if (this.eventQueue.length > 0) {
59
- unlock();
60
- const value = this.eventQueue.shift();
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
@@ -1 +1 @@
1
- {"version":3,"file":"video_stream.js","sourceRoot":"","sources":["../src/video_stream.ts"],"names":[],"mappings":"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"}
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.11.1",
6
+ "version": "0.12.1",
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.11.1",
49
- "@livekit/rtc-node-darwin-x64": "0.11.1",
50
- "@livekit/rtc-node-linux-arm64-gnu": "0.11.1",
51
- "@livekit/rtc-node-linux-x64-gnu": "0.11.1",
52
- "@livekit/rtc-node-win32-x64-msvc": "0.11.1"
57
+ "@livekit/rtc-node-darwin-arm64": "0.12.1",
58
+ "@livekit/rtc-node-darwin-x64": "0.12.1",
59
+ "@livekit/rtc-node-linux-arm64-gnu": "0.12.1",
60
+ "@livekit/rtc-node-linux-x64-gnu": "0.12.1",
61
+ "@livekit/rtc-node-win32-x64-msvc": "0.12.1"
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:tsc": "pnpm prebuild && tsc && cp -r src/napi dist/",
60
- "build": "pnpm build:tsc && napi build --platform --release --dts native.d.ts --js native.cjs --pipe \"prettier -w\" src/napi",
61
- "artifacts": "pnpm build:tsc && napi artifacts",
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",
@@ -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].sampleRate;
76
- const channels = buffer[0].channels;
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) {
@@ -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() / 1000000n) + this.lastCapture,
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() / 1000000n);
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 = 0n;
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 = 0n;
249
+ private roomHandle = BigInt(0);
250
250
  private options: E2EEOptions;
251
251
  private keyProvider?: KeyProvider;
252
252
 
package/src/ffi_client.ts CHANGED
@@ -14,16 +14,16 @@ import {
14
14
  livekitRetrievePtr,
15
15
  } from './napi/native.js';
16
16
  import {
17
- FfiEvent,
17
+ type FfiEvent,
18
18
  FfiEventSchema,
19
- FfiRequest,
19
+ type FfiRequest,
20
20
  FfiRequestSchema,
21
- FfiResponse,
21
+ type FfiResponse,
22
22
  FfiResponseSchema,
23
23
  } from './proto/ffi_pb.js';
24
24
  import { SDK_VERSION } from './version.js';
25
25
 
26
- export { FfiHandle, FfiEvent, FfiResponse, FfiRequest, livekitDispose as dispose };
26
+ export { FfiHandle, type FfiEvent, type FfiResponse, type FfiRequest, livekitDispose as dispose };
27
27
 
28
28
  export type FfiClientCallbacks = {
29
29
  ffi_event: (event: FfiEvent) => void;
package/src/index.ts CHANGED
@@ -14,24 +14,24 @@ import {
14
14
  import { TrackSource } from './proto/track_pb.js';
15
15
  import { VideoCodec } from './proto/video_frame_pb.js';
16
16
 
17
- export { Room, RoomEvent, ConnectError, RoomOptions, RtcConfiguration } from './room.js';
17
+ export { Room, RoomEvent, ConnectError, type RoomOptions, type RtcConfiguration } from './room.js';
18
18
  export { Participant, RemoteParticipant, LocalParticipant } from './participant.js';
19
19
  export {
20
20
  Track,
21
- LocalTrack,
22
- RemoteTrack,
23
- VideoTrack,
21
+ type LocalTrack,
22
+ type RemoteTrack,
23
+ type VideoTrack,
24
24
  LocalAudioTrack,
25
25
  LocalVideoTrack,
26
26
  RemoteAudioTrack,
27
27
  RemoteVideoTrack,
28
- AudioTrack,
28
+ type AudioTrack,
29
29
  } from './track.js';
30
30
  export { VideoFrame } from './video_frame.js';
31
31
  export { AudioFrame, combineAudioFrames } from './audio_frame.js';
32
32
  export { AudioStream } from './audio_stream.js';
33
33
  export { AudioResampler, AudioResamplerQuality } from './audio_resampler.js';
34
- export { VideoStream, VideoFrameEvent } from './video_stream.js';
34
+ export { VideoStream, type VideoFrameEvent } from './video_stream.js';
35
35
  export { AudioSource } from './audio_source.js';
36
36
  export { VideoSource } from './video_source.js';
37
37
  export {
@@ -39,8 +39,14 @@ export {
39
39
  RemoteTrackPublication,
40
40
  LocalTrackPublication,
41
41
  } from './track_publication.js';
42
- export { Transcription, TranscriptionSegment } from './transcription.js';
43
- export { E2EEManager, E2EEOptions, KeyProviderOptions, KeyProvider, FrameCryptor } from './e2ee.js';
42
+ export { type Transcription, type TranscriptionSegment } from './transcription.js';
43
+ export {
44
+ E2EEManager,
45
+ type E2EEOptions,
46
+ type KeyProviderOptions,
47
+ KeyProvider,
48
+ FrameCryptor,
49
+ } from './e2ee.js';
44
50
 
45
51
  export {
46
52
  ConnectionQuality,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.11.1";
1
+ export const SDK_VERSION = "0.12.1";
@@ -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
 
@@ -48,7 +48,11 @@ export class VideoSource {
48
48
  this.ffiHandle = new FfiHandle(res.source!.handle!.id);
49
49
  }
50
50
 
51
- captureFrame(frame: VideoFrame, timestampUs = 0n, rotation = VideoRotation.VIDEO_ROTATION_0) {
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(),