@livekit/rtc-node 0.13.14 → 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 (122) hide show
  1. package/dist/audio_stream.cjs +3 -2
  2. package/dist/audio_stream.cjs.map +1 -1
  3. package/dist/audio_stream.d.cts +2 -1
  4. package/dist/audio_stream.d.ts +2 -1
  5. package/dist/audio_stream.d.ts.map +1 -1
  6. package/dist/audio_stream.js +2 -1
  7. package/dist/audio_stream.js.map +1 -1
  8. package/dist/data_streams/index.d.cts +2 -2
  9. package/dist/data_streams/index.d.ts +2 -2
  10. package/dist/data_streams/stream_reader.cjs.map +1 -1
  11. package/dist/data_streams/stream_reader.d.cts +2 -2
  12. package/dist/data_streams/stream_reader.d.ts +2 -2
  13. package/dist/data_streams/stream_reader.d.ts.map +1 -1
  14. package/dist/data_streams/stream_reader.js.map +1 -1
  15. package/dist/data_streams/stream_writer.cjs.map +1 -1
  16. package/dist/data_streams/stream_writer.d.cts +2 -2
  17. package/dist/data_streams/stream_writer.d.ts +2 -2
  18. package/dist/data_streams/stream_writer.d.ts.map +1 -1
  19. package/dist/data_streams/stream_writer.js.map +1 -1
  20. package/dist/data_streams/types.d.cts +2 -2
  21. package/dist/data_streams/types.d.ts +2 -2
  22. package/dist/ffi_client.d.cts +1 -0
  23. package/dist/ffi_client.d.ts +1 -0
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.ts +2 -2
  26. package/dist/participant.cjs +13 -15
  27. package/dist/participant.cjs.map +1 -1
  28. package/dist/participant.d.cts +2 -2
  29. package/dist/participant.d.ts +2 -2
  30. package/dist/participant.d.ts.map +1 -1
  31. package/dist/participant.js +5 -7
  32. package/dist/participant.js.map +1 -1
  33. package/dist/proto/audio_frame_pb.cjs +4 -2
  34. package/dist/proto/audio_frame_pb.cjs.map +1 -1
  35. package/dist/proto/audio_frame_pb.d.cts +8 -0
  36. package/dist/proto/audio_frame_pb.d.ts +8 -0
  37. package/dist/proto/audio_frame_pb.d.ts.map +1 -1
  38. package/dist/proto/audio_frame_pb.js +4 -2
  39. package/dist/proto/audio_frame_pb.js.map +1 -1
  40. package/dist/proto/data_stream_pb.cjs +1549 -0
  41. package/dist/proto/data_stream_pb.cjs.map +1 -0
  42. package/dist/proto/data_stream_pb.d.cts +1358 -0
  43. package/dist/proto/data_stream_pb.d.ts +1358 -0
  44. package/dist/proto/data_stream_pb.d.ts.map +1 -0
  45. package/dist/proto/data_stream_pb.js +1473 -0
  46. package/dist/proto/data_stream_pb.js.map +1 -0
  47. package/dist/proto/ffi_pb.cjs +43 -3
  48. package/dist/proto/ffi_pb.cjs.map +1 -1
  49. package/dist/proto/ffi_pb.d.cts +244 -1
  50. package/dist/proto/ffi_pb.d.ts +244 -1
  51. package/dist/proto/ffi_pb.d.ts.map +1 -1
  52. package/dist/proto/ffi_pb.js +43 -3
  53. package/dist/proto/ffi_pb.js.map +1 -1
  54. package/dist/proto/participant_pb.cjs +5 -1
  55. package/dist/proto/participant_pb.cjs.map +1 -1
  56. package/dist/proto/participant_pb.d.cts +9 -1
  57. package/dist/proto/participant_pb.d.ts +9 -1
  58. package/dist/proto/participant_pb.d.ts.map +1 -1
  59. package/dist/proto/participant_pb.js +5 -1
  60. package/dist/proto/participant_pb.js.map +1 -1
  61. package/dist/proto/room_pb.cjs +99 -2
  62. package/dist/proto/room_pb.cjs.map +1 -1
  63. package/dist/proto/room_pb.d.cts +130 -2
  64. package/dist/proto/room_pb.d.ts +130 -2
  65. package/dist/proto/room_pb.d.ts.map +1 -1
  66. package/dist/proto/room_pb.js +97 -3
  67. package/dist/proto/room_pb.js.map +1 -1
  68. package/dist/proto/track_pb.cjs +27 -1
  69. package/dist/proto/track_pb.cjs.map +1 -1
  70. package/dist/proto/track_pb.d.cts +40 -1
  71. package/dist/proto/track_pb.d.ts +40 -1
  72. package/dist/proto/track_pb.d.ts.map +1 -1
  73. package/dist/proto/track_pb.js +26 -1
  74. package/dist/proto/track_pb.js.map +1 -1
  75. package/dist/room.cjs +79 -3
  76. package/dist/room.cjs.map +1 -1
  77. package/dist/room.d.cts +51 -3
  78. package/dist/room.d.ts +51 -3
  79. package/dist/room.d.ts.map +1 -1
  80. package/dist/room.js +77 -1
  81. package/dist/room.js.map +1 -1
  82. package/dist/{stream_reader-a8_oiaOi.d.cts → stream_reader-Ch2zvjU3.d.cts} +0 -1
  83. package/dist/{stream_reader-DWUV4eJB.d.ts → stream_reader-DRyR29vo.d.ts} +0 -1
  84. package/dist/track.cjs +23 -4
  85. package/dist/track.cjs.map +1 -1
  86. package/dist/track.d.cts +8 -2
  87. package/dist/track.d.ts +8 -2
  88. package/dist/track.d.ts.map +1 -1
  89. package/dist/track.js +23 -4
  90. package/dist/track.js.map +1 -1
  91. package/dist/track_publication.d.cts +1 -0
  92. package/dist/track_publication.d.ts +1 -0
  93. package/dist/version.cjs +1 -1
  94. package/dist/version.cjs.map +1 -1
  95. package/dist/version.d.cts +1 -1
  96. package/dist/version.d.ts +1 -1
  97. package/dist/version.js +1 -1
  98. package/dist/version.js.map +1 -1
  99. package/dist/video_source.d.cts +1 -0
  100. package/dist/video_source.d.ts +1 -0
  101. package/dist/video_stream.cjs +1 -2
  102. package/dist/video_stream.cjs.map +1 -1
  103. package/dist/video_stream.d.cts +1 -1
  104. package/dist/video_stream.d.ts +1 -1
  105. package/dist/video_stream.d.ts.map +1 -1
  106. package/dist/video_stream.js +0 -1
  107. package/dist/video_stream.js.map +1 -1
  108. package/package.json +7 -7
  109. package/src/audio_stream.ts +5 -1
  110. package/src/data_streams/stream_reader.ts +0 -1
  111. package/src/data_streams/stream_writer.ts +0 -1
  112. package/src/participant.ts +13 -15
  113. package/src/proto/audio_frame_pb.ts +12 -0
  114. package/src/proto/data_stream_pb.ts +2515 -0
  115. package/src/proto/ffi_pb.ts +283 -1
  116. package/src/proto/participant_pb.ts +12 -0
  117. package/src/proto/room_pb.ts +212 -1
  118. package/src/proto/track_pb.ts +58 -0
  119. package/src/room.ts +79 -1
  120. package/src/track.ts +28 -4
  121. package/src/version.ts +1 -1
  122. package/src/video_stream.ts +1 -1
