@livekit/rtc-node 0.13.13 → 0.13.16

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 (129) hide show
  1. package/README.md +3 -0
  2. package/dist/audio_stream.cjs +3 -2
  3. package/dist/audio_stream.cjs.map +1 -1
  4. package/dist/audio_stream.d.cts +10 -2
  5. package/dist/audio_stream.d.ts +10 -2
  6. package/dist/audio_stream.d.ts.map +1 -1
  7. package/dist/audio_stream.js +2 -1
  8. package/dist/audio_stream.js.map +1 -1
  9. package/dist/data_streams/index.d.cts +2 -2
  10. package/dist/data_streams/index.d.ts +2 -2
  11. package/dist/data_streams/stream_reader.cjs.map +1 -1
  12. package/dist/data_streams/stream_reader.d.cts +2 -2
  13. package/dist/data_streams/stream_reader.d.ts +2 -2
  14. package/dist/data_streams/stream_reader.d.ts.map +1 -1
  15. package/dist/data_streams/stream_reader.js.map +1 -1
  16. package/dist/data_streams/stream_writer.cjs.map +1 -1
  17. package/dist/data_streams/stream_writer.d.cts +2 -2
  18. package/dist/data_streams/stream_writer.d.ts +2 -2
  19. package/dist/data_streams/stream_writer.d.ts.map +1 -1
  20. package/dist/data_streams/stream_writer.js.map +1 -1
  21. package/dist/data_streams/types.d.cts +2 -2
  22. package/dist/data_streams/types.d.ts +2 -2
  23. package/dist/ffi_client.cjs +4 -2
  24. package/dist/ffi_client.cjs.map +1 -1
  25. package/dist/ffi_client.d.cts +4 -1
  26. package/dist/ffi_client.d.ts +4 -1
  27. package/dist/ffi_client.d.ts.map +1 -1
  28. package/dist/ffi_client.js +4 -2
  29. package/dist/ffi_client.js.map +1 -1
  30. package/dist/index.d.cts +11 -8
  31. package/dist/index.d.ts +11 -8
  32. package/dist/participant.cjs +13 -15
  33. package/dist/participant.cjs.map +1 -1
  34. package/dist/participant.d.cts +8 -4
  35. package/dist/participant.d.ts +8 -4
  36. package/dist/participant.d.ts.map +1 -1
  37. package/dist/participant.js +5 -7
  38. package/dist/participant.js.map +1 -1
  39. package/dist/proto/audio_frame_pb.cjs +4 -2
  40. package/dist/proto/audio_frame_pb.cjs.map +1 -1
  41. package/dist/proto/audio_frame_pb.d.cts +8 -0
  42. package/dist/proto/audio_frame_pb.d.ts +8 -0
  43. package/dist/proto/audio_frame_pb.d.ts.map +1 -1
  44. package/dist/proto/audio_frame_pb.js +4 -2
  45. package/dist/proto/audio_frame_pb.js.map +1 -1
  46. package/dist/proto/data_stream_pb.cjs +1549 -0
  47. package/dist/proto/data_stream_pb.cjs.map +1 -0
  48. package/dist/proto/data_stream_pb.d.cts +1358 -0
  49. package/dist/proto/data_stream_pb.d.ts +1358 -0
  50. package/dist/proto/data_stream_pb.d.ts.map +1 -0
  51. package/dist/proto/data_stream_pb.js +1473 -0
  52. package/dist/proto/data_stream_pb.js.map +1 -0
  53. package/dist/proto/ffi_pb.cjs +43 -3
  54. package/dist/proto/ffi_pb.cjs.map +1 -1
  55. package/dist/proto/ffi_pb.d.cts +251 -8
  56. package/dist/proto/ffi_pb.d.ts +251 -8
  57. package/dist/proto/ffi_pb.d.ts.map +1 -1
  58. package/dist/proto/ffi_pb.js +43 -3
  59. package/dist/proto/ffi_pb.js.map +1 -1
  60. package/dist/proto/participant_pb.cjs +5 -1
  61. package/dist/proto/participant_pb.cjs.map +1 -1
  62. package/dist/proto/participant_pb.d.cts +9 -1
  63. package/dist/proto/participant_pb.d.ts +9 -1
  64. package/dist/proto/participant_pb.d.ts.map +1 -1
  65. package/dist/proto/participant_pb.js +5 -1
  66. package/dist/proto/participant_pb.js.map +1 -1
  67. package/dist/proto/room_pb.cjs +99 -2
  68. package/dist/proto/room_pb.cjs.map +1 -1
  69. package/dist/proto/room_pb.d.cts +130 -2
  70. package/dist/proto/room_pb.d.ts +130 -2
  71. package/dist/proto/room_pb.d.ts.map +1 -1
  72. package/dist/proto/room_pb.js +97 -3
  73. package/dist/proto/room_pb.js.map +1 -1
  74. package/dist/proto/track_pb.cjs +27 -1
  75. package/dist/proto/track_pb.cjs.map +1 -1
  76. package/dist/proto/track_pb.d.cts +40 -1
  77. package/dist/proto/track_pb.d.ts +40 -1
  78. package/dist/proto/track_pb.d.ts.map +1 -1
  79. package/dist/proto/track_pb.js +26 -1
  80. package/dist/proto/track_pb.js.map +1 -1
  81. package/dist/room.cjs +79 -3
  82. package/dist/room.cjs.map +1 -1
  83. package/dist/room.d.cts +59 -8
  84. package/dist/room.d.ts +59 -8
  85. package/dist/room.d.ts.map +1 -1
  86. package/dist/room.js +77 -1
  87. package/dist/room.js.map +1 -1
  88. package/dist/{stream_reader-a8_oiaOi.d.cts → stream_reader-Ch2zvjU3.d.cts} +0 -1
  89. package/dist/{stream_reader-DWUV4eJB.d.ts → stream_reader-DRyR29vo.d.ts} +0 -1
  90. package/dist/track.cjs +23 -4
  91. package/dist/track.cjs.map +1 -1
  92. package/dist/track.d.cts +17 -4
  93. package/dist/track.d.ts +17 -4
  94. package/dist/track.d.ts.map +1 -1
  95. package/dist/track.js +23 -4
  96. package/dist/track.js.map +1 -1
  97. package/dist/track_publication.d.cts +9 -1
  98. package/dist/track_publication.d.ts +9 -1
  99. package/dist/version.cjs +1 -1
  100. package/dist/version.cjs.map +1 -1
  101. package/dist/version.d.cts +1 -1
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +1 -1
  104. package/dist/version.js.map +1 -1
  105. package/dist/video_source.d.cts +11 -2
  106. package/dist/video_source.d.ts +11 -2
  107. package/dist/video_stream.cjs +1 -2
  108. package/dist/video_stream.cjs.map +1 -1
  109. package/dist/video_stream.d.cts +8 -1
  110. package/dist/video_stream.d.ts +8 -1
  111. package/dist/video_stream.d.ts.map +1 -1
  112. package/dist/video_stream.js +0 -1
  113. package/dist/video_stream.js.map +1 -1
  114. package/package.json +7 -7
  115. package/src/audio_stream.ts +5 -1
  116. package/src/data_streams/stream_reader.ts +0 -1
  117. package/src/data_streams/stream_writer.ts +0 -1
  118. package/src/ffi_client.ts +9 -5
  119. package/src/participant.ts +13 -15
  120. package/src/proto/audio_frame_pb.ts +12 -0
  121. package/src/proto/data_stream_pb.ts +2515 -0
  122. package/src/proto/ffi_pb.ts +283 -1
  123. package/src/proto/participant_pb.ts +12 -0
  124. package/src/proto/room_pb.ts +212 -1
  125. package/src/proto/track_pb.ts +58 -0
  126. package/src/room.ts +79 -1
  127. package/src/track.ts +28 -4
  128. package/src/version.ts +1 -1
  129. package/src/video_stream.ts +1 -1
package/README.md CHANGED
@@ -16,6 +16,9 @@ Use this SDK to add realtime video, audio and data features to your Node app. By
16
16
  >
17
17
  > We welcome and appreciate any feedback or contributions. You can create issues here or chat live with us in the #dev channel within the [LiveKit Community Slack](https://livekit.io/join-slack).
18
18
 
