@livekit/rtc-node 0.13.22 → 0.13.23

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 (109) hide show
  1. package/dist/audio_frame.cjs +5 -0
  2. package/dist/audio_frame.cjs.map +1 -1
  3. package/dist/audio_frame.d.cts +3 -0
  4. package/dist/audio_frame.d.ts +3 -0
  5. package/dist/audio_frame.d.ts.map +1 -1
  6. package/dist/audio_frame.js +5 -0
  7. package/dist/audio_frame.js.map +1 -1
  8. package/dist/audio_stream.cjs +18 -5
  9. package/dist/audio_stream.cjs.map +1 -1
  10. package/dist/audio_stream.d.cts +4 -3
  11. package/dist/audio_stream.d.ts +4 -3
  12. package/dist/audio_stream.d.ts.map +1 -1
  13. package/dist/audio_stream.js +18 -5
  14. package/dist/audio_stream.js.map +1 -1
  15. package/dist/data_streams/stream_reader.cjs.map +1 -1
  16. package/dist/data_streams/stream_reader.js.map +1 -1
  17. package/dist/frame_processor.cjs +38 -0
  18. package/dist/frame_processor.cjs.map +1 -0
  19. package/dist/frame_processor.d.cts +29 -0
  20. package/dist/frame_processor.d.ts +29 -0
  21. package/dist/frame_processor.d.ts.map +1 -0
  22. package/dist/frame_processor.js +14 -0
  23. package/dist/frame_processor.js.map +1 -0
  24. package/dist/index.cjs +3 -0
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +1 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/proto/audio_frame_pb.cjs.map +1 -1
  32. package/dist/proto/audio_frame_pb.js.map +1 -1
  33. package/dist/proto/e2ee_pb.cjs.map +1 -1
  34. package/dist/proto/e2ee_pb.js.map +1 -1
  35. package/dist/proto/ffi_pb.cjs +4 -2
  36. package/dist/proto/ffi_pb.cjs.map +1 -1
  37. package/dist/proto/ffi_pb.d.cts +13 -1
  38. package/dist/proto/ffi_pb.d.ts +13 -1
  39. package/dist/proto/ffi_pb.d.ts.map +1 -1
  40. package/dist/proto/ffi_pb.js +5 -3
  41. package/dist/proto/ffi_pb.js.map +1 -1
  42. package/dist/proto/handle_pb.cjs.map +1 -1
  43. package/dist/proto/handle_pb.js.map +1 -1
  44. package/dist/proto/participant_pb.cjs +26 -4
  45. package/dist/proto/participant_pb.cjs.map +1 -1
  46. package/dist/proto/participant_pb.d.cts +31 -2
  47. package/dist/proto/participant_pb.d.ts +31 -2
  48. package/dist/proto/participant_pb.d.ts.map +1 -1
  49. package/dist/proto/participant_pb.js +24 -3
  50. package/dist/proto/participant_pb.js.map +1 -1
  51. package/dist/proto/room_pb.cjs +29 -2
  52. package/dist/proto/room_pb.cjs.map +1 -1
  53. package/dist/proto/room_pb.d.cts +30 -7
  54. package/dist/proto/room_pb.d.ts +30 -7
  55. package/dist/proto/room_pb.d.ts.map +1 -1
  56. package/dist/proto/room_pb.js +28 -2
  57. package/dist/proto/room_pb.js.map +1 -1
  58. package/dist/proto/rpc_pb.cjs.map +1 -1
  59. package/dist/proto/rpc_pb.js.map +1 -1
  60. package/dist/proto/stats_pb.cjs.map +1 -1
  61. package/dist/proto/stats_pb.js.map +1 -1
  62. package/dist/proto/track_pb.cjs.map +1 -1
  63. package/dist/proto/track_pb.js.map +1 -1
  64. package/dist/proto/track_publication_pb.cjs +66 -2
  65. package/dist/proto/track_publication_pb.cjs.map +1 -1
  66. package/dist/proto/track_publication_pb.d.cts +56 -1
  67. package/dist/proto/track_publication_pb.d.ts +56 -1
  68. package/dist/proto/track_publication_pb.d.ts.map +1 -1
  69. package/dist/proto/track_publication_pb.js +62 -1
  70. package/dist/proto/track_publication_pb.js.map +1 -1
  71. package/dist/proto/video_frame_pb.cjs +3 -1
  72. package/dist/proto/video_frame_pb.cjs.map +1 -1
  73. package/dist/proto/video_frame_pb.d.cts +5 -1
  74. package/dist/proto/video_frame_pb.d.ts +5 -1
  75. package/dist/proto/video_frame_pb.d.ts.map +1 -1
  76. package/dist/proto/video_frame_pb.js +3 -1
  77. package/dist/proto/video_frame_pb.js.map +1 -1
  78. package/dist/room.cjs +10 -10
  79. package/dist/room.cjs.map +1 -1
  80. package/dist/room.d.cts +10 -10
  81. package/dist/room.d.ts +10 -10
  82. package/dist/room.d.ts.map +1 -1
  83. package/dist/room.js +11 -11
  84. package/dist/room.js.map +1 -1
  85. package/dist/version.cjs +1 -1
  86. package/dist/version.cjs.map +1 -1
  87. package/dist/version.d.cts +1 -1
  88. package/dist/version.d.ts +1 -1
  89. package/dist/version.js +1 -1
  90. package/dist/version.js.map +1 -1
  91. package/package.json +6 -6
  92. package/src/audio_frame.ts +7 -0
  93. package/src/audio_stream.ts +22 -7
  94. package/src/data_streams/stream_reader.ts +4 -4
  95. package/src/frame_processor.ts +29 -0
  96. package/src/index.ts +5 -0
  97. package/src/proto/audio_frame_pb.ts +1 -1
  98. package/src/proto/e2ee_pb.ts +1 -1
  99. package/src/proto/ffi_pb.ts +16 -2
  100. package/src/proto/handle_pb.ts +1 -1
  101. package/src/proto/participant_pb.ts +45 -1
  102. package/src/proto/room_pb.ts +52 -8
  103. package/src/proto/rpc_pb.ts +1 -1
  104. package/src/proto/stats_pb.ts +1 -1
  105. package/src/proto/track_pb.ts +1 -1
  106. package/src/proto/track_publication_pb.ts +105 -1
  107. package/src/proto/video_frame_pb.ts +7 -1
  108. package/src/room.ts +33 -33
  109. package/src/version.ts +1 -1
@@ -31,6 +31,7 @@ class AudioFrame {
31
31
  // it is recommended to use buffer.subarray instead.
32
32
  // XXX(nbsp): add this when writing proper docs
33
33
  constructor(data, sampleRate, channels, samplesPerChannel) {
34
+ this._userdata = {};
34
35
  this.data = data;
35
36
  this.sampleRate = sampleRate;
36
37
  this.channels = channels;
@@ -62,6 +63,10 @@ class AudioFrame {
62
63
  samplesPerChannel: this.samplesPerChannel
63
64
  });
64
65
  }
66
+ /** Returns the user data associated with the audio frame. */
67
+ get userdata() {
68
+ return this._userdata;
69
+ }
65
70
  }