@@ -113,6 +113,58 @@ proto2.util.setEnumType(StreamState, "livekit.proto.StreamState", [
113
113
  { no: 2, name: "STATE_PAUSED" },
114
114
  ]);
115
115
 
116
+ /**
117
+ * @generated from enum livekit.proto.AudioTrackFeature
118
+ */
119
+ export enum AudioTrackFeature {
120
+ /**
121
+ * @generated from enum value: TF_STEREO = 0;
122
+ */
123
+ TF_STEREO = 0,
124
+
125
+ /**
126
+ * @generated from enum value: TF_NO_DTX = 1;
127
+ */
128
+ TF_NO_DTX = 1,
129
+
130
+ /**
131
+ * @generated from enum value: TF_AUTO_GAIN_CONTROL = 2;
132
+ */
133
+ TF_AUTO_GAIN_CONTROL = 2,
134
+
135
+ /**
136
+ * @generated from enum value: TF_ECHO_CANCELLATION = 3;
137
+ */
138
+ TF_ECHO_CANCELLATION = 3,
139
+
140
+ /**
141
+ * @generated from enum value: TF_NOISE_SUPPRESSION = 4;
142
+ */
143
+ TF_NOISE_SUPPRESSION = 4,
144
+
145
+ /**
146
+ * @generated from enum value: TF_ENHANCED_NOISE_CANCELLATION = 5;
147
+ */
148
+ TF_ENHANCED_NOISE_CANCELLATION = 5,
149
+
150
+ /**
151
+ * client will buffer audio once available and send it to the server via bytes stream once connected
152
+ *
153
+ * @generated from enum value: TF_PRECONNECT_BUFFER = 6;
154
+ */
155
+ TF_PRECONNECT_BUFFER = 6,
156
+ }
157
+ // Retrieve enum metadata with: proto2.getEnumType(AudioTrackFeature)
158
+ proto2.util.setEnumType(AudioTrackFeature, "livekit.proto.AudioTrackFeature", [
159
+ { no: 0, name: "TF_STEREO" },
160
+ { no: 1, name: "TF_NO_DTX" },
161
+ { no: 2, name: "TF_AUTO_GAIN_CONTROL" },
162
+ { no: 3, name: "TF_ECHO_CANCELLATION" },
163
+ { no: 4, name: "TF_NOISE_SUPPRESSION" },
164
+ { no: 5, name: "TF_ENHANCED_NOISE_CANCELLATION" },
165
+ { no: 6, name: "TF_PRECONNECT_BUFFER" },
166
+ ]);
167
+
116
168
  /**
117
169
  * Create a new VideoTrack from a VideoSource
118
170
  *
@@ -490,6 +542,11 @@ export class TrackPublicationInfo extends Message<TrackPublicationInfo> {
490
542
  */