19
+ ### Warning
20
+
21
+ Avoid running this with hot reloads (ex. [bun's hot reload](https://bun.sh/guides/http/hot)). This is known to cause issues with WebRTC connectivity.
19
22
 
20
23
  ## Using realtime SDK
21
24
 
@@ -21,7 +21,6 @@ __export(audio_stream_exports, {
21
21
  AudioStream: () => AudioStream
22
22
  });
23
23
  module.exports = __toCommonJS(audio_stream_exports);
24
- var import_web = require("node:stream/web");
25
24
  var import_audio_frame = require("./audio_frame.cjs");
26
25
  var import_ffi_client = require("./ffi_client.cjs");
27
26
  var import_audio_frame_pb = require("./proto/audio_frame_pb.cjs");
@@ -50,6 +49,7 @@ class AudioStreamSource {
50
49
  this.sampleRate = sampleRateOrOptions.sampleRate ?? 48e3;
51
50
  this.numChannels = sampleRateOrOptions.numChannels ?? 1;
52
51
  this.ncOptions = sampleRateOrOptions.noiseCancellation;
52
+ this.frameSizeMs = sampleRateOrOptions.frameSizeMs;
53
53
  } else {
54
54
  this.sampleRate = sampleRateOrOptions ?? 48e3;
55
55
  this.numChannels = numChannels ?? 1;
@@ -59,6 +59,7 @@ class AudioStreamSource {
59
59
  trackHandle: track.ffi_handle.handle,
60
60
  sampleRate: this.sampleRate,
61
61
  numChannels: this.numChannels,
62
+ frameSizeMs: this.frameSizeMs,
62
63
  ...this.ncOptions ? {
63
64
  audioFilterModuleId: this.ncOptions.moduleId,
64
65
  audioFilterOptions: JSON.stringify(this.ncOptions.options)
@@ -81,7 +82,7 @@ class AudioStreamSource {
81
82
  this.ffiHandle.dispose();
82
83
  }
83
84
  }
84
- class AudioStream extends import_web.ReadableStream {
85
+ class AudioStream extends ReadableStream {
85
86
  constructor(track, sampleRateOrOptions, numChannels) {
86
87
  super(new AudioStreamSource(track, sampleRateOrOptions, numChannels));
87
88
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/audio_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadableStream, type UnderlyingSource } from 'node:stream/web';\nimport { AudioFrame } from './audio_frame.js';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type { NewAudioStreamResponse } from './proto/audio_frame_pb.js';\nimport { AudioStreamType, NewAudioStreamRequest } from './proto/audio_frame_pb.js';\nimport type { Track } from './track.js';\n\nexport interface AudioStreamOptions {\n noiseCancellation?: NoiseCancellationOptions;\n sampleRate?: number;\n numChannels?: number;\n}\n\nexport interface NoiseCancellationOptions {\n moduleId: string;\n options: Record<string, any>;\n}\n\nclass AudioStreamSource implements UnderlyingSource<AudioFrame> {\n private controller?: ReadableStreamDefaultController<AudioFrame>;\n private ffiHandle: FfiHandle;\n private sampleRate: number;\n private numChannels: number;\n private ncOptions?: NoiseCancellationOptions;\n\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n if (sampleRateOrOptions !== undefined && typeof sampleRateOrOptions !== 'number') {\n this.sampleRate = sampleRateOrOptions.sampleRate ?? 48000;\n this.numChannels = sampleRateOrOptions.numChannels ?? 1;\n this.ncOptions = sampleRateOrOptions.noiseCancellation;\n } else {\n this.sampleRate = (sampleRateOrOptions as number) ?? 48000;\n this.numChannels = numChannels ?? 1;\n }\n\n const req = new NewAudioStreamRequest({\n type: AudioStreamType.AUDIO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n sampleRate: this.sampleRate,\n numChannels: this.numChannels,\n ...(this.ncOptions\n ? {\n audioFilterModuleId: this.ncOptions.moduleId,\n audioFilterOptions: JSON.stringify(this.ncOptions.options),\n }\n : {}),\n });\n\n const res = FfiClient.instance.request<NewAudioStreamResponse>({\n message: {\n case: 'newAudioStream',\n value: req,\n },\n });\n\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 (!this.controller) {\n throw new Error('Stream controller not initialized');\n }\n\n if (\n ev.message.case != 'audioStreamEvent' ||\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 frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame!);\n this.controller.enqueue(frame);\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.controller.close();\n break;\n }\n };\n\n start(controller: ReadableStreamDefaultController<AudioFrame>) {\n this.controller = controller;\n }\n\n cancel() {\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.ffiHandle.dispose();\n }\n}\n\nexport class AudioStream extends ReadableStream<AudioFrame> {\n constructor(track: Track);\n constructor(track: Track, sampleRate: number);\n constructor(track: Track, sampleRate: number, numChannels: number);\n constructor(track: Track, options: AudioStreamOptions);\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n super(new AudioStreamSource(track, sampleRateOrOptions, numChannels));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsD;AACtD,yBAA2B;AAE3B,wBAAqD;AAErD,4BAAuD;AAcvD,MAAM,kBAA0D;AAAA,EAO9D,YACE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,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EA2BA,MAAM,YAAyD;AAC7D,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,SAAS;AACP,gCAAU,SAAS,IAAI,iCAAe,UAAU,KAAK,OAAO;AAC5D,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAEO,MAAM,oBAAoB,0BAA2B;AAAA,EAK1D,YACE,OACA,qBACA,aACA;AACA,UAAM,IAAI,kBAAkB,OAAO,qBAAqB,WAAW,CAAC;AAAA,EACtE;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/audio_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { UnderlyingSource } from 'node:stream/web';\nimport { AudioFrame } from './audio_frame.js';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type { NewAudioStreamResponse } from './proto/audio_frame_pb.js';\nimport { AudioStreamType, NewAudioStreamRequest } from './proto/audio_frame_pb.js';\nimport type { Track } from './track.js';\n\nexport interface AudioStreamOptions {\n noiseCancellation?: NoiseCancellationOptions;\n sampleRate?: number;\n numChannels?: number;\n frameSizeMs?: number;\n}\n\nexport interface NoiseCancellationOptions {\n moduleId: string;\n options: Record<string, any>;\n}\n\nclass AudioStreamSource implements UnderlyingSource<AudioFrame> {\n private controller?: ReadableStreamDefaultController<AudioFrame>;\n private ffiHandle: FfiHandle;\n private sampleRate: number;\n private numChannels: number;\n private ncOptions?: NoiseCancellationOptions;\n private frameSizeMs?: number;\n\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n if (sampleRateOrOptions !== undefined && typeof sampleRateOrOptions !== 'number') {\n this.sampleRate = sampleRateOrOptions.sampleRate ?? 48000;\n this.numChannels = sampleRateOrOptions.numChannels ?? 1;\n this.ncOptions = sampleRateOrOptions.noiseCancellation;\n this.frameSizeMs = sampleRateOrOptions.frameSizeMs;\n } else {\n this.sampleRate = (sampleRateOrOptions as number) ?? 48000;\n this.numChannels = numChannels ?? 1;\n }\n\n const req = new NewAudioStreamRequest({\n type: AudioStreamType.AUDIO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n sampleRate: this.sampleRate,\n numChannels: this.numChannels,\n frameSizeMs: this.frameSizeMs,\n ...(this.ncOptions\n ? {\n audioFilterModuleId: this.ncOptions.moduleId,\n audioFilterOptions: JSON.stringify(this.ncOptions.options),\n }\n : {}),\n });\n\n const res = FfiClient.instance.request<NewAudioStreamResponse>({\n message: {\n case: 'newAudioStream',\n value: req,\n },\n });\n\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 (!this.controller) {\n throw new Error('Stream controller not initialized');\n }\n\n if (\n ev.message.case != 'audioStreamEvent' ||\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 frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame!);\n this.controller.enqueue(frame);\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.controller.close();\n break;\n }\n };\n\n start(controller: ReadableStreamDefaultController<AudioFrame>) {\n this.controller = controller;\n }\n\n cancel() {\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.ffiHandle.dispose();\n }\n}\n\nexport class AudioStream extends ReadableStream<AudioFrame> {\n constructor(track: Track);\n constructor(track: Track, sampleRate: number);\n constructor(track: Track, sampleRate: number, numChannels: number);\n constructor(track: Track, options: AudioStreamOptions);\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n super(new AudioStreamSource(track, sampleRateOrOptions, numChannels));\n }\n}\n"],"mappings":";;;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AAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,YAAY,IAAI,4BAAU,IAAI,OAAQ,OAAQ,EAAG;AAEtD,gCAAU,SAAS,GAAG,iCAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EA2BA,MAAM,YAAyD;AAC7D,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,SAAS;AACP,gCAAU,SAAS,IAAI,iCAAe,UAAU,KAAK,OAAO;AAC5D,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAEO,MAAM,oBAAoB,eAA2B;AAAA,EAK1D,YACE,OACA,qBACA,aACA;AACA,UAAM,IAAI,kBAAkB,OAAO,qBAAqB,WAAW,CAAC;AAAA,EACtE;AACF;","names":[]}
@@ -1,4 +1,3 @@
1
- import { ReadableStream } from 'node:stream/web';
2
1
  import { AudioFrame } from './audio_frame.cjs';
3
2
  import { Track } from './track.cjs';
4
3
  import './proto/audio_frame_pb.cjs';
@@ -9,14 +8,23 @@ import './proto/e2ee_pb.cjs';
9
8
  import './proto/handle_pb.cjs';
10
9
  import './audio_source.cjs';
11
10
  import './napi/native.d.cjs';
12
- import './video_source.cjs';
11
+ import './ffi_client.cjs';
12
+ import '@livekit/typed-emitter';
13
+ import './proto/ffi_pb.cjs';
14
+ import './proto/room_pb.cjs';
15
+ import './proto/participant_pb.cjs';
13
16
  import './proto/video_frame_pb.cjs';
17
+ import './proto/data_stream_pb.cjs';
18
+ import './proto/rpc_pb.cjs';
19
+ import './proto/track_publication_pb.cjs';
20
+ import './video_source.cjs';
14
21
  import './video_frame.cjs';
15
22
 
16
23
  interface AudioStreamOptions {
17
24
  noiseCancellation?: NoiseCancellationOptions;
18
25
  sampleRate?: number;
19
26
  numChannels?: number;
27
+ frameSizeMs?: number;
20
28
  }
21
29
  interface NoiseCancellationOptions {
22
30
  moduleId: string;
@@ -1,4 +1,3 @@
1
- import { ReadableStream } from 'node:stream/web';
2
1
  import { AudioFrame } from './audio_frame.js';
3
2
  import { Track } from './track.js';
4
3
  import './proto/audio_frame_pb.js';
@@ -9,14 +8,23 @@ import './proto/e2ee_pb.js';
9
8
  import './proto/handle_pb.js';
10
9
  import './audio_source.js';
11
10
  import './napi/native.d.js';
12
- import './video_source.js';
11
+ import './ffi_client.js';
12
+ import '@livekit/typed-emitter';
13
+ import './proto/ffi_pb.js';
14
+ import './proto/room_pb.js';
15
+ import './proto/participant_pb.js';
13
16
  import './proto/video_frame_pb.js';
17
+ import './proto/data_stream_pb.js';
18
+ import './proto/rpc_pb.js';
19
+ import './proto/track_publication_pb.js';
20
+ import './video_source.js';
14
21
  import './video_frame.js';
15
22
 
16
23
  interface AudioStreamOptions {
17
24
  noiseCancellation?: NoiseCancellationOptions;
18
25
  sampleRate?: number;
19
26
  numChannels?: number;
27
+ frameSizeMs?: number;
20
28
  }
21
29
  interface NoiseCancellationOptions {
22
30
  moduleId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"audio_stream.d.ts","sourceRoot":"","sources":["../src/audio_stream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAyB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAmFD,qBAAa,WAAY,SAAQ,cAAc,CAAC,UAAU,CAAC;gBAC7C,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM;gBAChC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;gBACrD,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB;CAQtD"}
1
+ {"version":3,"file":"audio_stream.d.ts","sourceRoot":"","sources":["../src/audio_stream.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAsFD,qBAAa,WAAY,SAAQ,cAAc,CAAC,UAAU,CAAC;gBAC7C,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM;gBAChC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;gBACrD,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB;CAQtD"}
@@ -1,4 +1,3 @@
1
- import { ReadableStream } from "node:stream/web";
2
1
  import { AudioFrame } from "./audio_frame.js";
3
2
  import { FfiClient, FfiClientEvent, FfiHandle } from "./ffi_client.js";
4
3
  import { AudioStreamType, NewAudioStreamRequest } from "./proto/audio_frame_pb.js";
@@ -27,6 +26,7 @@ class AudioStreamSource {
27
26
  this.sampleRate = sampleRateOrOptions.sampleRate ?? 48e3;
28
27
  this.numChannels = sampleRateOrOptions.numChannels ?? 1;
29
28
  this.ncOptions = sampleRateOrOptions.noiseCancellation;
29
+ this.frameSizeMs = sampleRateOrOptions.frameSizeMs;
30
30
  } else {
31
31
  this.sampleRate = sampleRateOrOptions ?? 48e3;
32
32
  this.numChannels = numChannels ?? 1;
@@ -36,6 +36,7 @@ class AudioStreamSource {
36
36
  trackHandle: track.ffi_handle.handle,
37
37
  sampleRate: this.sampleRate,
38
38
  numChannels: this.numChannels,
39
+ frameSizeMs: this.frameSizeMs,
39
40
  ...this.ncOptions ? {
40
41
  audioFilterModuleId: this.ncOptions.moduleId,
41
42
  audioFilterOptions: JSON.stringify(this.ncOptions.options)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/audio_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadableStream, type UnderlyingSource } from 'node:stream/web';\nimport { AudioFrame } from './audio_frame.js';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type { NewAudioStreamResponse } from './proto/audio_frame_pb.js';\nimport { AudioStreamType, NewAudioStreamRequest } from './proto/audio_frame_pb.js';\nimport type { Track } from './track.js';\n\nexport interface AudioStreamOptions {\n noiseCancellation?: NoiseCancellationOptions;\n sampleRate?: number;\n numChannels?: number;\n}\n\nexport interface NoiseCancellationOptions {\n moduleId: string;\n options: Record<string, any>;\n}\n\nclass AudioStreamSource implements UnderlyingSource<AudioFrame> {\n private controller?: ReadableStreamDefaultController<AudioFrame>;\n private ffiHandle: FfiHandle;\n private sampleRate: number;\n private numChannels: number;\n private ncOptions?: NoiseCancellationOptions;\n\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n if (sampleRateOrOptions !== undefined && typeof sampleRateOrOptions !== 'number') {\n this.sampleRate = sampleRateOrOptions.sampleRate ?? 48000;\n this.numChannels = sampleRateOrOptions.numChannels ?? 1;\n this.ncOptions = sampleRateOrOptions.noiseCancellation;\n } else {\n this.sampleRate = (sampleRateOrOptions as number) ?? 48000;\n this.numChannels = numChannels ?? 1;\n }\n\n const req = new NewAudioStreamRequest({\n type: AudioStreamType.AUDIO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n sampleRate: this.sampleRate,\n numChannels: this.numChannels,\n ...(this.ncOptions\n ? {\n audioFilterModuleId: this.ncOptions.moduleId,\n audioFilterOptions: JSON.stringify(this.ncOptions.options),\n }\n : {}),\n });\n\n const res = FfiClient.instance.request<NewAudioStreamResponse>({\n message: {\n case: 'newAudioStream',\n value: req,\n },\n });\n\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 (!this.controller) {\n throw new Error('Stream controller not initialized');\n }\n\n if (\n ev.message.case != 'audioStreamEvent' ||\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 frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame!);\n this.controller.enqueue(frame);\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.controller.close();\n break;\n }\n };\n\n start(controller: ReadableStreamDefaultController<AudioFrame>) {\n this.controller = controller;\n }\n\n cancel() {\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.ffiHandle.dispose();\n }\n}\n\nexport class AudioStream extends ReadableStream<AudioFrame> {\n constructor(track: Track);\n constructor(track: Track, sampleRate: number);\n constructor(track: Track, sampleRate: number, numChannels: number);\n constructor(track: Track, options: AudioStreamOptions);\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n super(new AudioStreamSource(track, sampleRateOrOptions, numChannels));\n }\n}\n"],"mappings":"AAGA,SAAS,sBAA6C;AACtD,SAAS,kBAAkB;AAE3B,SAAS,W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,SAAK,YAAY,IAAI,UAAU,IAAI,OAAQ,OAAQ,EAAG;AAEtD,cAAU,SAAS,GAAG,eAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EA2BA,MAAM,YAAyD;AAC7D,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,SAAS;AACP,cAAU,SAAS,IAAI,eAAe,UAAU,KAAK,OAAO;AAC5D,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAEO,MAAM,oBAAoB,eAA2B;AAAA,EAK1D,YACE,OACA,qBACA,aACA;AACA,UAAM,IAAI,kBAAkB,OAAO,qBAAqB,WAAW,CAAC;AAAA,EACtE;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/audio_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { UnderlyingSource } from 'node:stream/web';\nimport { AudioFrame } from './audio_frame.js';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type { NewAudioStreamResponse } from './proto/audio_frame_pb.js';\nimport { AudioStreamType, NewAudioStreamRequest } from './proto/audio_frame_pb.js';\nimport type { Track } from './track.js';\n\nexport interface AudioStreamOptions {\n noiseCancellation?: NoiseCancellationOptions;\n sampleRate?: number;\n numChannels?: number;\n frameSizeMs?: number;\n}\n\nexport interface NoiseCancellationOptions {\n moduleId: string;\n options: Record<string, any>;\n}\n\nclass AudioStreamSource implements UnderlyingSource<AudioFrame> {\n private controller?: ReadableStreamDefaultController<AudioFrame>;\n private ffiHandle: FfiHandle;\n private sampleRate: number;\n private numChannels: number;\n private ncOptions?: NoiseCancellationOptions;\n private frameSizeMs?: number;\n\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,\n numChannels?: number,\n ) {\n if (sampleRateOrOptions !== undefined && typeof sampleRateOrOptions !== 'number') {\n this.sampleRate = sampleRateOrOptions.sampleRate ?? 48000;\n this.numChannels = sampleRateOrOptions.numChannels ?? 1;\n this.ncOptions = sampleRateOrOptions.noiseCancellation;\n this.frameSizeMs = sampleRateOrOptions.frameSizeMs;\n } else {\n this.sampleRate = (sampleRateOrOptions as number) ?? 48000;\n this.numChannels = numChannels ?? 1;\n }\n\n const req = new NewAudioStreamRequest({\n type: AudioStreamType.AUDIO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n sampleRate: this.sampleRate,\n numChannels: this.numChannels,\n frameSizeMs: this.frameSizeMs,\n ...(this.ncOptions\n ? {\n audioFilterModuleId: this.ncOptions.moduleId,\n audioFilterOptions: JSON.stringify(this.ncOptions.options),\n }\n : {}),\n });\n\n const res = FfiClient.instance.request<NewAudioStreamResponse>({\n message: {\n case: 'newAudioStream',\n value: req,\n },\n });\n\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 (!this.controller) {\n throw new Error('Stream controller not initialized');\n }\n\n if (\n ev.message.case != 'audioStreamEvent' ||\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 frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame!);\n this.controller.enqueue(frame);\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.controller.close();\n break;\n }\n };\n\n start(controller: ReadableStreamDefaultController<AudioFrame>) {\n this.controller = controller;\n }\n\n cancel() {\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n this.ffiHandle.dispose();\n }\n}\n\nexport class AudioStream extends ReadableStream<AudioFrame> {\n constructor(track: Track);\n constructor(track: Track, sampleRate: number);\n constructor(track: Track, sampleRate: number, numChannels: number);\n constructor(track: Track, options: AudioStreamOptions);\n constructor(\n track: Track,\n sampleRateOrOptions?: number | AudioStreamOptions,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AAAA,MAC3D,IACA,CAAC;AAAA,IACP,CAAC;AAED,UAAM,MAAM,UAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,YAAY,IAAI,UAAU,IAAI,OAAQ,OAAQ,EAAG;AAEtD,cAAU,SAAS,GAAG,eAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EA2BA,MAAM,YAAyD;AAC7D,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,SAAS;AACP,cAAU,SAAS,IAAI,eAAe,UAAU,KAAK,OAAO;AAC5D,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAEO,MAAM,oBAAoB,eAA2B;AAAA,EAK1D,YACE,OACA,qBACA,aACA;AACA,UAAM,IAAI,kBAAkB,OAAO,qBAAqB,WAAW,CAAC;AAAA,EACtE;AACF;","names":[]}
@@ -1,6 +1,5 @@
1
- export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, B as ByteStreamReader, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions, T as TextStreamReader } from '../stream_reader-a8_oiaOi.cjs';
1
+ export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, B as ByteStreamReader, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions, T as TextStreamReader } from '../stream_reader-Ch2zvjU3.cjs';
2
2
  export { ByteStreamWriter, TextStreamWriter } from './stream_writer.cjs';
3
- import 'node:stream/web';
4
3
  import '../proto/room_pb.cjs';
5
4
  import '@bufbuild/protobuf';
6
5
  import '../proto/participant_pb.cjs';
@@ -9,3 +8,4 @@ import '../proto/track_pb.cjs';
9
8
  import '../proto/stats_pb.cjs';
10
9
  import '../proto/e2ee_pb.cjs';
11
10
  import '../proto/video_frame_pb.cjs';
11
+ import '../proto/data_stream_pb.cjs';
@@ -1,6 +1,5 @@
1
- export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, B as ByteStreamReader, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions, T as TextStreamReader } from '../stream_reader-DWUV4eJB.js';
1
+ export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, B as ByteStreamReader, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions, T as TextStreamReader } from '../stream_reader-DRyR29vo.js';
2
2
  export { ByteStreamWriter, TextStreamWriter } from './stream_writer.js';