66
71
  const combineAudioFrames = (buffer) => {
67
72
  if (!Array.isArray(buffer)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/audio_frame.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { FfiClient, FfiHandle } from './ffi_client.js';\nimport type { OwnedAudioFrameBuffer } from './proto/audio_frame_pb.js';\nimport { AudioFrameBufferInfo } from './proto/audio_frame_pb.js';\n\nexport class AudioFrame {\n data: Int16Array;\n sampleRate: number;\n channels: number;\n samplesPerChannel: number;\n\n // note: if converting from Uint8Array to Int16Array, *do not* use buffer.slice!\n // it is marked unstable by Node and can cause undefined behaviour, such as massive chunks of\n // noise being added to the end.\n // it is recommended to use buffer.subarray instead.\n // XXX(nbsp): add this when writing proper docs\n constructor(data: Int16Array, sampleRate: number, channels: number, samplesPerChannel: number) {\n this.data = data;\n this.sampleRate = sampleRate;\n this.channels = channels;\n this.samplesPerChannel = samplesPerChannel;\n }\n\n static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame {\n const data = new Int16Array(channels * samplesPerChannel);\n return new AudioFrame(data, sampleRate, channels, samplesPerChannel);\n }\n\n /** @internal */\n static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame {\n const info = owned.info!;\n const len = info.numChannels! * info.samplesPerChannel! * 2; // c_int16\n const data = FfiClient.instance.copyBuffer(info.dataPtr!, len);\n new FfiHandle(owned.handle!.id!).dispose();\n return new AudioFrame(\n new Int16Array(data.buffer),\n info.sampleRate!,\n info.numChannels!,\n info.samplesPerChannel!,\n );\n }\n\n /** @internal */\n protoInfo(): AudioFrameBufferInfo {\n return new AudioFrameBufferInfo({\n dataPtr: FfiClient.instance.retrievePtr(new Uint8Array(this.data.buffer)),\n sampleRate: this.sampleRate,\n numChannels: this.channels,\n samplesPerChannel: this.samplesPerChannel,\n });\n }\n}\n\n/**\n * Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.\n *\n * This function concatenates the audio data from multiple frames, ensuring that all frames have\n * the same sample rate and number of channels. It efficiently merges the data by preallocating the\n * necessary memory and copying the frame data without unnecessary reallocations.\n *\n * @param buffer - a single AudioFrame or list thereof\n */\nexport const combineAudioFrames = (buffer: AudioFrame | AudioFrame[]): AudioFrame => {\n if (!Array.isArray(buffer)) {\n return buffer;\n }\n buffer = buffer as AudioFrame[];\n\n if (buffer.length === 0) {\n throw new Error('buffer is empty');\n }\n\n const sampleRate = buffer[0]!.sampleRate;\n const channels = buffer[0]!.channels;\n\n let totalSamplesPerChannel = 0;\n for (const frame of buffer) {\n if (frame.sampleRate != sampleRate) {\n throw new Error(`sample rate mismatch: expected ${sampleRate}, got ${frame.sampleRate}`);\n }\n\n if (frame.channels != channels) {\n throw new Error(`channel mismatch: expected ${channels}, got ${frame.channels}`);\n }\n\n totalSamplesPerChannel += frame.samplesPerChannel;\n }\n\n const data = new Int16Array(buffer.map((x) => [...x.data]).flat());\n return new AudioFrame(data, sampleRate, channels, totalSamplesPerChannel);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAqC;AAErC,4BAAqC;AAE9B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWtB,YAAY,MAAkB,YAAoB,UAAkB,mBAA2B;AAC7F,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,oBAAoB;AAAA,EAC3B;AAAA,EAEA,OAAO,OAAO,YAAoB,UAAkB,mBAAuC;AACzF,UAAM,OAAO,IAAI,WAAW,WAAW,iBAAiB;AACxD,WAAO,IAAI,WAAW,MAAM,YAAY,UAAU,iBAAiB;AAAA,EACrE;AAAA;AAAA,EAGA,OAAO,cAAc,OAA0C;AAC7D,UAAM,OAAO,MAAM;AACnB,UAAM,MAAM,KAAK,cAAe,KAAK,oBAAqB;AAC1D,UAAM,OAAO,4BAAU,SAAS,WAAW,KAAK,SAAU,G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DX-License-Identifier: Apache-2.0\nimport { FfiClient, FfiHandle } from './ffi_client.js';\nimport type { OwnedAudioFrameBuffer } from './proto/audio_frame_pb.js';\nimport { AudioFrameBufferInfo } from './proto/audio_frame_pb.js';\n\nexport class AudioFrame {\n data: Int16Array;\n sampleRate: number;\n channels: number;\n samplesPerChannel: number;\n\n private _userdata: Record<string, unknown> = {};\n\n // note: if converting from Uint8Array to Int16Array, *do not* use buffer.slice!\n // it is marked unstable by Node and can cause undefined behaviour, such as massive chunks of\n // noise being added to the end.\n // it is recommended to use buffer.subarray instead.\n // XXX(nbsp): add this when writing proper docs\n constructor(data: Int16Array, sampleRate: number, channels: number, samplesPerChannel: number) {\n this.data = data;\n this.sampleRate = sampleRate;\n this.channels = channels;\n this.samplesPerChannel = samplesPerChannel;\n }\n\n static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame {\n const data = new Int16Array(channels * samplesPerChannel);\n return new AudioFrame(data, sampleRate, channels, samplesPerChannel);\n }\n\n /** @internal */\n static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame {\n const info = owned.info!;\n const len = info.numChannels! * info.samplesPerChannel! * 2; // c_int16\n const data = FfiClient.instance.copyBuffer(info.dataPtr!, len);\n new FfiHandle(owned.handle!.id!).dispose();\n return new AudioFrame(\n new Int16Array(data.buffer),\n info.sampleRate!,\n info.numChannels!,\n info.samplesPerChannel!,\n );\n }\n\n /** @internal */\n protoInfo(): AudioFrameBufferInfo {\n return new AudioFrameBufferInfo({\n dataPtr: FfiClient.instance.retrievePtr(new Uint8Array(this.data.buffer)),\n sampleRate: this.sampleRate,\n numChannels: this.channels,\n samplesPerChannel: this.samplesPerChannel,\n });\n }\n\n /** Returns the user data associated with the audio frame. */\n get userdata() {\n return this._userdata;\n }\n}\n\n/**\n * Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.\n *\n * This function concatenates the audio data from multiple frames, ensuring that all frames have\n * the same sample rate and number of channels. It efficiently merges the data by preallocating the\n * necessary memory and copying the frame data without unnecessary reallocations.\n *\n * @param buffer - a single AudioFrame or list thereof\n */\nexport const combineAudioFrames = (buffer: AudioFrame | AudioFrame[]): AudioFrame => {\n if (!Array.isArray(buffer)) {\n return buffer;\n }\n buffer = buffer as AudioFrame[];\n\n if (buffer.length === 0) {\n throw new Error('buffer is empty');\n }\n\n const sampleRate = buffer[0]!.sampleRate;\n const channels = buffer[0]!.channels;\n\n let totalSamplesPerChannel = 0;\n for (const frame of buffer) {\n if (frame.sampleRate != sampleRate) {\n throw new Error(`sample rate mismatch: expected ${sampleRate}, got ${frame.sampleRate}`);\n }\n\n if (frame.channels != channels) {\n throw new Error(`channel mismatch: expected ${channels}, got ${frame.channels}`);\n }\n\n totalSamplesPerChannel += frame.samplesPerChannel;\n }\n\n const data = new Int16Array(buffer.map((x) => [...x.data]).flat());\n return new AudioFrame(data, sampleRate, channels, totalSamplesPerChannel);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAqC;AAErC,4BAAqC;AAE9B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatB,YAAY,MAAkB,YAAoB,UAAkB,mBAA2B;AAP/F,SAAQ,YAAqC,CAAC;AAQ5C,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,oBAAoB;AAAA,EAC3B;AAAA,EAEA,OAAO,OAAO,YAAoB,UAAkB,mBAAuC;AACzF,UAAM,OAAO,IAAI,WAAW,WAAW,iBAAiB;AACxD,WAAO,IAAI,WAAW,MAAM,YAAY,UAAU,iBAAiB;AAAA,EACrE;AAAA;AAAA,EAGA,OAAO,cAAc,OAA0C;AAC7D,UAAM,OAAO,MAAM;AACnB,UAAM,MAAM,KAAK,cAAe,KAAK,oBAAqB;AAC1D,UAAM,OAAO,4BAAU,SAAS,WAAW,KAAK,SAAU,GAAG;AAC7D,QAAI,4BAAU,MAAM,OAAQ,EAA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erChannel: number;
13
+ private _userdata;
13
14
  constructor(data: Int16Array, sampleRate: number, channels: number, samplesPerChannel: number);
14
15
  static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame;
15
16
  /** @internal */
16
17
  static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame;
17
18
  /** @internal */
18
19
  protoInfo(): AudioFrameBufferInfo;
20
+ /** Returns the user data associated with the audio frame. */
21
+ get userdata(): Record<string, unknown>;
19
22
  }
20
23
  /**
21
24
  * Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.
@@ -10,12 +10,15 @@ declare class AudioFrame {
10
10
  sampleRate: number;
11
11
  channels: number;
12
12
  samplesPerChannel: number;
13
+ private _userdata;
13
14
  constructor(data: Int16Array, sampleRate: number, channels: number, samplesPerChannel: number);
14
15
  static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame;
15
16
  /** @internal */
16
17
  static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame;
17
18
  /** @internal */
18
19
  protoInfo(): AudioFrameBufferInfo;
20
+ /** Returns the user data associated with the audio frame. */
21
+ get userdata(): Record<string, unknown>;
19
22
  }
20
23
  /**
21
24
  * Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.
@@ -1 +1 @@
1
- {"version":3,"file":"audio_frame.d.ts","sourceRoot":"","sources":["../src/audio_frame.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,qBAAa,UAAU;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;gBAOd,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;IAO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recommended to use buffer.subarray instead.
8
8
  // XXX(nbsp): add this when writing proper docs
9
9
  constructor(data, sampleRate, channels, samplesPerChannel) {
10
+ this._userdata = {};
10
11
  this.data = data;
11
12
  this.sampleRate = sampleRate;
12
13
  this.channels = channels;
@@ -38,6 +39,10 @@ class AudioFrame {
38
39
  samplesPerChannel: this.samplesPerChannel
39
40
  });
40
41
  }
42
+ /** Returns the user data associated with the audio frame. */
43
+ get userdata() {
44
+ return this._userdata;
45
+ }
41
46
  }