491
543
  encryptionType?: EncryptionType;
492
544
 
545
+ /**
546
+ * @generated from field: repeated livekit.proto.AudioTrackFeature audio_features = 12;
547
+ */
548
+ audioFeatures: AudioTrackFeature[] = [];
549
+
493
550
  constructor(data?: PartialMessage<TrackPublicationInfo>) {
494
551
  super();
495
552
  proto2.util.initPartial(data, this);
@@ -509,6 +566,7 @@ export class TrackPublicationInfo extends Message<TrackPublicationInfo> {
509
566
  { no: 9, name: "muted", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true },
510
567
  { no: 10, name: "remote", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true },
511
568
  { no: 11, name: "encryption_type", kind: "enum", T: proto2.getEnumType(EncryptionType), req: true },
569
+ { no: 12, name: "audio_features", kind: "enum", T: proto2.getEnumType(AudioTrackFeature), repeated: true },
512
570
  ]);
513
571
 
514
572
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): TrackPublicationInfo {
package/src/room.ts CHANGED
@@ -3,7 +3,6 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';
5
5
  import EventEmitter from 'events';
6
- import { ReadableStream } from 'node:stream/web';
7
6
  import { ByteStreamReader, TextStreamReader } from './data_streams/stream_reader.js';
8
7
  import type {
9
8
  ByteStreamHandler,
@@ -105,6 +104,12 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
105
104
  return this.ffiHandle != undefined && this.connectionState != ConnectionState.CONN_DISCONNECTED;
106
105
  }
107
106
 
107
+ /**
108
+ * Gets the room's server ID. This ID is assigned by the LiveKit server
109
+ * and is unique for each room session.
110
+ * SID is assigned asynchronously after connection.
111
+ * @returns Promise that resolves to the room's server ID, or empty string if not connected
112
+ */
108
113
  async getSid(): Promise<string> {
109
114
  if (!this.isConnected) {
110
115
  return '';
@@ -127,6 +132,44 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
127
132
  });
128
133
  }