3
- import 'node:stream/web';
4
3
  import '../proto/room_pb.js';
5
4
  import '@bufbuild/protobuf';
6
5
  import '../proto/participant_pb.js';
@@ -9,3 +8,4 @@ import '../proto/track_pb.js';
9
8
  import '../proto/stats_pb.js';
10
9
  import '../proto/e2ee_pb.js';
11
10
  import '../proto/video_frame_pb.js';
11
+ import '../proto/data_stream_pb.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data_streams/stream_reader.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ReadableStream } from 'node:stream/web';\nimport { log } from '../log.js';\nimport type { DataStream_Chunk } from '../proto/room_pb.js';\nimport { bigIntToNumber } from '../utils.js';\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nabstract class BaseStreamReader<T extends BaseStreamInfo> {\n protected reader: ReadableStream<DataStream_Chunk>;\n\n protected totalByteSize?: number;\n\n protected _info: T;\n\n protected bytesReceived: number;\n\n get info() {\n return this._info;\n }\n\n constructor(info: T, stream: ReadableStream<DataStream_Chunk>, totalByteSize?: number) {\n this.reader = stream;\n this.totalByteSize = totalByteSize;\n this._info = info;\n this.bytesReceived = 0;\n }\n\n protected abstract handleChunkReceived(chunk: DataStream_Chunk): void;\n\n onProgress?: (progress: number | undefined) => void;\n\n abstract readAll(): Promise<string | Array<Uint8Array>>;\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class ByteStreamReader extends BaseStreamReader<ByteStreamInfo> {\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n this.bytesReceived += chunk.content!.byteLength;\n const currentProgress = this.totalByteSize\n ? this.bytesReceived / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n\n return {\n next: async (): Promise<IteratorResult<Uint8Array>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined as any };\n } else {\n this.handleChunkReceived(value);\n return { done: false, value: value.content! };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<Uint8Array> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<Array<Uint8Array>> {\n const chunks: Set<Uint8Array> = new Set();\n for await (const chunk of this) {\n chunks.add(chunk);\n }\n return Array.from(chunks);\n }\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class TextStreamReader extends BaseStreamReader<TextStreamInfo> {\n private receivedChunks: Map<number, DataStream_Chunk>;\n\n /**\n * A TextStreamReader instance can be used as an AsyncIterator that returns the entire string\n * that has been received up to the current point in time.\n */\n constructor(\n info: TextStreamInfo,\n stream: ReadableStream<DataStream_Chunk>,\n totalChunkCount?: number,\n ) {\n super(info, stream, totalChunkCount);\n this.receivedChunks = new Map();\n }\n\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n const index = bigIntToNumber(chunk.chunkIndex!);\n const previousChunkAtIndex = this.receivedChunks.get(index!);\n if (previousChunkAtIndex && previousChunkAtIndex.version! > chunk.version!) {\n // we have a newer version already, dropping the old one\n return;\n }\n this.receivedChunks.set(index, chunk);\n const currentProgress = this.totalByteSize\n ? this.receivedChunks.size / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n /**\n * Async iterator implementation to allow usage of `for await...of` syntax.\n * Yields structured chunks from the stream.\n *\n */\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n const decoder = new TextDecoder();\n\n return {\n next: async (): Promise<IteratorResult<string>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined };\n } else {\n this.handleChunkReceived(value);\n return {\n done: false,\n value: decoder.decode(value.content!),\n };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<string> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<string> {\n let finalString: string = '';\n for await (const chunk of this) {\n finalString += chunk;\n }\n return finalString;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAAoB;AAEpB,mBAA+B;AAG/B,MAAe,iBAA2C;AAAA,EASxD,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,YAAY,MAAS,QAA0C,eAAwB;AACrF,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,QAAQ;AACb,SAAK,gBAAgB;AAAA,EACvB;AAOF;AAKO,MAAM,yBAAyB,iBAAiC;AAAA,EAC3D,oBAAoB,OAAyB;AAxCzD;AAyCI,SAAK,iBAAiB,MAAM,QAAS;AACrC,UAAM,kBAAkB,KAAK,gBACzB,KAAK,gBAAgB,KAAK,gBAC1B;AACJ,eAAK,eAAL,8BAAkB;AAAA,EACpB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAI;AACvB,UAAM,SAAS,KAAK,OAAO,UAAU;AAErC,WAAO;AAAA,MACL,MAAM,YAAiD;AACrD,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR,mBAAO,EA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AAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR,mBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,UACxC,OAAO;AACL,iBAAK,oBAAoB,KAAK;AAC9B,mBAAO;AAAA,cACL,MAAM;AAAA,cACN,OAAO,QAAQ,OAAO,MAAM,OAAQ;AAAA,YACtC;AAAA,UACF;AAAA,QACF,SAAS,OAAO;AACd,yBAAI,MAAM,kCAAkC,KAAK;AACjD,iBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,QACxC;AAAA,MACF;AAAA,MAEA,SAAiC;AAC/B,eAAO,YAAY;AACnB,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,UAA2B;AAC/B,QAAI,cAAsB;AAC1B,qBAAiB,SAAS,MAAM;AAC9B,qBAAe;AAAA,IACjB;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/data_streams/stream_reader.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { log } from '../log.js';\nimport type { DataStream_Chunk } from '../proto/room_pb.js';\nimport { bigIntToNumber } from '../utils.js';\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nabstract class BaseStreamReader<T extends BaseStreamInfo> {\n protected reader: ReadableStream<DataStream_Chunk>;\n\n protected totalByteSize?: number;\n\n protected _info: T;\n\n protected bytesReceived: number;\n\n get info() {\n return this._info;\n }\n\n constructor(info: T, stream: ReadableStream<DataStream_Chunk>, totalByteSize?: number) {\n this.reader = stream;\n this.totalByteSize = totalByteSize;\n this._info = info;\n this.bytesReceived = 0;\n }\n\n protected abstract handleChunkReceived(chunk: DataStream_Chunk): void;\n\n onProgress?: (progress: number | undefined) => void;\n\n abstract readAll(): Promise<string | Array<Uint8Array>>;\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class ByteStreamReader extends BaseStreamReader<ByteStreamInfo> {\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n this.bytesReceived += chunk.content!.byteLength;\n const currentProgress = this.totalByteSize\n ? this.bytesReceived / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n\n return {\n next: async (): Promise<IteratorResult<Uint8Array>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined as any };\n } else {\n this.handleChunkReceived(value);\n return { done: false, value: value.content! };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<Uint8Array> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<Array<Uint8Array>> {\n const chunks: Set<Uint8Array> = new Set();\n for await (const chunk of this) {\n chunks.add(chunk);\n }\n return Array.from(chunks);\n }\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class TextStreamReader extends BaseStreamReader<TextStreamInfo> {\n private receivedChunks: Map<number, DataStream_Chunk>;\n\n /**\n * A TextStreamReader instance can be used as an AsyncIterator that returns the entire string\n * that has been received up to the current point in time.\n */\n constructor(\n info: TextStreamInfo,\n stream: ReadableStream<DataStream_Chunk>,\n totalChunkCount?: number,\n ) {\n super(info, stream, totalChunkCount);\n this.receivedChunks = new Map();\n }\n\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n const index = bigIntToNumber(chunk.chunkIndex!);\n const previousChunkAtIndex = this.receivedChunks.get(index!);\n if (previousChunkAtIndex && previousChunkAtIndex.version! > chunk.version!) {\n // we have a newer version already, dropping the old one\n return;\n }\n this.receivedChunks.set(index, chunk);\n const currentProgress = this.totalByteSize\n ? this.receivedChunks.size / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n /**\n * Async iterator implementation to allow usage of `for await...of` syntax.\n * Yields structured chunks from the stream.\n *\n */\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n const decoder = new TextDecoder();\n\n return {\n next: async (): Promise<IteratorResult<string>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined };\n } else {\n this.handleChunkReceived(value);\n return {\n done: false,\n value: decoder.decode(value.content!),\n };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<string> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<string> {\n let finalString: string = '';\n for await (const chunk of this) {\n finalString += chunk;\n }\n return finalString;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AAEpB,mBAA+B;AAG/B,MAAe,iBAA2C;AAAA,EASxD,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,YAAY,MAAS,QAA0C,eAAwB;AACrF,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,QAAQ;AACb,SAAK,gBAAgB;AAAA,EACvB;AAOF;AAKO,MAAM,yBAAyB,iBAAiC;AAAA,EAC3D,oBAAoB,OAAyB;AAvCzD;AAwCI,SAAK,iBAAiB,MAAM,QAAS;AACrC,UAAM,kBAAkB,KAAK,gBACzB,KAAK,gBAAgB,KAAK,gBAC1B;AACJ,eAAK,eAAL,8BAAkB;AAAA,EACpB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAI;AACvB,UAAM,SAAS,KAAK,OAAO,UAAU;AAErC,WAAO;AAAA,MACL,MAAM,YAAiD;AACrD,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR,mBAAO,EAAE,MAAM,MAAM,OAAO,OAAiB;AAAA,UAC/C,OAAO;AACL,iBAAK,oBAAoB,KAAK;AAC9B,mBAAO,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OAAU;AAAA,UACxC,OAAO;AACL,iBAAK,oBAAoB,KAAK;AAC9B,mBAAO;AAAA,cACL,MAAM;AAAA,cACN,OAAO,QAAQ,OAAO,MAAM,OAAQ;AAAA,YACtC;AAAA,UACF;AAAA,QACF,SAAS,OAAO;AACd,yBAAI,MAAM,kCAAkC,KAAK;AACjD,iBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,QACxC;AAAA,MACF;AAAA,MAEA,SAAiC;AAC/B,eAAO,YAAY;AACnB,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,UAA2B;AAC/B,QAAI,cAAsB;AAC1B,qBAAiB,SAAS,MAAM;AAC9B,qBAAe;AAAA,IACjB;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,6 +1,5 @@
1
- import 'node:stream/web';
2
1
  import '../proto/room_pb.cjs';