42
47
  const combineAudioFrames = (buffer) => {
43
48
  if (!Array.isArray(buffer)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/audio_frame.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { FfiClient, FfiHandle } from './ffi_client.js';\nimport type { OwnedAudioFrameBuffer } from './proto/audio_frame_pb.js';\nimport { AudioFrameBufferInfo } from './proto/audio_frame_pb.js';\n\nexport class AudioFrame {\n data: Int16Array;\n sampleRate: number;\n channels: number;\n samplesPerChannel: number;\n\n // note: if converting from Uint8Array to Int16Array, *do not* use buffer.slice!\n // it is marked unstable by Node and can cause undefined behaviour, such as massive chunks of\n // noise being added to the end.\n // it is recommended to use buffer.subarray instead.\n // XXX(nbsp): add this when writing proper docs\n constructor(data: Int16Array, sampleRate: number, channels: number, samplesPerChannel: number) {\n this.data = data;\n this.sampleRate = sampleRate;\n this.channels = channels;\n this.samplesPerChannel = samplesPerChannel;\n }\n\n static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame {\n const data = new Int16Array(channels * samplesPerChannel);\n return new AudioFrame(data, sampleRate, channels, samplesPerChannel);\n }\n\n /** @internal */\n static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame {\n const info = owned.info!;\n const len = info.numChannels! * info.samplesPerChannel! * 2; // c_int16\n const data = FfiClient.instance.copyBuffer(info.dataPtr!, len);\n new FfiHandle(owned.handle!.id!).dispose();\n return new AudioFrame(\n new Int16Array(data.buffer),\n info.sampleRate!,\n info.numChannels!,\n info.samplesPerChannel!,\n );\n }\n\n /** @internal */\n protoInfo(): AudioFrameBufferInfo {\n return new AudioFrameBufferInfo({\n dataPtr: FfiClient.instance.retrievePtr(new Uint8Array(this.data.buffer)),\n sampleRate: this.sampleRate,\n numChannels: this.channels,\n samplesPerChannel: this.samplesPerChannel,\n });\n }\n}\n\n/**\n * Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.\n *\n * This function concatenates the audio data from multiple frames, ensuring that all frames have\n * the same sample rate and number of channels. It efficiently merges the data by preallocating the\n * necessary memory and copying the frame data without unnecessary reallocations.\n *\n * @param buffer - a single AudioFrame or list thereof\n */\nexport const combineAudioFrames = (buffer: AudioFrame | AudioFrame[]): AudioFrame => {\n if (!Array.isArray(buffer)) {\n return buffer;\n }\n buffer = buffer as AudioFrame[];\n\n if (buffer.length === 0) {\n throw new Error('buffer is empty');\n }\n\n const sampleRate = buffer[0]!.sampleRate;\n const channels = buffer[0]!.channels;\n\n let totalSamplesPerChannel = 0;\n for (const frame of buffer) {\n if (frame.sampleRate != sampleRate) {\n throw new Error(`sample rate mismatch: expected ${sampleRate}, got ${frame.sampleRate}`);\n }\n\n if (frame.channels != channels) {\n throw new Error(`channel mismatch: expected ${channels}, got ${frame.channels}`);\n }\n\n totalSamplesPerChannel += frame.samplesPerChannel;\n }\n\n const data = new Int16Array(buffer.map((x) => [...x.data]).flat());\n return new AudioFrame(data, sampleRate, channels, totalSamplesPerChannel);\n};\n"],"mappings":"AAGA,SAAS,WAAW,iBAAiB;AAErC,SAAS,4BAA4B;AAE9B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWtB,YAAY,MAAkB,YAAoB,UAAkB,mBAA2B;AAC7F,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,oBAAoB;AAAA,EAC3B;AAAA,EAEA,OAAO,OAAO,YAAoB,UAAk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AM;AAAA,EAClC;AAEA,QAAM,OAAO,IAAI,WAAW,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC;AACjE,SAAO,IAAI,WAAW,MAAM,YAAY,UAAU,sBAAsB;AAC1E;","names":[]}
1
+ {"version":3,"sources":["../src/audio_frame.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { FfiClient, FfiHandle } from './ffi_client.js';\nimport type { OwnedAudioFrameBuffer } from './proto/audio_frame_pb.js';\nimport { AudioFrameBufferInfo } from './proto/audio_frame_pb.js';\n\nexport class AudioFrame {\n data: Int16Array;\n sampleRate: number;\n channels: number;\n samplesPerChannel: number;\n\n private _userdata: Record<string, unknown> = {};\n\n // note: if converting from Uint8Array to Int16Array, *do not* use buffer.slice!\n // it is marked unstable by Node and can cause undefined behaviour, such as massive chunks of\n // noise being added to the end.\n // it is recommended to use buffer.subarray instead.\n // XXX(nbsp): add this when writing proper docs\n constructor(data: Int16Array, sampleRate: number, channels: number, samplesPerChannel: number) {\n this.data = data;\n this.sampleRate = sampleRate;\n this.channels = channels;\n this.samplesPerChannel = samplesPerChannel;\n }\n\n static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame {\n const data = new Int16Array(channels * samplesPerChannel);\n return new AudioFrame(data, sampleRate, channels, samplesPerChannel);\n }\n\n /** @internal */\n static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame {\n const info = owned.info!;\n const len = info.numChannels! * info.samplesPerChannel! * 2; // c_int16\n const data = FfiClient.instance.copyBuffer(info.dataPtr!, len);\n new FfiHandle(owned.handle!.id!).dispose();\n return new AudioFrame(\n new Int16Array(data.buffer),\n info.sampleRate!,\n info.numChannels!,\n info.samplesPerChannel!,\n );\n }\n\n /** @internal */\n protoInfo(): AudioFrameBufferInfo {\n return new AudioFrameBufferInfo({\n dataPtr: FfiClient.instance.retrievePtr(new Uint8Array(this.data.buffer)),\n sampleRate: this.sampleRate,\n numChannels: this.channels,\n samplesPerChannel: this.samplesPerChannel,\n });\n }\n\n /** Returns the user data associated with the audio frame. */\n get userdata() {\n return this._userdata;\n }\n}\n\n/**\n * Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.\n *\n * This function concatenates the audio data from multiple frames, ensuring that all frames have\n * the same sample rate and number of channels. It efficiently merges the data by preallocating the\n * necessary memory and copying the frame data without unnecessary reallocations.\n *\n * @param buffer - a single AudioFrame or list thereof\n */\nexport const combineAudioFrames = (buffer: AudioFrame | AudioFrame[]): AudioFrame => {\n if (!Array.isArray(buffer)) {\n return buffer;\n }\n buffer = buffer as AudioFrame[];\n\n if (buffer.length === 0) {\n throw new Error('buffer is empty');\n }\n\n const sampleRate = buffer[0]!.sampleRate;\n const channels = buffer[0]!.channels;\n\n let totalSamplesPerChannel = 0;\n for (const frame of buffer) {\n if (frame.sampleRate != sampleRate) {\n throw new Error(`sample rate mismatch: expected ${sampleRate}, got ${frame.sampleRate}`);\n }\n\n if (frame.channels != channels) {\n throw new Error(`channel mismatch: expected ${channels}, got ${frame.channels}`);\n }\n\n totalSamplesPerChannel += frame.samplesPerChannel;\n }\n\n const data = new Int16Array(buffer.map((x) => [...x.data]).flat());\n return new AudioFrame(data, sampleRate, channels, totalSamplesPerChannel);\n};\n"],"mappings":"AAGA,SAAS,WAAW,iBAAiB;AAErC,SAAS,4BAA4B;AAE9B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatB,YAAY,MAAkB,YAAoB,UAAkB,mBAA2B;AAP/F,SAAQ,YAAqC,CAAC;AAQ5C,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,oBAAoB;AAAA,EAC3B;AAAA,EAEA,OAAO,OAAO,YAAoB,UAAkB,mBAAuC;AACzF,UAAM,OAAO,IAAI,WAAW,WAAW,iBAAiB;AACxD,WAAO,IAAI,WAAW,MAAM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,OAAO,IAAI,WAAW,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC;AACjE,SAAO,IAAI,WAAW,MAAM,YAAY,UAAU,sBAAsB;AAC1E;","names":[]}
@@ -23,6 +23,8 @@ __export(audio_stream_exports, {
23
23
  module.exports = __toCommonJS(audio_stream_exports);
24
24
  var import_audio_frame = require("./audio_frame.cjs");
25
25
  var import_ffi_client = require("./ffi_client.cjs");
26
+ var import_frame_processor = require("./frame_processor.cjs");
27
+ var import_log = require("./log.cjs");
26
28
  var import_audio_frame_pb = require("./proto/audio_frame_pb.cjs");
27
29
  class AudioStreamSource {
28
30
  constructor(track, sampleRateOrOptions, numChannels) {
@@ -36,7 +38,14 @@ class AudioStreamSource {
36
38
  const streamEvent = ev.message.value.message;
37
39
  switch (streamEvent.case) {
38
40
  case "frameReceived":
39
- const frame = import_audio_frame.AudioFrame.fromOwnedInfo(streamEvent.value.frame);
41
+ let frame = import_audio_frame.AudioFrame.fromOwnedInfo(streamEvent.value.frame);
42
+ if (this.frameProcessor && this.frameProcessor.isEnabled()) {
43
+ try {
44
+ frame = this.frameProcessor.process(frame);
45
+ } catch (err) {
46
+ import_log.log.warn(`Frame processing failed, passing through original frame: ${err}`);
47
+ }
48
+ }
40
49
  this.controller.enqueue(frame);
41
50
  break;
42
51
  case "eos":
@@ -48,7 +57,11 @@ class AudioStreamSource {
48
57
  if (sampleRateOrOptions !== void 0 && typeof sampleRateOrOptions !== "number") {
49
58
  this.sampleRate = sampleRateOrOptions.sampleRate ?? 48e3;
50
59
  this.numChannels = sampleRateOrOptions.numChannels ?? 1;
51
- this.ncOptions = sampleRateOrOptions.noiseCancellation;
60
+ if (sampleRateOrOptions.noiseCancellation instanceof import_frame_processor.FrameProcessor) {
61
+ this.frameProcessor = sampleRateOrOptions.noiseCancellation;
62
+ } else {
63
+ this.legacyNcOptions = sampleRateOrOptions.noiseCancellation;
64
+ }
52
65
  this.frameSizeMs = sampleRateOrOptions.frameSizeMs;
53
66
  } else {
54
67
  this.sampleRate = sampleRateOrOptions ?? 48e3;
@@ -60,9 +73,9 @@ class AudioStreamSource {
60
73
  sampleRate: this.sampleRate,
61
74
  numChannels: this.numChannels,
62
75
  frameSizeMs: this.frameSizeMs,
63
- ...this.ncOptions ? {
64
- audioFilterModuleId: this.ncOptions.moduleId,
65
- audioFilterOptions: JSON.stringify(this.ncOptions.options)
76
+ ...this.legacyNcOptions ? {
77
+ audioFilterModuleId: this.legacyNcOptions.moduleId,
78
+ audioFilterOptions: JSON.stringify(this.legacyNcOptions.options)
66
79
  } : {}
67
80
  });
68
81
  const res = import_ffi_client.FfiClient.instance.request({
@@ -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 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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAA2B;AAE3B,wBAAqD;AAErD,4BAAuD;AAevD,MAAM,kBAA0D;AAAA,EAQ9D,YACE,OACA,qBACA,aACA;AAqCF,SAAQ,UAAU,CAAC,OAAiB;AAClC,UAAI,CAAC,KAAK,YAAY;AACpB,cAAM,IAAI,MAAM,mCAAmC;AAAA,MACrD;AAEA,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,QAAQ,8BAAW,cAAc,YAAY,MAAM,KAAM;AAC/D,eAAK,WAAW,QAAQ,KAAK;AAC7B;AAAA,QACF,KAAK;AACH,sCAAU,SAAS,IAAI,iCAAe,UAAU,KAAK,OAAO;AAC5D,eAAK,WAAW,MAAM;AACtB;AAAA,MACJ;AAAA,IACF;AA3DE,QAAI,wBAAwB,UAAa,OAAO,wBAAwB,UAAU;AAChF,WAAK,aAAa,oBAAoB,cAAc;AACpD,WAAK,cAAc,oBAAoB,eAAe;AACtD,WAAK,YAAY,oBAAoB;AACrC,WAAK,cAAc,oBAAoB;AAAA,IACzC,OAAO;AACL,WAAK,aAAc,uBAAkC;AACrD,WAAK,cAAc,eAAe;AAAA,IACpC;AAEA,UAAM,MAAM,IAAI,4CAAsB;AAAA,MACpC,MAAM,sCAAgB;AAAA,MACtB,aAAa,MAAM,WAAW;AAAA,MAC9B,YAAY,KAAK;AAAA,MACjB,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,GAAI,KAAK,YACL;AAAA,QACE,qBAAqB,KAAK,UAAU;AAAA,QACpC,oBAAoB,KAAK,UAAU,KAAK,UAAU,OAAO;AAAA,MAC3D,IACA,CAAC;AAAA,IACP,CAAC;AAED,UAAM,MAAM,4BAAU,SAAS,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
+ {"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 { FrameProcessor } from './frame_processor.js';\nimport { log } from './log.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 | FrameProcessor<AudioFrame>;\n sampleRate?: number;\n numChannels?: number;\n frameSizeMs?: number;\n}\n\nexport interface NoiseCancellationOptions {\n moduleId: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 legacyNcOptions?: NoiseCancellationOptions;\n private frameProcessor?: FrameProcessor<AudioFrame>;\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 if (sampleRateOrOptions.noiseCancellation instanceof FrameProcessor) {\n this.frameProcessor = sampleRateOrOptions.noiseCancellation;\n } else {\n this.legacyNcOptions = sampleRateOrOptions.noiseCancellation;\n }\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.legacyNcOptions\n ? {\n audioFilterModuleId: this.legacyNcOptions.moduleId,\n audioFilterOptions: JSON.stringify(this.legacyNcOptions.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 let frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame!);\n if (this.frameProcessor && this.frameProcessor.isEnabled()) {\n try {\n frame = this.frameProcessor.process(frame);\n } catch (err: unknown) {\n log.warn(`Frame processing failed, passing through original frame: ${err}`);\n }\n }\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;AAIA,yBAA2B;AAE3B,wBAAqD;AACrD,6BAA+B;AAC/B,iBAAoB;AAEpB,4BAAuD;AAgBvD,MAAM,kBAA0D;AAAA,EAS9D,YACE,OACA,qBACA,aACA;AAyCF,SAAQ,UAAU,CAAC,OAAiB;AAClC,UAAI,CAAC,KAAK,YAAY;AACpB,cAAM,IAAI,MAAM,mCAAmC;AAAA,MACrD;AAEA,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,cAAI,QAAQ,8BAAW,cAAc,YAAY,MAAM,KAAM;AAC7D,cAAI,KAAK,kBAAkB,KAAK,eAAe,UAAU,GAAG;AAC1D,gBAAI;AACF,sBAAQ,K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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,5 @@
1
1
  import { AudioFrame } from './audio_frame.cjs';
2
+ import { FrameProcessor } from './frame_processor.cjs';
2
3
  import { Track } from './track.cjs';
3
4
  import './proto/audio_frame_pb.cjs';
4
5
  import '@bufbuild/protobuf';
@@ -6,6 +7,8 @@ import './proto/track_pb.cjs';
6
7
  import './proto/stats_pb.cjs';
7
8
  import './proto/e2ee_pb.cjs';
8
9
  import './proto/handle_pb.cjs';
10
+ import './video_frame.cjs';
11
+ import './proto/video_frame_pb.cjs';
9
12
  import './audio_source.cjs';
10
13
  import './napi/native.d.cjs';
11
14
  import './ffi_client.cjs';
@@ -13,15 +16,13 @@ import '@livekit/typed-emitter';
13
16
  import './proto/ffi_pb.cjs';
14
17
  import './proto/room_pb.cjs';
15
18
  import './proto/participant_pb.cjs';
16
- import './proto/video_frame_pb.cjs';
17
19
  import './proto/data_stream_pb.cjs';
18
20
  import './proto/rpc_pb.cjs';
19
21
  import './proto/track_publication_pb.cjs';
20
22
  import './video_source.cjs';
21
- import './video_frame.cjs';
22
23
 
23
24
  interface AudioStreamOptions {
24
- noiseCancellation?: NoiseCancellationOptions;
25
+ noiseCancellation?: NoiseCancellationOptions | FrameProcessor<AudioFrame>;
25
26
  sampleRate?: number;
26
27
  numChannels?: number;
27
28
  frameSizeMs?: number;
@@ -1,4 +1,5 @@
1
1
  import { AudioFrame } from './audio_frame.js';
2
+ import { FrameProcessor } from './frame_processor.js';
2
3
  import { Track } from './track.js';
3
4
  import './proto/audio_frame_pb.js';
4
5
  import '@bufbuild/protobuf';
@@ -6,6 +7,8 @@ import './proto/track_pb.js';
6
7
  import './proto/stats_pb.js';
7
8
  import './proto/e2ee_pb.js';
8
9
  import './proto/handle_pb.js';
10
+ import './video_frame.js';
11
+ import './proto/video_frame_pb.js';
9
12
  import './audio_source.js';
10
13
  import './napi/native.d.js';
11
14
  import './ffi_client.js';
@@ -13,15 +16,13 @@ import '@livekit/typed-emitter';
13
16
  import './proto/ffi_pb.js';
14
17
  import './proto/room_pb.js';
15
18
  import './proto/participant_pb.js';
16
- import './proto/video_frame_pb.js';
17
19
  import './proto/data_stream_pb.js';
18
20
  import './proto/rpc_pb.js';
19
21
  import './proto/track_publication_pb.js';
20
22
  import './video_source.js';
21
- import './video_frame.js';
22
23
 
23
24
  interface AudioStreamOptions {
24
- noiseCancellation?: NoiseCancellationOptions;
25
+ noiseCancellation?: NoiseCancellationOptions | FrameProcessor<AudioFrame>;
25
26
  sampleRate?: number;
26
27
  numChannels?: number;
27
28
  frameSizeMs?: number;
@@ -1 +1 @@
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
+ {"version":3,"file":"audio_stream.d.ts","sourceRoot":"","sources":["../src/audio_stream.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,CAAC,EAAE,wBAAwB,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1E,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;IAEjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAkGD,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,5 +1,7 @@
1
1
  import { AudioFrame } from "./audio_frame.js";
2
2
  import { FfiClient, FfiClientEvent, FfiHandle } from "./ffi_client.js";
3
+ import { FrameProcessor } from "./frame_processor.js";
4
+ import { log } from "./log.js";
3
5
  import { AudioStreamType, NewAudioStreamRequest } from "./proto/audio_frame_pb.js";
4
6
  class AudioStreamSource {
5
7
  constructor(track, sampleRateOrOptions, numChannels) {
@@ -13,7 +15,14 @@ class AudioStreamSource {
13
15
  const streamEvent = ev.message.value.message;
14
16
  switch (streamEvent.case) {
15
17
  case "frameReceived":
16
- const frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame);
18
+ let frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame);
19
+ if (this.frameProcessor && this.frameProcessor.isEnabled()) {
20
+ try {
21
+ frame = this.frameProcessor.process(frame);
22
+ } catch (err) {
23
+ log.warn(`Frame processing failed, passing through original frame: ${err}`);
24
+ }
25
+ }
17
26
  this.controller.enqueue(frame);
18
27
  break;
19
28
  case "eos":
@@ -25,7 +34,11 @@ class AudioStreamSource {
25
34
  if (sampleRateOrOptions !== void 0 && typeof sampleRateOrOptions !== "number") {
26
35
  this.sampleRate = sampleRateOrOptions.sampleRate ?? 48e3;
27
36
  this.numChannels = sampleRateOrOptions.numChannels ?? 1;
28
- this.ncOptions = sampleRateOrOptions.noiseCancellation;
37
+ if (sampleRateOrOptions.noiseCancellation instanceof FrameProcessor) {
38
+ this.frameProcessor = sampleRateOrOptions.noiseCancellation;
39
+ } else {
40
+ this.legacyNcOptions = sampleRateOrOptions.noiseCancellation;
41
+ }
29
42
  this.frameSizeMs = sampleRateOrOptions.frameSizeMs;
30
43
  } else {
31
44
  this.sampleRate = sampleRateOrOptions ?? 48e3;
@@ -37,9 +50,9 @@ class AudioStreamSource {
37
50
  sampleRate: this.sampleRate,
38
51
  numChannels: this.numChannels,
39
52
  frameSizeMs: this.frameSizeMs,
40
- ...this.ncOptions ? {
41
- audioFilterModuleId: this.ncOptions.moduleId,
42
- audioFilterOptions: JSON.stringify(this.ncOptions.options)
53
+ ...this.legacyNcOptions ? {
54
+ audioFilterModuleId: this.legacyNcOptions.moduleId,
55
+ audioFilterOptions: JSON.stringify(this.legacyNcOptions.options)
43
56
  } : {}
44
57
  });
45
58
  const res = FfiClient.instance.request({
@@ -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 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":"AAIA,SAAS,kBAAkB;AAE3B,SAAS,WAAW,gBAAgB,iBAAiB;AAErD,SAAS,iBAAiB,6BAA6B;AAevD,MAAM,kBAA0D;AAAA,EAQ9D,YACE,OACA,qBACA,aACA;AAqCF,SAAQ,UAAU,CAAC,OAAiB;AAClC,UAAI,CAAC,KAAK,YAAY;AACpB,cAAM,IAAI,MAAM,mCAAmC;AAAA,MACrD;AAEA,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;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A,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 { FrameProcessor } from './frame_processor.js';\nimport { log } from './log.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 | FrameProcessor<AudioFrame>;\n sampleRate?: number;\n numChannels?: number;\n frameSizeMs?: number;\n}\n\nexport interface NoiseCancellationOptions {\n moduleId: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 legacyNcOptions?: NoiseCancellationOptions;\n private frameProcessor?: FrameProcessor<AudioFrame>;\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 if (sampleRateOrOptions.noiseCancellation instanceof FrameProcessor) {\n this.frameProcessor = sampleRateOrOptions.noiseCancellation;\n } else {\n this.legacyNcOptions = sampleRateOrOptions.noiseCancellation;\n }\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.legacyNcOptions\n ? {\n audioFilterModuleId: this.legacyNcOptions.moduleId,\n audioFilterOptions: JSON.stringify(this.legacyNcOptions.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 let frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame!);\n if (this.frameProcessor && this.frameProcessor.isEnabled()) {\n try {\n frame = this.frameProcessor.process(frame);\n } catch (err: unknown) {\n log.warn(`Frame processing failed, passing through original frame: ${err}`);\n }\n }\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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zC,OAAO;AACL,WAAK,aAAc,uBAAkC;AACrD,WAAK,cAAc,eAAe;AAAA,IACpC;AAEA,UAAM,MAAM,IAAI,sBAAsB;AAAA,MACpC,MAAM,gBAAgB;AAAA,MACtB,aAAa,MAAM,WAAW;AAAA,MAC9B,YAAY,KAAK;AAAA,MACjB,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,GAAI,KAAK,kBACL;AAAA,QACE,qBAAqB,KAAK,gBAAgB;AAAA,QAC1C,oBAAoB,KAAK,UAAU,KAAK,gBAAgB,OAAO;AAAA,MACjE,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,EAkCA,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 +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 { 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: any) {\n log.error('error processing stream update: %s', 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: any) {\n log.error('error processing stream update: %s', 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,KAA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AAO,KAAK,gBAChC;AACJ,eAAK,eAAL,8BAAkB;AAAA,EACpB;AAAA;AAAA;AAAA;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,OAAY;AACnB,yBAAI,MAAM,sCAAsC,KAAK;AACrD,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 unknown };\n } else {\n this.handleChunkReceived(value);\n return { done: false, value: value.content! };\n }\n } catch (error: unknown) {\n log.error('error processing stream update: %s', error);\n return { done: true, value: undefined as unknown };\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: unknown) {\n log.error('error processing stream update: %s', 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,CA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AAAA;AAAA;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,OAAgB;AACvB,yBAAI,MAAM,sCAAsC,KAAK;AACrD,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_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: any) {\n log.error('error processing stream update: %s', 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: any) {\n log.error('error processing stream update: %s', 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;A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AU,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,OAAY;AACnB,cAAI,MAAM,sCAAsC,KAAK;AACrD,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 unknown };\n } else {\n this.handleChunkReceived(value);\n return { done: false, value: value.content! };\n }\n } catch (error: unknown) {\n log.error('error processing stream update: %s', error);\n return { done: true, value: undefined as unknown };\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: unknown) {\n log.error('error processing stream update: %s', 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,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR,mBAAO,EAAE,MAAM,MAAM,OAAO,OAAqB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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,OAAgB;AACvB,cAAI,MAAM,sCAAsC,KAAK;AACrD,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":[]}
@@ -0,0 +1,38 @@
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 frame_processor_exports = {};
20
+ __export(frame_processor_exports, {
21
+ FrameProcessor: () => FrameProcessor
22
+ });
23
+ module.exports = __toCommonJS(frame_processor_exports);
24
+ var import_audio_frame = require("./audio_frame.cjs");
25
+ var import_video_frame = require("./video_frame.cjs");
26
+ class FrameProcessor {
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
+ onStreamInfoUpdated(_info) {
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ onCredentialsUpdated(_credentials) {
32
+ }
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ FrameProcessor
37
+ });
38
+ //# sourceMappingURL=frame_processor.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/frame_processor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { type AudioFrame } from './audio_frame.js';\nimport { type VideoFrame } from './video_frame.js';\n\nexport type FrameProcessorStreamInfo = {\n roomName: string;\n participantIdentity: string;\n publicationSid: string;\n};\n\nexport type FrameProcessorCredentials = {\n token: string;\n url: string;\n};\n\nexport abstract class FrameProcessor<Frame extends VideoFrame | AudioFrame> {\n abstract isEnabled(): boolean;\n abstract setEnabled(enabled: boolean): void;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onStreamInfoUpdated(_info: FrameProcessorStreamInfo): void {}\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onCredentialsUpdated(_credentials: FrameProcessorCredentials): void {}\n\n abstract process(frame: Frame): Frame;\n abstract close(): void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAgC;AAChC,yBAAgC;AAazB,MAAe,eAAsD;AAAA;AAAA,EAK1E,oBAAoB,OAAuC;AAAA,EAAC;AAAA;AAAA,EAE5D,qBAAqB,cAA+C;AAAA,EAAC;AAIvE;","names":[]}
@@ -0,0 +1,29 @@
1
+ import { AudioFrame } from './audio_frame.cjs';
2
+ import { VideoFrame } from './video_frame.cjs';
3
+ import './proto/audio_frame_pb.cjs';
4
+ import '@bufbuild/protobuf';
5
+ import './proto/track_pb.cjs';
6
+ import './proto/stats_pb.cjs';
7
+ import './proto/e2ee_pb.cjs';
8
+ import './proto/handle_pb.cjs';
9
+ import './proto/video_frame_pb.cjs';
10
+
11
+ type FrameProcessorStreamInfo = {
12
+ roomName: string;
13
+ participantIdentity: string;
14
+ publicationSid: string;
15
+ };
16
+ type FrameProcessorCredentials = {
17
+ token: string;
18
+ url: string;
19
+ };
20
+ declare abstract class FrameProcessor<Frame extends VideoFrame | AudioFrame> {
21
+ abstract isEnabled(): boolean;
22
+ abstract setEnabled(enabled: boolean): void;
23
+ onStreamInfoUpdated(_info: FrameProcessorStreamInfo): void;
24
+ onCredentialsUpdated(_credentials: FrameProcessorCredentials): void;
25
+ abstract process(frame: Frame): Frame;
26
+ abstract close(): void;
27
+ }
28
+
29
+ export { FrameProcessor, type FrameProcessorCredentials, type FrameProcessorStreamInfo };
@@ -0,0 +1,29 @@
1
+ import { AudioFrame } from './audio_frame.js';
2
+ import { VideoFrame } from './video_frame.js';
3
+ import './proto/audio_frame_pb.js';
4
+ import '@bufbuild/protobuf';
5
+ import './proto/track_pb.js';
6
+ import './proto/stats_pb.js';
7
+ import './proto/e2ee_pb.js';
8
+ import './proto/handle_pb.js';
9
+ import './proto/video_frame_pb.js';
10
+
11
+ type FrameProcessorStreamInfo = {
12
+ roomName: string;
13
+ participantIdentity: string;
14
+ publicationSid: string;
15
+ };
16
+ type FrameProcessorCredentials = {
17
+ token: string;
18
+ url: string;
19
+ };
20
+ declare abstract class FrameProcessor<Frame extends VideoFrame | AudioFrame> {
21
+ abstract isEnabled(): boolean;
22
+ abstract setEnabled(enabled: boolean): void;
23
+ onStreamInfoUpdated(_info: FrameProcessorStreamInfo): void;
24
+ onCredentialsUpdated(_credentials: FrameProcessorCredentials): void;
25
+ abstract process(frame: Frame): Frame;
26
+ abstract close(): void;
27
+ }
28
+
29
+ export { FrameProcessor, type FrameProcessorCredentials, type FrameProcessorStreamInfo };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame_processor.d.ts","sourceRoot":"","sources":["../src/frame_processor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,8BAAsB,cAAc,CAAC,KAAK,SAAS,UAAU,GAAG,UAAU;IACxE,QAAQ,CAAC,SAAS,IAAI,OAAO;IAC7B,QAAQ,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAG3C,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,IAAI;IAE1D,oBAAoB,CAAC,YAAY,EAAE,yBAAyB,GAAG,IAAI;IAEnE,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IACrC,QAAQ,CAAC,KAAK,IAAI,IAAI;CACvB"}
@@ -0,0 +1,14 @@
1
+ import {} from "./audio_frame.js";
2
+ import {} from "./video_frame.js";
3
+ class FrameProcessor {
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ onStreamInfoUpdated(_info) {
6
+ }
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ onCredentialsUpdated(_credentials) {
9
+ }
10
+ }
11
+ export {
12
+ FrameProcessor
13
+ };
14
+ //# sourceMappingURL=frame_processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/frame_processor.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { type AudioFrame } from './audio_frame.js';\nimport { type VideoFrame } from './video_frame.js';\n\nexport type FrameProcessorStreamInfo = {\n roomName: string;\n participantIdentity: string;\n publicationSid: string;\n};\n\nexport type FrameProcessorCredentials = {\n token: string;\n url: string;\n};\n\nexport abstract class FrameProcessor<Frame extends VideoFrame | AudioFrame> {\n abstract isEnabled(): boolean;\n abstract setEnabled(enabled: boolean): void;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onStreamInfoUpdated(_info: FrameProcessorStreamInfo): void {}\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onCredentialsUpdated(_credentials: FrameProcessorCredentials): void {}\n\n abstract process(frame: Frame): Frame;\n abstract close(): void;\n}\n"],"mappings":"AAGA,eAAgC;AAChC,eAAgC;AAazB,MAAe,eAAsD;AAAA;AAAA,EAK1E,oBAAoB,OAAuC;AAAA,EAAC;AAAA;AAAA,EAE5D,qBAAqB,cAA+C;AAAA,EAAC;AAIvE;","names":[]}
package/dist/index.cjs CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  EncryptionState: () => import_e2ee_pb.EncryptionState,
37
37
  EncryptionType: () => import_e2ee_pb.EncryptionType,
38
38
  FrameCryptor: () => import_e2ee.FrameCryptor,
39
+ FrameProcessor: () => import_frame_processor.FrameProcessor,
39
40
  IceServer: () => import_room_pb.IceServer,
40
41
  IceTransportType: () => import_room_pb.IceTransportType,
41
42
  KeyProvider: () => import_e2ee.KeyProvider,
@@ -90,6 +91,7 @@ var import_track_publication = require("./track_publication.cjs");
90
91
  var import_video_frame = require("./video_frame.cjs");
91
92
  var import_video_source = require("./video_source.cjs");
92
93
  var import_video_stream = require("./video_stream.cjs");
94
+ var import_frame_processor = require("./frame_processor.cjs");
93
95
  // Annotate the CommonJS export names for ESM import in node:
94
96
  0 && (module.exports = {
95
97
  AudioFilter,
@@ -109,6 +111,7 @@ var import_video_stream = require("./video_stream.cjs");
109
111
  EncryptionState,
110
112
  EncryptionType,
111
113
  FrameCryptor,
114
+ FrameProcessor,
112
115
  IceServer,
113
116
  IceTransportType,
114
117
  KeyProvider,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport { AudioFrame, combineAudioFrames } from './audio_frame.js';\nexport { AudioResampler, AudioResamplerQuality } from './audio_resampler.js';\nexport { AudioSource } from './audio_source.js';\nexport { AudioStream } from './audio_stream.js';\nexport type { NoiseCancellationOptions } from './audio_stream.js';\nexport { AudioFilter } from './audio_filter.js';\nexport { AudioMixer, type AudioMixerOptions } from './audio_mixer.js';\nexport * from './data_streams/index.js';\nexport { E2EEManager, FrameCryptor, KeyProvider } from './e2ee.js';\nexport type { E2EEOptions, KeyProviderOptions } from './e2ee.js';\nexport { dispose } from './ffi_client.js';\nexport { LocalParticipant, Participant, RemoteParticipant } from './participant.js';\nexport { EncryptionState, EncryptionType } from './proto/e2ee_pb.js';\nexport { DisconnectReason, ParticipantKind } from './proto/participant_pb.js';\nexport {\n ConnectionQuality,\n ConnectionState,\n ContinualGatheringPolicy,\n DataPacketKind,\n IceServer,\n IceTransportType,\n TrackPublishOptions,\n} from './proto/room_pb.js';\nexport { StreamState, TrackKind, TrackSource } from './proto/track_pb.js';\nexport { VideoBufferType, VideoCodec, VideoRotation } from './proto/video_frame_pb.js';\nexport { ConnectError, Room, RoomEvent, type RoomOptions, type RtcConfiguration } from './room.js';\nexport { RpcError, type PerformRpcParams, type RpcInvocationData } from './rpc.js';\nexport {\n LocalAudioTrack,\n LocalVideoTrack,\n RemoteAudioTrack,\n RemoteVideoTrack,\n Track,\n type AudioTrack,\n type LocalTrack,\n type RemoteTrack,\n type VideoTrack,\n} from './track.js';\nexport {\n LocalTrackPublication,\n RemoteTrackPublication,\n TrackPublication,\n} from './track_publication.js';\nexport type { Transcription, TranscriptionSegment } from './transcription.js';\nexport type { ChatMessage } from './types.js';\nexport { VideoFrame } from './video_frame.js';\nexport { VideoSource } from './video_source.js';\nexport { VideoStream, type VideoFrameEvent } from './video_stream.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAA+C;AAC/C,6BAAsD;AACtD,0BAA4B;AAC5B,0BAA4B;AAE5B,0BAA4B;AAC5B,yBAAmD;AACnD,0BAAc,oCAXd;AAYA,kBAAuD;AAEvD,wBAAwB;AACxB,yBAAiE;AACjE,qBAAgD;AAChD,4BAAkD;AAClD,qBAQO;AACP,sBAAoD;AACpD,4BAA2D;AAC3D,kBAAuF;AACvF,iBAAwE;AACxE,mBAUO;AACP,+BAIO;AAGP,yBAA2B;AAC3B,0BAA4B;AAC5B,0BAAkD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport { AudioFrame, combineAudioFrames } from './audio_frame.js';\nexport { AudioResampler, AudioResamplerQuality } from './audio_resampler.js';\nexport { AudioSource } from './audio_source.js';\nexport { AudioStream } from './audio_stream.js';\nexport type { NoiseCancellationOptions } from './audio_stream.js';\nexport { AudioFilter } from './audio_filter.js';\nexport { AudioMixer, type AudioMixerOptions } from './audio_mixer.js';\nexport * from './data_streams/index.js';\nexport { E2EEManager, FrameCryptor, KeyProvider } from './e2ee.js';\nexport type { E2EEOptions, KeyProviderOptions } from './e2ee.js';\nexport { dispose } from './ffi_client.js';\nexport { LocalParticipant, Participant, RemoteParticipant } from './participant.js';\nexport { EncryptionState, EncryptionType } from './proto/e2ee_pb.js';\nexport { DisconnectReason, ParticipantKind } from './proto/participant_pb.js';\nexport {\n ConnectionQuality,\n ConnectionState,\n ContinualGatheringPolicy,\n DataPacketKind,\n IceServer,\n IceTransportType,\n TrackPublishOptions,\n} from './proto/room_pb.js';\nexport { StreamState, TrackKind, TrackSource } from './proto/track_pb.js';\nexport { VideoBufferType, VideoCodec, VideoRotation } from './proto/video_frame_pb.js';\nexport { ConnectError, Room, RoomEvent, type RoomOptions, type RtcConfiguration } from './room.js';\nexport { RpcError, type PerformRpcParams, type RpcInvocationData } from './rpc.js';\nexport {\n LocalAudioTrack,\n LocalVideoTrack,\n RemoteAudioTrack,\n RemoteVideoTrack,\n Track,\n type AudioTrack,\n type LocalTrack,\n type RemoteTrack,\n type VideoTrack,\n} from './track.js';\nexport {\n LocalTrackPublication,\n RemoteTrackPublication,\n TrackPublication,\n} from './track_publication.js';\nexport type { Transcription, TranscriptionSegment } from './transcription.js';\nexport type { ChatMessage } from './types.js';\nexport { VideoFrame } from './video_frame.js';\nexport { VideoSource } from './video_source.js';\nexport { VideoStream, type VideoFrameEvent } from './video_stream.js';\nexport {\n FrameProcessor,\n type FrameProcessorStreamInfo,\n type FrameProcessorCredentials,\n} from './frame_processor.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAA+C;AAC/C,6BAAsD;AACtD,0BAA4B;AAC5B,0BAA4B;AAE5B,0BAA4B;AAC5B,yBAAmD;AACnD,0BAAc,oCAXd;AAYA,kBAAuD;AAEvD,wBAAwB;AACxB,yBAAiE;AACjE,qBAAgD;AAChD,4BAAkD;AAClD,qBAQO;AACP,sBAAoD;AACpD,4BAA2D;AAC3D,kBAAuF;AACvF,iBAAwE;AACxE,mBAUO;AACP,+BAIO;AAGP,yBAA2B;AAC3B,0BAA4B;AAC5B,0BAAkD;AAClD,6BAIO;","names":[]}