129
134
 
135
+ get numParticipants(): number {
136
+ return this.info?.numParticipants ?? 0;
137
+ }
138
+
139
+ get numPublishers(): number {
140
+ return this.info?.numPublishers ?? 0;
141
+ }
142
+
143
+ get creationTime(): Date {
144
+ return new Date(Number(this.info?.creationTime ?? 0));
145
+ }
146
+
147
+ get isRecording(): boolean {
148
+ return this.info?.activeRecording ?? false;
149
+ }
150
+
151
+ /**
152
+ * The time in seconds after which a room will be closed after the last
153
+ * participant has disconnected.
154
+ */
155
+ get departureTimeout(): number {
156
+ return this.info?.departureTimeout ?? 0;
157
+ }
158
+
159
+ /**
160
+ * The time in seconds after which an empty room will be automatically closed.
161
+ */
162
+ get emptyTimeout(): number {
163
+ return this.info?.emptyTimeout ?? 0;
164
+ }
165
+
166
+ /**
167
+ * Connects to a LiveKit room using the provided URL and access token.
168
+ * @param url The WebSocket URL of the LiveKit server
169
+ * @param token A valid LiveKit access token for authentication
170
+ * @param opts Optional room configuration options
171
+ * @throws ConnectError if connection fails
172
+ */
130
173
  async connect(url: string, token: string, opts?: RoomOptions) {
131
174
  const options = { ...defaultRoomOptions, ...opts };
132
175
  const e2eeOptions = { ...defaultE2EEOptions, ...options.e2ee };
@@ -176,6 +219,10 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
176
219
  }
177
220
  }
178
221
 