3
- export { B as ByteStreamReader, T as TextStreamReader } from '../stream_reader-a8_oiaOi.cjs';
2
+ export { B as ByteStreamReader, T as TextStreamReader } from '../stream_reader-Ch2zvjU3.cjs';
4
3
  import '@bufbuild/protobuf';
5
4
  import '../proto/participant_pb.cjs';
6
5
  import '../proto/handle_pb.cjs';
@@ -8,3 +7,4 @@ import '../proto/track_pb.cjs';
8
7
  import '../proto/stats_pb.cjs';
9
8
  import '../proto/e2ee_pb.cjs';
10
9
  import '../proto/video_frame_pb.cjs';
10
+ import '../proto/data_stream_pb.cjs';
@@ -1,6 +1,5 @@
1
- import 'node:stream/web';
2
1
  import '../proto/room_pb.js';
3
- export { B as ByteStreamReader, T as TextStreamReader } from '../stream_reader-DWUV4eJB.js';
2
+ export { B as ByteStreamReader, T as TextStreamReader } from '../stream_reader-DRyR29vo.js';
4
3
  import '@bufbuild/protobuf';
5
4
  import '../proto/participant_pb.js';
6
5
  import '../proto/handle_pb.js';
@@ -8,3 +7,4 @@ import '../proto/track_pb.js';
8
7
  import '../proto/stats_pb.js';
9
8
  import '../proto/e2ee_pb.js';
10
9
  import '../proto/video_frame_pb.js';
10
+ import '../proto/data_stream_pb.js';
@@ -1 +1 @@
1
- {"version":3,"file":"stream_reader.d.ts","sourceRoot":"","sources":["../../src/data_streams/stream_reader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjF,uBAAe,gBAAgB,CAAC,CAAC,SAAS,cAAc;IACtD,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC;IAEnD,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEjC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IAEnB,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC;IAEhC,IAAI,IAAI,MAEP;gBAEW,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC,EAAE,MAAM;IAOrF,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAErE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAEpD,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;CACxD;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,cAAc,CAAC;IACpE,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;IAQrD,CAAC,MAAM,CAAC,aAAa,CAAC;oBAIF,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;kBAezC,cAAc,CAAC,UAAU,CAAC;;IA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E,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAEpD,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;CACxD;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,cAAc,CAAC;IACpE,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;IAQrD,CAAC,MAAM,CAAC,aAAa,CAAC;oBAIF,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;kBAezC,cAAc,CAAC,UAAU,CAAC;;IAOlC,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;CAO5C;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,cAAc,CAAC;IACpE,OAAO,CAAC,cAAc,CAAgC;IAEtD;;;OAGG;gBAED,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,cAAc,CAAC,gBAAgB,CAAC,EACxC,eAAe,CAAC,EAAE,MAAM;IAM1B,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;IAcrD;;;;OAIG;IACH,CAAC,MAAM,CAAC,aAAa,CAAC;oBAKF,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;kBAkBrC,cAAc,CAAC,MAAM,CAAC;;IAO9B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAOjC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data_streams/stream_reader.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ReadableStream } from 'node:stream/web';\nimport { log } from '../log.js';\nimport type { DataStream_Chunk } from '../proto/room_pb.js';\nimport { bigIntToNumber } from '../utils.js';\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nabstract class BaseStreamReader<T extends BaseStreamInfo> {\n protected reader: ReadableStream<DataStream_Chunk>;\n\n protected totalByteSize?: number;\n\n protected _info: T;\n\n protected bytesReceived: number;\n\n get info() {\n return this._info;\n }\n\n constructor(info: T, stream: ReadableStream<DataStream_Chunk>, totalByteSize?: number) {\n this.reader = stream;\n this.totalByteSize = totalByteSize;\n this._info = info;\n this.bytesReceived = 0;\n }\n\n protected abstract handleChunkReceived(chunk: DataStream_Chunk): void;\n\n onProgress?: (progress: number | undefined) => void;\n\n abstract readAll(): Promise<string | Array<Uint8Array>>;\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class ByteStreamReader extends BaseStreamReader<ByteStreamInfo> {\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n this.bytesReceived += chunk.content!.byteLength;\n const currentProgress = this.totalByteSize\n ? this.bytesReceived / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n\n return {\n next: async (): Promise<IteratorResult<Uint8Array>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined as any };\n } else {\n this.handleChunkReceived(value);\n return { done: false, value: value.content! };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<Uint8Array> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<Array<Uint8Array>> {\n const chunks: Set<Uint8Array> = new Set();\n for await (const chunk of this) {\n chunks.add(chunk);\n }\n return Array.from(chunks);\n }\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class TextStreamReader extends BaseStreamReader<TextStreamInfo> {\n private receivedChunks: Map<number, DataStream_Chunk>;\n\n /**\n * A TextStreamReader instance can be used as an AsyncIterator that returns the entire string\n * that has been received up to the current point in time.\n */\n constructor(\n info: TextStreamInfo,\n stream: ReadableStream<DataStream_Chunk>,\n totalChunkCount?: number,\n ) {\n super(info, stream, totalChunkCount);\n this.receivedChunks = new Map();\n }\n\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n const index = bigIntToNumber(chunk.chunkIndex!);\n const previousChunkAtIndex = this.receivedChunks.get(index!);\n if (previousChunkAtIndex && previousChunkAtIndex.version! > chunk.version!) {\n // we have a newer version already, dropping the old one\n return;\n }\n this.receivedChunks.set(index, chunk);\n const currentProgress = this.totalByteSize\n ? this.receivedChunks.size / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n /**\n * Async iterator implementation to allow usage of `for await...of` syntax.\n * Yields structured chunks from the stream.\n *\n */\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n const decoder = new TextDecoder();\n\n return {\n next: async (): Promise<IteratorResult<string>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined };\n } else {\n this.handleChunkReceived(value);\n return {\n done: false,\n value: decoder.decode(value.content!),\n };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<string> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<string> {\n let finalString: string = '';\n for await (const chunk of this) {\n finalString += chunk;\n }\n return finalString;\n }\n}\n"],"mappings":"AAIA,SAAS,WAAW;AAEpB,SAAS,sBAAsB;AAG/B,MAAe,iBAA2C;AAAA,EASxD,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,YAAY,MAAS,QAA0C,eAAwB;AACrF,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,QAAQ;AACb,SAAK,gBAAgB;AAAA,EACvB;AAOF;AAKO,MAAM,yBAAyB,iBAAiC;AAAA,EAC3D,oBAAoB,OAAyB;AAxCzD;AAyCI,SAAK,iBAAiB,MAAM,QAAS;AACrC,UAAM,kBAAkB,KAAK,gBACzB,KAAK,gBAAgB,KAAK,gBAC1B;AACJ,eAAK,eAAL,8BAAkB;AAAA,EACpB;AAAA,EAEA,CAAC,O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AA;AAAA;AAAA;AAAA,EAOA,CAAC,OAAO,aAAa,IAAI;AACvB,UAAM,SAAS,KAAK,OAAO,UAAU;AACrC,UAAM,UAAU,IAAI,YAAY;AAEhC,WAAO;AAAA,MACL,MAAM,YAA6C;AACjD,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR,mBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,UACxC,OAAO;AACL,iBAAK,oBAAoB,KAAK;AAC9B,mBAAO;AAAA,cACL,MAAM;AAAA,cACN,OAAO,QAAQ,OAAO,MAAM,OAAQ;AAAA,YACtC;AAAA,UACF;AAAA,QACF,SAAS,OAAO;AACd,cAAI,MAAM,kCAAkC,KAAK;AACjD,iBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,QACxC;AAAA,MACF;AAAA,MAEA,SAAiC;AAC/B,eAAO,YAAY;AACnB,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,UAA2B;AAC/B,QAAI,cAAsB;AAC1B,qBAAiB,SAAS,MAAM;AAC9B,qBAAe;AAAA,IACjB;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/data_streams/stream_reader.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { log } from '../log.js';\nimport type { DataStream_Chunk } from '../proto/room_pb.js';\nimport { bigIntToNumber } from '../utils.js';\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nabstract class BaseStreamReader<T extends BaseStreamInfo> {\n protected reader: ReadableStream<DataStream_Chunk>;\n\n protected totalByteSize?: number;\n\n protected _info: T;\n\n protected bytesReceived: number;\n\n get info() {\n return this._info;\n }\n\n constructor(info: T, stream: ReadableStream<DataStream_Chunk>, totalByteSize?: number) {\n this.reader = stream;\n this.totalByteSize = totalByteSize;\n this._info = info;\n this.bytesReceived = 0;\n }\n\n protected abstract handleChunkReceived(chunk: DataStream_Chunk): void;\n\n onProgress?: (progress: number | undefined) => void;\n\n abstract readAll(): Promise<string | Array<Uint8Array>>;\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class ByteStreamReader extends BaseStreamReader<ByteStreamInfo> {\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n this.bytesReceived += chunk.content!.byteLength;\n const currentProgress = this.totalByteSize\n ? this.bytesReceived / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n\n return {\n next: async (): Promise<IteratorResult<Uint8Array>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined as any };\n } else {\n this.handleChunkReceived(value);\n return { done: false, value: value.content! };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<Uint8Array> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<Array<Uint8Array>> {\n const chunks: Set<Uint8Array> = new Set();\n for await (const chunk of this) {\n chunks.add(chunk);\n }\n return Array.from(chunks);\n }\n}\n\n/**\n * A class to read chunks from a ReadableStream and provide them in a structured format.\n */\nexport class TextStreamReader extends BaseStreamReader<TextStreamInfo> {\n private receivedChunks: Map<number, DataStream_Chunk>;\n\n /**\n * A TextStreamReader instance can be used as an AsyncIterator that returns the entire string\n * that has been received up to the current point in time.\n */\n constructor(\n info: TextStreamInfo,\n stream: ReadableStream<DataStream_Chunk>,\n totalChunkCount?: number,\n ) {\n super(info, stream, totalChunkCount);\n this.receivedChunks = new Map();\n }\n\n protected handleChunkReceived(chunk: DataStream_Chunk) {\n const index = bigIntToNumber(chunk.chunkIndex!);\n const previousChunkAtIndex = this.receivedChunks.get(index!);\n if (previousChunkAtIndex && previousChunkAtIndex.version! > chunk.version!) {\n // we have a newer version already, dropping the old one\n return;\n }\n this.receivedChunks.set(index, chunk);\n const currentProgress = this.totalByteSize\n ? this.receivedChunks.size / this.totalByteSize\n : undefined;\n this.onProgress?.(currentProgress);\n }\n\n /**\n * Async iterator implementation to allow usage of `for await...of` syntax.\n * Yields structured chunks from the stream.\n *\n */\n [Symbol.asyncIterator]() {\n const reader = this.reader.getReader();\n const decoder = new TextDecoder();\n\n return {\n next: async (): Promise<IteratorResult<string>> => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n return { done: true, value: undefined };\n } else {\n this.handleChunkReceived(value);\n return {\n done: false,\n value: decoder.decode(value.content!),\n };\n }\n } catch (error) {\n log.error('error processing stream update', error);\n return { done: true, value: undefined };\n }\n },\n\n return(): IteratorResult<string> {\n reader.releaseLock();\n return { done: true, value: undefined };\n },\n };\n }\n\n async readAll(): Promise<string> {\n let finalString: string = '';\n for await (const chunk of this) {\n finalString += chunk;\n }\n return finalString;\n }\n}\n"],"mappings":"AAGA,SAAS,WAAW;AAEpB,SAAS,sBAAsB;AAG/B,MAAe,iBAA2C;AAAA,EASxD,IAAI,OAAO;AACT,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,YAAY,MAAS,QAA0C,eAAwB;AACrF,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,QAAQ;AACb,SAAK,gBAAgB;AAAA,EACvB;AAOF;AAKO,MAAM,yBAAyB,iBAAiC;AAAA,EAC3D,oBAAoB,OAAyB;AAvCzD;AAwCI,SAAK,iBAAiB,MAAM,QAAS;AACrC,UAAM,kBAAkB,KAAK,gBACzB,KAAK,gBAAgB,KAAK,gBAC1B;AACJ,eAAK,eAAL,8BAAkB;AAAA,EACpB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAI;AACvB,UAAM,SAAS,KAAK,OAAO,UAAU;AAErC,WAAO;AAAA,MACL,MAAM,YAAiD;AACrD,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MA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,MAAM,YAA6C;AACjD,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR,mBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,UACxC,OAAO;AACL,iBAAK,oBAAoB,KAAK;AAC9B,mBAAO;AAAA,cACL,MAAM;AAAA,cACN,OAAO,QAAQ,OAAO,MAAM,OAAQ;AAAA,YACtC;AAAA,UACF;AAAA,QACF,SAAS,OAAO;AACd,cAAI,MAAM,kCAAkC,KAAK;AACjD,iBAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,QACxC;AAAA,MACF;AAAA,MAEA,SAAiC;AAC/B,eAAO,YAAY;AACnB,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,UAA2B;AAC/B,QAAI,cAAsB;AAC1B,qBAAiB,SAAS,MAAM;AAC9B,qBAAe;AAAA,IACjB;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data_streams/stream_writer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { WritableStream } from 'node:stream/web';\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nclass BaseStreamWriter<T, InfoType extends BaseStreamInfo> {\n protected writableStream: WritableStream<T>;\n\n protected defaultWriter: WritableStreamDefaultWriter<T>;\n\n protected onClose?: () => void;\n\n readonly info: InfoType;\n\n constructor(writableStream: WritableStream<T>, info: InfoType, onClose?: () => void) {\n this.writableStream = writableStream;\n this.defaultWriter = writableStream.getWriter();\n this.onClose = onClose;\n this.info = info;\n }\n\n write(chunk: T): Promise<void> {\n return this.defaultWriter.write(chunk);\n }\n\n async close() {\n await this.defaultWriter.close();\n this.defaultWriter.releaseLock();\n this.onClose?.();\n }\n}\n\nexport class TextStreamWriter extends BaseStreamWriter<string, TextStreamInfo> {}\n\nexport class ByteStreamWriter extends BaseStreamWriter<Uint8Array, ByteStreamInfo> {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,MAAM,iBAAqD;AAAA,EASzD,YAAY,gBAAmC,MAAgB,SAAsB;AACnF,SAAK,iBAAiB;AACtB,SAAK,gBAAgB,eAAe,UAAU;AAC9C,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAM,OAAyB;AAC7B,WAAO,KAAK,cAAc,MAAM,KAAK;AAAA,EACvC;AAAA,EAEA,MAAM,QAAQ;AA1BhB;AA2BI,UAAM,KAAK,cAAc,MAAM;AAC/B,SAAK,cAAc,YAAY;AAC/B,eAAK,YAAL;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,iBAAyC;AAAC;AAEzE,MAAM,yBAAyB,iBAA6C;AAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/data_streams/stream_writer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nclass BaseStreamWriter<T, InfoType extends BaseStreamInfo> {\n protected writableStream: WritableStream<T>;\n\n protected defaultWriter: WritableStreamDefaultWriter<T>;\n\n protected onClose?: () => void;\n\n readonly info: InfoType;\n\n constructor(writableStream: WritableStream<T>, info: InfoType, onClose?: () => void) {\n this.writableStream = writableStream;\n this.defaultWriter = writableStream.getWriter();\n this.onClose = onClose;\n this.info = info;\n }\n\n write(chunk: T): Promise<void> {\n return this.defaultWriter.write(chunk);\n }\n\n async close() {\n await this.defaultWriter.close();\n this.defaultWriter.releaseLock();\n this.onClose?.();\n }\n}\n\nexport class TextStreamWriter extends BaseStreamWriter<string, TextStreamInfo> {}\n\nexport class ByteStreamWriter extends BaseStreamWriter<Uint8Array, ByteStreamInfo> {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,MAAM,iBAAqD;AAAA,EASzD,YAAY,gBAAmC,MAAgB,SAAsB;AACnF,SAAK,iBAAiB;AACtB,SAAK,gBAAgB,eAAe,UAAU;AAC9C,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAM,OAAyB;AAC7B,WAAO,KAAK,cAAc,MAAM,KAAK;AAAA,EACvC;AAAA,EAEA,MAAM,QAAQ;AAzBhB;AA0BI,UAAM,KAAK,cAAc,MAAM;AAC/B,SAAK,cAAc,YAAY;AAC/B,eAAK,YAAL;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,iBAAyC;AAAC;AAEzE,MAAM,yBAAyB,iBAA6C;AAAC;","names":[]}
@@ -1,5 +1,4 @@
1
- import { a as BaseStreamInfo, c as TextStreamInfo, b as ByteStreamInfo } from '../stream_reader-a8_oiaOi.cjs';
2
- import { WritableStream } from 'node:stream/web';
1
+ import { a as BaseStreamInfo, c as TextStreamInfo, b as ByteStreamInfo } from '../stream_reader-Ch2zvjU3.cjs';
3
2
  import '../proto/room_pb.cjs';