222
+ /**
223
+ * Disconnects from the room and cleans up all resources.
224
+ * This will stop all tracks and close the connection.
225
+ */
179
226
  async disconnect() {
180
227
  if (!this.isConnected) {
181
228
  return;
@@ -194,6 +241,13 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
194
241
  this.removeAllListeners();
195
242
  }
196
243
 
244
+ /**
245
+ * Registers a handler for incoming text data streams on a specific topic.
246
+ * Text streams are used for receiving structured text data from other participants.
247
+ * @param topic The topic to listen for text streams on
248
+ * @param callback Function to handle incoming text stream data
249
+ * @throws Error if a handler for this topic is already registered
250
+ */
197
251
  registerTextStreamHandler(topic: string, callback: TextStreamHandler) {
198
252
  if (this.textStreamHandlers.has(topic)) {
199
253
  throw new Error(`A text stream handler for topic "${topic}" has already been set.`);
@@ -205,6 +259,13 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
205
259
  this.textStreamHandlers.delete(topic);
206
260
  }
207
261
 
262
+ /**
263
+ * Registers a handler for incoming byte data streams on a specific topic.
264
+ * Byte streams are used for receiving binary data like files from other participants.
265
+ * @param topic The topic to listen for byte streams on
266
+ * @param callback Function to handle incoming byte stream data
267
+ * @throws Error if a handler for this topic is already registered
268
+ */
208
269
  registerByteStreamHandler(topic: string, callback: ByteStreamHandler) {
209
270
  if (this.byteStreamHandlers.has(topic)) {
210
271
  throw new Error(`A byte stream handler for topic "${topic}" has already been set.`);
@@ -421,6 +482,19 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
421
482
  this.handleStreamChunk(ev.value.chunk);
422
483
  } else if (ev.case === 'streamTrailerReceived' && ev.value.trailer) {
423
484
  this.handleStreamTrailer(ev.value.trailer);
485
+ } else if (ev.case === 'roomUpdated') {
486
+ this.info = ev.value;
487
+ this.emit(RoomEvent.RoomUpdated);
488
+ } else if (ev.case === 'moved') {
489
+ this.info = ev.value;
490
+ this.emit(RoomEvent.Moved);
491
+ } else if (ev.case === 'participantsUpdated') {
492
+ for (const info of ev.value.participants) {
493
+ const participant = this.retrieveParticipantByIdentity(info.identity!);
494
+ if (participant) {
495
+ participant.info = info;
496
+ }
497
+ }
424
498
  }
425
499
  };
426
500
 
@@ -632,6 +706,8 @@ export type RoomCallbacks = {
632
706
  reconnecting: () => void;
633
707
  reconnected: () => void;
634
708
  roomSidChanged: (sid: string) => void;
709
+ roomUpdated: () => void;
710
+ moved: () => void;
635
711
  };
636
712
 
637
713
  export enum RoomEvent {
@@ -663,4 +739,6 @@ export enum RoomEvent {
663
739
  Disconnected = 'disconnected',
664
740
  Reconnecting = 'reconnecting',
665
741
  Reconnected = 'reconnected',
742
+ RoomUpdated = 'roomUpdated',
743
+ Moved = 'moved',
666
744
  }
package/src/track.ts CHANGED
@@ -45,11 +45,18 @@ export abstract class Track {
45
45
  get muted(): boolean | undefined {
46
46
  return this.info?.muted;
47
47
  }
48
+
49
+ async close() {
50
+ this.ffi_handle.dispose();
51
+ }
48
52
  }
49
53
 
50
54
  export class LocalAudioTrack extends Track {
51
- constructor(owned: OwnedTrack) {
55
+ private source?: AudioSource;
56
+
57
+ constructor(owned: OwnedTrack, source?: AudioSource) {
52
58
  super(owned);
59
+ this.source = source;
53
60
  }
54
61
 
55
62
  static createAudioTrack(name: string, source: AudioSource): LocalAudioTrack {
@@ -62,13 +69,23 @@ export class LocalAudioTrack extends Track {
62
69
  message: { case: 'createAudioTrack', value: req },
63
70
  });
64
71
 
65
- return new LocalAudioTrack(res.track!);
72
+ return new LocalAudioTrack(res.track!, source);
73
+ }
74
+
75
+ async close(closeSource = true) {
76
+ await super.close();
77
+ if (closeSource) {
78
+ await this.source?.close();
79
+ }
66
80
  }
67
81
  }
68
82
 
69
83
  export class LocalVideoTrack extends Track {
70
- constructor(owned: OwnedTrack) {
84
+ private source?: VideoSource;
85
+
86
+ constructor(owned: OwnedTrack, source?: VideoSource) {
71
87
  super(owned);
88
+ this.source = source;
72
89
  }
73
90
 
74
91
  static createVideoTrack(name: string, source: VideoSource): LocalVideoTrack {
@@ -81,7 +98,14 @@ export class LocalVideoTrack extends Track {
81
98
  message: { case: 'createVideoTrack', value: req },
82
99
  });
83
100
 
84
- return new LocalVideoTrack(res.track!);
101
+ return new LocalVideoTrack(res.track!, source);
102
+ }
103
+
104
+ async close(closeSource = true) {
105
+ await super.close();
106
+ if (closeSource) {
107
+ await this.source?.close();
108
+ }
85
109
  }
86
110
  }
87
111
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.13.14";
1
+ export const SDK_VERSION = "0.13.16";
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- import { ReadableStream, type UnderlyingSource } from 'node:stream/web';
4
+ import type { UnderlyingSource } from 'node:stream/web';
5
5
  import type { FfiEvent } from './ffi_client.js';
6
6
  import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
7
7
  import type { NewVideoStreamResponse, VideoRotation } from './proto/video_frame_pb.js';