4
3
  import '@bufbuild/protobuf';
5
4
  import '../proto/participant_pb.cjs';
@@ -8,6 +7,7 @@ import '../proto/track_pb.cjs';
8
7
  import '../proto/stats_pb.cjs';
9
8
  import '../proto/e2ee_pb.cjs';
10
9
  import '../proto/video_frame_pb.cjs';
10
+ import '../proto/data_stream_pb.cjs';
11
11
 
12
12
  declare class BaseStreamWriter<T, InfoType extends BaseStreamInfo> {
13
13
  protected writableStream: WritableStream<T>;
@@ -1,5 +1,4 @@
1
- import { a as BaseStreamInfo, c as TextStreamInfo, b as ByteStreamInfo } from '../stream_reader-DWUV4eJB.js';
2
- import { WritableStream } from 'node:stream/web';
1
+ import { a as BaseStreamInfo, c as TextStreamInfo, b as ByteStreamInfo } from '../stream_reader-DRyR29vo.js';
3
2
  import '../proto/room_pb.js';
4
3
  import '@bufbuild/protobuf';
5
4
  import '../proto/participant_pb.js';
@@ -8,6 +7,7 @@ import '../proto/track_pb.js';
8
7
  import '../proto/stats_pb.js';
9
8
  import '../proto/e2ee_pb.js';
10
9
  import '../proto/video_frame_pb.js';
10
+ import '../proto/data_stream_pb.js';
11
11
 
12
12
  declare class BaseStreamWriter<T, InfoType extends BaseStreamInfo> {
13
13
  protected writableStream: WritableStream<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"stream_writer.d.ts","sourceRoot":"","sources":["../../src/data_streams/stream_writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjF,cAAM,gBAAgB,CAAC,CAAC,EAAE,QAAQ,SAAS,cAAc;IACvD,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAE5C,SAAS,CAAC,aAAa,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAC;IAExD,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAE/B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;gBAEZ,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;IAOnF,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxB,KAAK;CAKZ;AAED,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,MAAM,EAAE,cAAc,CAAC;CAAG;AAEjF,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,UAAU,EAAE,cAAc,CAAC;CAAG"}
1
+ {"version":3,"file":"stream_writer.d.ts","sourceRoot":"","sources":["../../src/data_streams/stream_writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjF,cAAM,gBAAgB,CAAC,CAAC,EAAE,QAAQ,SAAS,cAAc;IACvD,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAE5C,SAAS,CAAC,aAAa,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAC;IAExD,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAE/B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;gBAEZ,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;IAOnF,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxB,KAAK;CAKZ;AAED,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,MAAM,EAAE,cAAc,CAAC;CAAG;AAEjF,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,UAAU,EAAE,cAAc,CAAC;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data_streams/stream_writer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { WritableStream } from 'node:stream/web';\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nclass BaseStreamWriter<T, InfoType extends BaseStreamInfo> {\n protected writableStream: WritableStream<T>;\n\n protected defaultWriter: WritableStreamDefaultWriter<T>;\n\n protected onClose?: () => void;\n\n readonly info: InfoType;\n\n constructor(writableStream: WritableStream<T>, info: InfoType, onClose?: () => void) {\n this.writableStream = writableStream;\n this.defaultWriter = writableStream.getWriter();\n this.onClose = onClose;\n this.info = info;\n }\n\n write(chunk: T): Promise<void> {\n return this.defaultWriter.write(chunk);\n }\n\n async close() {\n await this.defaultWriter.close();\n this.defaultWriter.releaseLock();\n this.onClose?.();\n }\n}\n\nexport class TextStreamWriter extends BaseStreamWriter<string, TextStreamInfo> {}\n\nexport class ByteStreamWriter extends BaseStreamWriter<Uint8Array, ByteStreamInfo> {}\n"],"mappings":"AAMA,MAAM,iBAAqD;AAAA,EASzD,YAAY,gBAAmC,MAAgB,SAAsB;AACnF,SAAK,iBAAiB;AACtB,SAAK,gBAAgB,eAAe,UAAU;AAC9C,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAM,OAAyB;AAC7B,WAAO,KAAK,cAAc,MAAM,KAAK;AAAA,EACvC;AAAA,EAEA,MAAM,QAAQ;AA1BhB;AA2BI,UAAM,KAAK,cAAc,MAAM;AAC/B,SAAK,cAAc,YAAY;AAC/B,eAAK,YAAL;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,iBAAyC;AAAC;AAEzE,MAAM,yBAAyB,iBAA6C;AAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/data_streams/stream_writer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { BaseStreamInfo, ByteStreamInfo, TextStreamInfo } from './types.js';\n\nclass BaseStreamWriter<T, InfoType extends BaseStreamInfo> {\n protected writableStream: WritableStream<T>;\n\n protected defaultWriter: WritableStreamDefaultWriter<T>;\n\n protected onClose?: () => void;\n\n readonly info: InfoType;\n\n constructor(writableStream: WritableStream<T>, info: InfoType, onClose?: () => void) {\n this.writableStream = writableStream;\n this.defaultWriter = writableStream.getWriter();\n this.onClose = onClose;\n this.info = info;\n }\n\n write(chunk: T): Promise<void> {\n return this.defaultWriter.write(chunk);\n }\n\n async close() {\n await this.defaultWriter.close();\n this.defaultWriter.releaseLock();\n this.onClose?.();\n }\n}\n\nexport class TextStreamWriter extends BaseStreamWriter<string, TextStreamInfo> {}\n\nexport class ByteStreamWriter extends BaseStreamWriter<Uint8Array, ByteStreamInfo> {}\n"],"mappings":"AAKA,MAAM,iBAAqD;AAAA,EASzD,YAAY,gBAAmC,MAAgB,SAAsB;AACnF,SAAK,iBAAiB;AACtB,SAAK,gBAAgB,eAAe,UAAU;AAC9C,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAM,OAAyB;AAC7B,WAAO,KAAK,cAAc,MAAM,KAAK;AAAA,EACvC;AAAA,EAEA,MAAM,QAAQ;AAzBhB;AA0BI,UAAM,KAAK,cAAc,MAAM;AAC/B,SAAK,cAAc,YAAY;AAC/B,eAAK,YAAL;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,iBAAyC;AAAC;AAEzE,MAAM,yBAAyB,iBAA6C;AAAC;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import '../proto/room_pb.cjs';
2
- export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions } from '../stream_reader-a8_oiaOi.cjs';
2
+ export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions } from '../stream_reader-Ch2zvjU3.cjs';
3
3
  import '@bufbuild/protobuf';
4
4
  import '../proto/participant_pb.cjs';
5
5
  import '../proto/handle_pb.cjs';
@@ -7,4 +7,4 @@ import '../proto/track_pb.cjs';
7
7
  import '../proto/stats_pb.cjs';
8
8
  import '../proto/e2ee_pb.cjs';
9
9
  import '../proto/video_frame_pb.cjs';
10
- import 'node:stream/web';
10
+ import '../proto/data_stream_pb.cjs';
@@ -1,5 +1,5 @@
1
1
  import '../proto/room_pb.js';
2
- export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions } from '../stream_reader-DWUV4eJB.js';
2
+ export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions } from '../stream_reader-DRyR29vo.js';
3
3
  import '@bufbuild/protobuf';
4
4
  import '../proto/participant_pb.js';
5
5
  import '../proto/handle_pb.js';
@@ -7,4 +7,4 @@ import '../proto/track_pb.js';
7
7
  import '../proto/stats_pb.js';
8
8
  import '../proto/e2ee_pb.js';
9
9
  import '../proto/video_frame_pb.js';
10
- import 'node:stream/web';
10
+ import '../proto/data_stream_pb.js';
@@ -46,8 +46,10 @@ var FfiClientEvent = /* @__PURE__ */ ((FfiClientEvent2) => {
46
46
  class FfiClient extends import_events.default {
47
47
  /** @internal */
48
48
  static get instance() {
49
- if (!FfiClient._client) FfiClient._client = new FfiClient();
50
- return FfiClient._client;
49
+ if (!globalThis._ffiClientInstance) {
50
+ globalThis._ffiClientInstance = new FfiClient();
51
+ }
52
+ return globalThis._ffiClientInstance;
51
53
  }
52
54
  constructor() {
53
55
  super();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ffi_client.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { PartialMessage } from '@bufbuild/protobuf';\nimport type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';\nimport EventEmitter from 'events';\nimport {\n FfiHandle,\n livekitCopyBuffer,\n livekitDispose,\n livekitFfiRequest,\n livekitInitialize,\n livekitRetrievePtr,\n} from './napi/native.js';\nimport { FfiEvent, FfiRequest, FfiResponse } from './proto/ffi_pb.js';\nimport { SDK_VERSION } from './version.js';\n\nexport { FfiHandle, type FfiEvent, type FfiResponse, FfiRequest, livekitDispose as dispose };\n\nexport type FfiClientCallbacks = {\n ffi_event: (event: FfiEvent) => void;\n};\n\nexport enum FfiClientEvent {\n FfiEvent = 'ffi_event',\n}\n\nexport class FfiClient extends (EventEmitter as new () => TypedEmitter<FfiClientCallbacks>) {\n static _client?: FfiClient;\n\n /** @internal */\n static get instance(): FfiClient {\n if (!FfiClient._client) FfiClient._client = new FfiClient();\n\n return FfiClient._client;\n }\n\n constructor() {\n super();\n this.setMaxListeners(0);\n\n livekitInitialize(\n (event_data: Uint8Array) => {\n const event = FfiEvent.fromBinary(event_data);\n this.emit(FfiClientEvent.FfiEvent, event);\n },\n true,\n SDK_VERSION,\n );\n }\n\n request<T>(req: PartialMessage<FfiRequest>): T {\n const request = new FfiRequest(req);\n const req_data = request.toBinary();\n const res_data = livekitFfiRequest(req_data);\n return FfiResponse.fromBinary(res_data).message.value as T;\n }\n\n copyBuffer(ptr: bigint, len: number): Uint8Array {\n return livekitCopyBuffer(ptr, len);\n }\n\n retrievePtr(data: Uint8Array): bigint {\n return livekitRetrievePtr(data);\n }\n\n async waitFor<T>(predicate: (ev: FfiEvent) => boolean): Promise<T> {\n return new Promise<T>((resolve) => {\n const listener = (ev: FfiEvent) => {\n if (predicate(ev)) {\n this.off(FfiClientEvent.FfiEvent, listener);\n resolve(ev.message.value as T);\n }\n };\n this.on(FfiClientEvent.FfiEvent, listener);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAAyB;AACzB,oBAOO;AACP,oBAAkD;AAClD,qBAA4B;AAQrB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;AAIL,MAAM,kBAAmB,cAAAC,QAA4D;AAAA;AAAA,EAI1F,WAAW,WAAsB;AAC/B,QAAI,CAAC,UAAU,QAAS,WAAU,UAAU,IAAI,UAAU;AAE1D,WAAO,UAAU;AAAA,EACnB;AAAA,EAEA,cAAc;AACZ,UAAM;AACN,SAAK,gBAAgB,CAAC;AAEtB;AAAA,MACE,CAAC,eAA2B;AAC1B,cAAM,QAAQ,uBAAS,WAAW,UAAU;AAC5C,aAAK,KAAK,4BAAyB,KAAK;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAW,KAAoC;AAC7C,UAAM,UAAU,IAAI,yBAAW,GAAG;AAClC,UAAM,WAAW,QAAQ,SAAS;AAClC,UAAM,eAAW,iCAAkB,QAAQ;AAC3C,WAAO,0BAAY,WAAW,QAAQ,EAAE,QAAQ;AAAA,EAClD;AAAA,EAEA,WAAW,KAAa,KAAyB;AAC/C,eAAO,iCAAkB,KAAK,GAAG;AAAA,EACnC;AAAA,EAEA,YAAY,MAA0B;AACpC,eAAO,kCAAmB,IAAI;AAAA,EAChC;AAAA,EAEA,MAAM,QAAW,WAAkD;AACjE,WAAO,IAAI,QAAW,CAAC,YAAY;AACjC,YAAM,WAAW,CAAC,OAAiB;AACjC,YAAI,UAAU,EAAE,GAAG;AACjB,eAAK,IAAI,4BAAyB,QAAQ;AAC1C,kBAAQ,GAAG,QAAQ,KAAU;AAAA,QAC/B;AAAA,MACF;AACA,WAAK,GAAG,4BAAyB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;","names":["FfiClientEvent","EventEmitter"]}
1
+ {"version":3,"sources":["../src/ffi_client.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { PartialMessage } from '@bufbuild/protobuf';\nimport type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';\nimport EventEmitter from 'events';\nimport {\n FfiHandle,\n livekitCopyBuffer,\n livekitDispose,\n livekitFfiRequest,\n livekitInitialize,\n livekitRetrievePtr,\n} from './napi/native.js';\nimport { FfiEvent, FfiRequest, FfiResponse } from './proto/ffi_pb.js';\nimport { SDK_VERSION } from './version.js';\n\nexport { FfiHandle, type FfiEvent, type FfiResponse, FfiRequest, livekitDispose as dispose };\n\nexport type FfiClientCallbacks = {\n ffi_event: (event: FfiEvent) => void;\n};\n\nexport enum FfiClientEvent {\n FfiEvent = 'ffi_event',\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var _ffiClientInstance: FfiClient | undefined;\n}\n\nexport class FfiClient extends (EventEmitter as new () => TypedEmitter<FfiClientCallbacks>) {\n /** @internal */\n static get instance(): FfiClient {\n if (!globalThis._ffiClientInstance) {\n globalThis._ffiClientInstance = new FfiClient();\n }\n return globalThis._ffiClientInstance;\n }\n\n constructor() {\n super();\n this.setMaxListeners(0);\n\n livekitInitialize(\n (event_data: Uint8Array) => {\n const event = FfiEvent.fromBinary(event_data);\n this.emit(FfiClientEvent.FfiEvent, event);\n },\n true,\n SDK_VERSION,\n );\n }\n\n request<T>(req: PartialMessage<FfiRequest>): T {\n const request = new FfiRequest(req);\n const req_data = request.toBinary();\n const res_data = livekitFfiRequest(req_data);\n return FfiResponse.fromBinary(res_data).message.value as T;\n }\n\n copyBuffer(ptr: bigint, len: number): Uint8Array {\n return livekitCopyBuffer(ptr, len);\n }\n\n retrievePtr(data: Uint8Array): bigint {\n return livekitRetrievePtr(data);\n }\n\n async waitFor<T>(predicate: (ev: FfiEvent) => boolean): Promise<T> {\n return new Promise<T>((resolve) => {\n const listener = (ev: FfiEvent) => {\n if (predicate(ev)) {\n this.off(FfiClientEvent.FfiEvent, listener);\n resolve(ev.message.value as T);\n }\n };\n this.on(FfiClientEvent.FfiEvent, listener);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAAyB;AACzB,oBAOO;AACP,oBAAkD;AAClD,qBAA4B;AAQrB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;AASL,MAAM,kBAAmB,cAAAC,QAA4D;AAAA;AAAA,EAE1F,WAAW,WAAsB;AAC/B,QAAI,CAAC,WAAW,oBAAoB;AAClC,iBAAW,qBAAqB,IAAI,UAAU;AAAA,IAChD;AACA,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,cAAc;AACZ,UAAM;AACN,SAAK,gBAAgB,CAAC;AAEtB;AAAA,MACE,CAAC,eAA2B;AAC1B,cAAM,QAAQ,uBAAS,WAAW,UAAU;AAC5C,aAAK,KAAK,4BAAyB,KAAK;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAW,KAAoC;AAC7C,UAAM,UAAU,IAAI,yBAAW,GAAG;AAClC,UAAM,WAAW,QAAQ,SAAS;AAClC,UAAM,eAAW,iCAAkB,QAAQ;AAC3C,WAAO,0BAAY,WAAW,QAAQ,EAAE,QAAQ;AAAA,EAClD;AAAA,EAEA,WAAW,KAAa,KAAyB;AAC/C,eAAO,iCAAkB,KAAK,GAAG;AAAA,EACnC;AAAA,EAEA,YAAY,MAA0B;AACpC,eAAO,kCAAmB,IAAI;AAAA,EAChC;AAAA,EAEA,MAAM,QAAW,WAAkD;AACjE,WAAO,IAAI,QAAW,CAAC,YAAY;AACjC,YAAM,WAAW,CAAC,OAAiB;AACjC,YAAI,UAAU,EAAE,GAAG;AACjB,eAAK,IAAI,4BAAyB,QAAQ;AAC1C,kBAAQ,GAAG,QAAQ,KAAU;AAAA,QAC/B;AAAA,MACF;AACA,WAAK,GAAG,4BAAyB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;","names":["FfiClientEvent","EventEmitter"]}
@@ -10,6 +10,7 @@ import './proto/track_pb.cjs';
10
10
  import './proto/stats_pb.cjs';
11
11
  import './proto/e2ee_pb.cjs';
12
12
  import './proto/video_frame_pb.cjs';
13
+ import './proto/data_stream_pb.cjs';
13
14
  import './proto/audio_frame_pb.cjs';
14
15
  import './proto/rpc_pb.cjs';
15
16
  import './proto/track_publication_pb.cjs';
@@ -20,9 +21,11 @@ type FfiClientCallbacks = {
20
21
  declare enum FfiClientEvent {
21
22
  FfiEvent = "ffi_event"
22
23
  }
24
+ declare global {
25
+ var _ffiClientInstance: FfiClient | undefined;
26
+ }
23
27
  declare const FfiClient_base: new () => TypedEventEmitter<FfiClientCallbacks>;
24
28
  declare class FfiClient extends FfiClient_base {
25
- static _client?: FfiClient;
26
29
  /** @internal */
27
30
  static get instance(): FfiClient;
28
31
  constructor();
@@ -10,6 +10,7 @@ import './proto/track_pb.js';
10
10
  import './proto/stats_pb.js';
11
11
  import './proto/e2ee_pb.js';
12
12
  import './proto/video_frame_pb.js';
13
+ import './proto/data_stream_pb.js';
13
14
  import './proto/audio_frame_pb.js';
14
15
  import './proto/rpc_pb.js';
15
16
  import './proto/track_publication_pb.js';
@@ -20,9 +21,11 @@ type FfiClientCallbacks = {
20
21
  declare enum FfiClientEvent {
21
22
  FfiEvent = "ffi_event"
22
23
  }
24
+ declare global {
25
+ var _ffiClientInstance: FfiClient | undefined;
26
+ }
23
27
  declare const FfiClient_base: new () => TypedEventEmitter<FfiClientCallbacks>;
24
28
  declare class FfiClient extends FfiClient_base {
25
- static _client?: FfiClient;
26
29
  /** @internal */
27
30
  static get instance(): FfiClient;
28
31
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"ffi_client.d.ts","sourceRoot":"","sources":["../src/ffi_client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EACL,SAAS,EAET,cAAc,EAIf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGtE,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,UAAU,EAAE,cAAc,IAAI,OAAO,EAAE,CAAC;AAE7F,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,CAAC,KAAK,EAAE,QAAQ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AkB,EAAE,SAAS,GAAG,SAAS,CAAC;CAC/C;8BAE+C,UAAU,YAAY,CAAC,kBAAkB,CAAC;AAA1F,qBAAa,SAAU,SAAQ,cAA4D;IACzF,gBAAgB;IAChB,MAAM,KAAK,QAAQ,IAAI,SAAS,CAK/B;;IAgBD,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC;IAO9C,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU;IAIhD,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAI/B,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAWnE"}
@@ -16,8 +16,10 @@ var FfiClientEvent = /* @__PURE__ */ ((FfiClientEvent2) => {
16
16
  class FfiClient extends EventEmitter {
17
17
  /** @internal */
18
18
  static get instance() {
19
- if (!FfiClient._client) FfiClient._client = new FfiClient();
20
- return FfiClient._client;
19
+ if (!globalThis._ffiClientInstance) {
20
+ globalThis._ffiClientInstance = new FfiClient();
21
+ }
22
+ return globalThis._ffiClientInstance;
21
23
  }
22
24
  constructor() {
23
25
  super();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ffi_client.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { PartialMessage } from '@bufbuild/protobuf';\nimport type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';\nimport EventEmitter from 'events';\nimport {\n FfiHandle,\n livekitCopyBuffer,\n livekitDispose,\n livekitFfiRequest,\n livekitInitialize,\n livekitRetrievePtr,\n} from './napi/native.js';\nimport { FfiEvent, FfiRequest, FfiResponse } from './proto/ffi_pb.js';\nimport { SDK_VERSION } from './version.js';\n\nexport { FfiHandle, type FfiEvent, type FfiResponse, FfiRequest, livekitDispose as dispose };\n\nexport type FfiClientCallbacks = {\n ffi_event: (event: FfiEvent) => void;\n};\n\nexport enum FfiClientEvent {\n FfiEvent = 'ffi_event',\n}\n\nexport class FfiClient extends (EventEmitter as new () => TypedEmitter<FfiClientCallbacks>) {\n static _client?: FfiClient;\n\n /** @internal */\n static get instance(): FfiClient {\n if (!FfiClient._client) FfiClient._client = new FfiClient();\n\n return FfiClient._client;\n }\n\n constructor() {\n super();\n this.setMaxListeners(0);\n\n livekitInitialize(\n (event_data: Uint8Array) => {\n const event = FfiEvent.fromBinary(event_data);\n this.emit(FfiClientEvent.FfiEvent, event);\n },\n true,\n SDK_VERSION,\n );\n }\n\n request<T>(req: PartialMessage<FfiRequest>): T {\n const request = new FfiRequest(req);\n const req_data = request.toBinary();\n const res_data = livekitFfiRequest(req_data);\n return FfiResponse.fromBinary(res_data).message.value as T;\n }\n\n copyBuffer(ptr: bigint, len: number): Uint8Array {\n return livekitCopyBuffer(ptr, len);\n }\n\n retrievePtr(data: Uint8Array): bigint {\n return livekitRetrievePtr(data);\n }\n\n async waitFor<T>(predicate: (ev: FfiEvent) => boolean): Promise<T> {\n return new Promise<T>((resolve) => {\n const listener = (ev: FfiEvent) => {\n if (predicate(ev)) {\n this.off(FfiClientEvent.FfiEvent, listener);\n resolve(ev.message.value as T);\n }\n };\n this.on(FfiClientEvent.FfiEvent, listener);\n });\n }\n}\n"],"mappings":"AAKA,OAAO,kBAAkB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,YAAY,mBAAmB;AAClD,SAAS,mBAAmB;AAQrB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;AAIL,MAAM,kBAAmB,aAA4D;AAAA;AAAA,EAI1F,WAAW,WAAsB;AAC/B,QAAI,CAAC,UAAU,QAAS,WAAU,UAAU,IAAI,UAAU;AAE1D,WAAO,UAAU;AAAA,EACnB;AAAA,EAEA,cAAc;AACZ,UAAM;AACN,SAAK,gBAAgB,CAAC;AAEtB;AAAA,MACE,CAAC,eAA2B;AAC1B,cAAM,QAAQ,SAAS,WAAW,UAAU;AAC5C,aAAK,KAAK,4BAAyB,KAAK;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAW,KAAoC;AAC7C,UAAM,UAAU,IAAI,WAAW,GAAG;AAClC,UAAM,WAAW,QAAQ,SAAS;AAClC,UAAM,WAAW,kBAAkB,QAAQ;AAC3C,WAAO,YAAY,WAAW,QAAQ,EAAE,QAAQ;AAAA,EAClD;AAAA,EAEA,WAAW,KAAa,KAAyB;AAC/C,WAAO,kBAAkB,KAAK,GAAG;AAAA,EACnC;AAAA,EAEA,YAAY,MAA0B;AACpC,WAAO,mBAAmB,IAAI;AAAA,EAChC;AAAA,EAEA,MAAM,QAAW,WAAkD;AACjE,WAAO,IAAI,QAAW,CAAC,YAAY;AACjC,YAAM,WAAW,CAAC,OAAiB;AACjC,YAAI,UAAU,EAAE,GAAG;AACjB,eAAK,IAAI,4BAAyB,QAAQ;AAC1C,kBAAQ,GAAG,QAAQ,KAAU;AAAA,QAC/B;AAAA,MACF;AACA,WAAK,GAAG,4BAAyB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;","names":["FfiClientEvent"]}
1
+ {"version":3,"sources":["../src/ffi_client.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { PartialMessage } from '@bufbuild/protobuf';\nimport type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';\nimport EventEmitter from 'events';\nimport {\n FfiHandle,\n livekitCopyBuffer,\n livekitDispose,\n livekitFfiRequest,\n livekitInitialize,\n livekitRetrievePtr,\n} from './napi/native.js';\nimport { FfiEvent, FfiRequest, FfiResponse } from './proto/ffi_pb.js';\nimport { SDK_VERSION } from './version.js';\n\nexport { FfiHandle, type FfiEvent, type FfiResponse, FfiRequest, livekitDispose as dispose };\n\nexport type FfiClientCallbacks = {\n ffi_event: (event: FfiEvent) => void;\n};\n\nexport enum FfiClientEvent {\n FfiEvent = 'ffi_event',\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var _ffiClientInstance: FfiClient | undefined;\n}\n\nexport class FfiClient extends (EventEmitter as new () => TypedEmitter<FfiClientCallbacks>) {\n /** @internal */\n static get instance(): FfiClient {\n if (!globalThis._ffiClientInstance) {\n globalThis._ffiClientInstance = new FfiClient();\n }\n return globalThis._ffiClientInstance;\n }\n\n constructor() {\n super();\n this.setMaxListeners(0);\n\n livekitInitialize(\n (event_data: Uint8Array) => {\n const event = FfiEvent.fromBinary(event_data);\n this.emit(FfiClientEvent.FfiEvent, event);\n },\n true,\n SDK_VERSION,\n );\n }\n\n request<T>(req: PartialMessage<FfiRequest>): T {\n const request = new FfiRequest(req);\n const req_data = request.toBinary();\n const res_data = livekitFfiRequest(req_data);\n return FfiResponse.fromBinary(res_data).message.value as T;\n }\n\n copyBuffer(ptr: bigint, len: number): Uint8Array {\n return livekitCopyBuffer(ptr, len);\n }\n\n retrievePtr(data: Uint8Array): bigint {\n return livekitRetrievePtr(data);\n }\n\n async waitFor<T>(predicate: (ev: FfiEvent) => boolean): Promise<T> {\n return new Promise<T>((resolve) => {\n const listener = (ev: FfiEvent) => {\n if (predicate(ev)) {\n this.off(FfiClientEvent.FfiEvent, listener);\n resolve(ev.message.value as T);\n }\n };\n this.on(FfiClientEvent.FfiEvent, listener);\n });\n }\n}\n"],"mappings":"AAKA,OAAO,kBAAkB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,YAAY,mBAAmB;AAClD,SAAS,mBAAmB;AAQrB,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;AASL,MAAM,kBAAmB,aAA4D;AAAA;AAAA,EAE1F,WAAW,WAAsB;AAC/B,QAAI,CAAC,WAAW,oBAAoB;AAClC,iBAAW,qBAAqB,IAAI,UAAU;AAAA,IAChD;AACA,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,cAAc;AACZ,UAAM;AACN,SAAK,gBAAgB,CAAC;AAEtB;AAAA,MACE,CAAC,eAA2B;AAC1B,cAAM,QAAQ,SAAS,WAAW,UAAU;AAC5C,aAAK,KAAK,4BAAyB,KAAK;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAW,KAAoC;AAC7C,UAAM,UAAU,IAAI,WAAW,GAAG;AAClC,UAAM,WAAW,QAAQ,SAAS;AAClC,UAAM,WAAW,kBAAkB,QAAQ;AAC3C,WAAO,YAAY,WAAW,QAAQ,EAAE,QAAQ;AAAA,EAClD;AAAA,EAEA,WAAW,KAAa,KAAyB;AAC/C,WAAO,kBAAkB,KAAK,GAAG;AAAA,EACnC;AAAA,EAEA,YAAY,MAA0B;AACpC,WAAO,mBAAmB,IAAI;AAAA,EAChC;AAAA,EAEA,MAAM,QAAW,WAAkD;AACjE,WAAO,IAAI,QAAW,CAAC,YAAY;AACjC,YAAM,WAAW,CAAC,OAAiB;AACjC,YAAI,UAAU,EAAE,GAAG;AACjB,eAAK,IAAI,4BAAyB,QAAQ;AAC1C,kBAAQ,GAAG,QAAQ,KAAU;AAAA,QAC/B;AAAA,MACF;AACA,WAAK,GAAG,4BAAyB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;","names":["FfiClientEvent"]}
package/dist/index.d.cts CHANGED
@@ -3,16 +3,16 @@ export { AudioResampler, AudioResamplerQuality } from './audio_resampler.cjs';
3
3
  export { AudioSource } from './audio_source.cjs';
4
4
  export { AudioStream, NoiseCancellationOptions } from './audio_stream.cjs';
5
5
  export { AudioFilter } from './audio_filter.cjs';
6
- export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, B as ByteStreamReader, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions, T as TextStreamReader } from './stream_reader-a8_oiaOi.cjs';
6
+ export { a as BaseStreamInfo, f as ByteStreamHandler, b as ByteStreamInfo, e as ByteStreamOptions, B as ByteStreamReader, D as DataStreamOptions, S as StreamController, g as TextStreamHandler, c as TextStreamInfo, d as TextStreamOptions, T as TextStreamReader } from './stream_reader-Ch2zvjU3.cjs';
7
7
  export { ByteStreamWriter, TextStreamWriter } from './data_streams/stream_writer.cjs';
8
8
  export { E2EEManager, E2EEOptions, FrameCryptor, KeyProvider, KeyProviderOptions } from './e2ee.cjs';
9
- export { livekitDispose as dispose } from './napi/native.d.cjs';
9
+ import './ffi_client.cjs';
10
+ export { LocalParticipant, Participant, RemoteParticipant } from './participant.cjs';
11
+ export { EncryptionState, EncryptionType } from './proto/e2ee_pb.cjs';
12
+ export { DisconnectReason, ParticipantKind } from './proto/participant_pb.cjs';
10
13
  export { ConnectionQuality, ConnectionState, ContinualGatheringPolicy, DataPacketKind, IceServer, IceTransportType, TrackPublishOptions } from './proto/room_pb.cjs';
11
14
  export { StreamState, TrackKind, TrackSource } from './proto/track_pb.cjs';
12
15
  export { VideoBufferType, VideoCodec, VideoRotation } from './proto/video_frame_pb.cjs';
13
- export { EncryptionState, EncryptionType } from './proto/e2ee_pb.cjs';
14
- export { LocalParticipant, Participant, RemoteParticipant } from './participant.cjs';
15
- export { DisconnectReason, ParticipantKind } from './proto/participant_pb.cjs';
16
16
  export { ConnectError, Room, RoomEvent, RoomOptions, RtcConfiguration } from './room.cjs';
17
17
  export { PerformRpcParams, RpcError, RpcInvocationData } from './rpc.cjs';
18
18
  export { AudioTrack, LocalAudioTrack, LocalTrack, LocalVideoTrack, RemoteAudioTrack, RemoteTrack, RemoteVideoTrack, Track, VideoTrack } from './track.cjs';
@@ -22,11 +22,14 @@ export { ChatMessage } from './types.cjs';
22
22
  export { VideoFrame } from './video_frame.cjs';
23
23
  export { VideoSource } from './video_source.cjs';
24
24
  export { VideoFrameEvent, VideoStream } from './video_stream.cjs';
25
+ export { livekitDispose as dispose } from './napi/native.d.cjs';
25
26
  import './proto/audio_frame_pb.cjs';
26
27
  import '@bufbuild/protobuf';
27
28
  import './proto/handle_pb.cjs';
28
- import 'node:stream/web';
29
- import './proto/stats_pb.cjs';
30
- import 'node:fs';
31
29
  import '@livekit/typed-emitter';
30
+ import './proto/ffi_pb.cjs';
32
31
  import './proto/rpc_pb.cjs';
32
+ import './proto/track_publication_pb.cjs';
33
+ import './proto/data_stream_pb.cjs';
34
+ import 'node:fs';
35
+ import './proto/stats_pb.cjs';