livekit-client 1.15.12 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/README.md +27 -15
  2. package/dist/livekit-client.esm.mjs +1750 -1581
  3. package/dist/livekit-client.esm.mjs.map +1 -1
  4. package/dist/livekit-client.umd.js +1 -1
  5. package/dist/livekit-client.umd.js.map +1 -1
  6. package/dist/src/api/SignalClient.d.ts +0 -2
  7. package/dist/src/api/SignalClient.d.ts.map +1 -1
  8. package/dist/src/index.d.ts +3 -3
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/options.d.ts +3 -9
  11. package/dist/src/options.d.ts.map +1 -1
  12. package/dist/src/proto/livekit_models_pb.d.ts +56 -1
  13. package/dist/src/proto/livekit_models_pb.d.ts.map +1 -1
  14. package/dist/src/proto/livekit_rtc_pb.d.ts +38 -0
  15. package/dist/src/proto/livekit_rtc_pb.d.ts.map +1 -1
  16. package/dist/src/room/PCTransport.d.ts +1 -2
  17. package/dist/src/room/PCTransport.d.ts.map +1 -1
  18. package/dist/src/room/PCTransportManager.d.ts.map +1 -1
  19. package/dist/src/room/RTCEngine.d.ts +1 -0
  20. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  21. package/dist/src/room/Room.d.ts +12 -15
  22. package/dist/src/room/Room.d.ts.map +1 -1
  23. package/dist/src/room/defaults.d.ts.map +1 -1
  24. package/dist/src/room/events.d.ts +8 -5
  25. package/dist/src/room/events.d.ts.map +1 -1
  26. package/dist/src/room/participant/LocalParticipant.d.ts +8 -25
  27. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  28. package/dist/src/room/participant/Participant.d.ts +6 -10
  29. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  30. package/dist/src/room/participant/RemoteParticipant.d.ts +9 -6
  31. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  32. package/dist/src/room/timers.d.ts +4 -5
  33. package/dist/src/room/timers.d.ts.map +1 -1
  34. package/dist/src/room/track/LocalVideoTrack.d.ts +3 -3
  35. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  36. package/dist/src/room/track/RemoteTrackPublication.d.ts +2 -2
  37. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  38. package/dist/src/room/track/Track.d.ts +5 -0
  39. package/dist/src/room/track/Track.d.ts.map +1 -1
  40. package/dist/src/room/track/options.d.ts +0 -5
  41. package/dist/src/room/track/options.d.ts.map +1 -1
  42. package/dist/src/room/types.d.ts +11 -3
  43. package/dist/src/room/types.d.ts.map +1 -1
  44. package/dist/src/version.d.ts +1 -1
  45. package/dist/ts4.2/src/api/SignalClient.d.ts +0 -2
  46. package/dist/ts4.2/src/index.d.ts +3 -3
  47. package/dist/ts4.2/src/options.d.ts +3 -9
  48. package/dist/ts4.2/src/proto/livekit_models_pb.d.ts +56 -1
  49. package/dist/ts4.2/src/proto/livekit_rtc_pb.d.ts +38 -0
  50. package/dist/ts4.2/src/room/PCTransport.d.ts +1 -2
  51. package/dist/ts4.2/src/room/RTCEngine.d.ts +1 -0
  52. package/dist/ts4.2/src/room/Room.d.ts +12 -15
  53. package/dist/ts4.2/src/room/events.d.ts +8 -5
  54. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +8 -25
  55. package/dist/ts4.2/src/room/participant/Participant.d.ts +6 -10
  56. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +9 -6
  57. package/dist/ts4.2/src/room/timers.d.ts +4 -5
  58. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +3 -3
  59. package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +2 -2
  60. package/dist/ts4.2/src/room/track/Track.d.ts +5 -0
  61. package/dist/ts4.2/src/room/track/options.d.ts +0 -5
  62. package/dist/ts4.2/src/room/types.d.ts +11 -3
  63. package/dist/ts4.2/src/version.d.ts +1 -1
  64. package/package.json +10 -9
  65. package/src/api/SignalClient.ts +2 -6
  66. package/src/e2ee/E2eeManager.ts +2 -2
  67. package/src/index.ts +2 -4
  68. package/src/options.ts +3 -10
  69. package/src/proto/livekit_models_pb.ts +78 -0
  70. package/src/proto/livekit_rtc_pb.ts +53 -0
  71. package/src/room/PCTransport.ts +3 -13
  72. package/src/room/PCTransportManager.ts +2 -3
  73. package/src/room/RTCEngine.ts +11 -1
  74. package/src/room/Room.ts +145 -114
  75. package/src/room/defaults.ts +1 -5
  76. package/src/room/events.ts +8 -6
  77. package/src/room/participant/LocalParticipant.ts +36 -77
  78. package/src/room/participant/Participant.ts +23 -24
  79. package/src/room/participant/RemoteParticipant.ts +27 -24
  80. package/src/room/track/LocalVideoTrack.test.ts +1 -1
  81. package/src/room/track/LocalVideoTrack.ts +11 -7
  82. package/src/room/track/RemoteTrackPublication.ts +2 -7
  83. package/src/room/track/Track.ts +10 -1
  84. package/src/room/track/options.ts +0 -6
  85. package/src/room/types.ts +11 -4
  86. package/src/version.ts +1 -1
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LogLevel, getLogger, setLogExtension, setLogLevel } from './logger';
2
- import { DataPacket_Kind, DisconnectReason, VideoQuality } from './proto/livekit_models_pb';
2
+ import { DataPacket_Kind, DisconnectReason } from './proto/livekit_models_pb';
3
3
  import DefaultReconnectPolicy from './room/DefaultReconnectPolicy';
4
- import Room, { ConnectionState, RoomState } from './room/Room';
4
+ import Room, { ConnectionState } from './room/Room';
5
5
  import LocalParticipant from './room/participant/LocalParticipant';
6
6
  import Participant, { ConnectionQuality } from './room/participant/Participant';
7
7
  import type { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
@@ -58,7 +58,6 @@ export {
58
58
  getLogger,
59
59
  Room,
60
60
  ConnectionState,
61
- RoomState,
62
61
  DataPacket_Kind,
63
62
  DisconnectReason,
64
63
  Participant,
@@ -73,7 +72,6 @@ export {
73
72
  RemoteVideoTrack,
74
73
  RemoteTrackPublication,
75
74
  TrackPublication,
76
- VideoQuality,
77
75
  ConnectionQuality,
78
76
  DefaultReconnectPolicy,
79
77
  CriticalTimers,
package/src/options.ts CHANGED
@@ -81,12 +81,11 @@ export interface InternalRoomOptions {
81
81
  expSignalLatency?: number;
82
82
 
83
83
  /**
84
- * @internal
85
- * @experimental
86
- * experimental flag, mix all audio tracks in web audio
84
+ * mix all audio tracks in web audio, helps to tackle some audio auto playback issues
85
+ * allows for passing in your own AudioContext instance, too
87
86
  */
88
87
 
89
- expWebAudioMix: boolean | WebAudioSettings;
88
+ webAudioMix: boolean | WebAudioSettings;
90
89
 
91
90
  /**
92
91
  * @experimental
@@ -116,12 +115,6 @@ export interface InternalRoomConnectOptions {
116
115
  */
117
116
  rtcConfig?: RTCConfiguration;
118
117
 
119
- /**
120
- * @deprecated
121
- * publish only mode
122
- */
123
- publishOnly?: string;
124
-
125
118
  /** specifies how often an initial join connection is allowed to retry (only applicable if server is not reachable) */
126
119
  maxRetries: number;
127
120
 
@@ -301,6 +301,16 @@ export enum DisconnectReason {
301
301
  * @generated from enum value: JOIN_FAILURE = 7;
302
302
  */
303
303
  JOIN_FAILURE = 7,
304
+
305
+ /**
306
+ * @generated from enum value: MIGRATION = 8;
307
+ */
308
+ MIGRATION = 8,
309
+
310
+ /**
311
+ * @generated from enum value: SIGNAL_CLOSE = 9;
312
+ */
313
+ SIGNAL_CLOSE = 9,
304
314
  }
305
315
  // Retrieve enum metadata with: proto3.getEnumType(DisconnectReason)
306
316
  proto3.util.setEnumType(DisconnectReason, "livekit.DisconnectReason", [
@@ -312,6 +322,8 @@ proto3.util.setEnumType(DisconnectReason, "livekit.DisconnectReason", [
312
322
  { no: 5, name: "ROOM_DELETED" },
313
323
  { no: 6, name: "STATE_MISMATCH" },
314
324
  { no: 7, name: "JOIN_FAILURE" },
325
+ { no: 8, name: "MIGRATION" },
326
+ { no: 9, name: "SIGNAL_CLOSE" },
315
327
  ]);
316
328
 
317
329
  /**
@@ -437,6 +449,11 @@ export class Room extends Message<Room> {
437
449
  */
438
450
  activeRecording = false;
439
451
 
452
+ /**
453
+ * @generated from field: livekit.TimedVersion version = 13;
454
+ */
455
+ version?: TimedVersion;
456
+
440
457
  constructor(data?: PartialMessage<Room>) {
441
458
  super();
442
459
  proto3.util.initPartial(data, this);
@@ -456,6 +473,7 @@ export class Room extends Message<Room> {
456
473
  { no: 9, name: "num_participants", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
457
474
  { no: 11, name: "num_publishers", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
458
475
  { no: 10, name: "active_recording", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
476
+ { no: 13, name: "version", kind: "message", T: TimedVersion },
459
477
  ]);
460
478
 
461
479
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Room {
@@ -726,6 +744,11 @@ export class ParticipantInfo extends Message<ParticipantInfo> {
726
744
  */
727
745
  isPublisher = false;
728
746
 
747
+ /**
748
+ * @generated from field: livekit.ParticipantInfo.Kind kind = 14;
749
+ */
750
+ kind = ParticipantInfo_Kind.STANDARD;
751
+
729
752
  constructor(data?: PartialMessage<ParticipantInfo>) {
730
753
  super();
731
754
  proto3.util.initPartial(data, this);
@@ -745,6 +768,7 @@ export class ParticipantInfo extends Message<ParticipantInfo> {
745
768
  { no: 11, name: "permission", kind: "message", T: ParticipantPermission },
746
769
  { no: 12, name: "region", kind: "scalar", T: 9 /* ScalarType.STRING */ },
747
770
  { no: 13, name: "is_publisher", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
771
+ { no: 14, name: "kind", kind: "enum", T: proto3.getEnumType(ParticipantInfo_Kind) },
748
772
  ]);
749
773
 
750
774
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ParticipantInfo {
@@ -804,6 +828,54 @@ proto3.util.setEnumType(ParticipantInfo_State, "livekit.ParticipantInfo.State",
804
828
  { no: 3, name: "DISCONNECTED" },
805
829
  ]);
806
830
 
831
+ /**
832
+ * @generated from enum livekit.ParticipantInfo.Kind
833
+ */
834
+ export enum ParticipantInfo_Kind {
835
+ /**
836
+ * standard participants, e.g. web clients
837
+ *
838
+ * @generated from enum value: STANDARD = 0;
839
+ */
840
+ STANDARD = 0,
841
+
842
+ /**
843
+ * only ingests streams
844
+ *
845
+ * @generated from enum value: INGRESS = 1;
846
+ */
847
+ INGRESS = 1,
848
+
849
+ /**
850
+ * only consumes streams
851
+ *
852
+ * @generated from enum value: EGRESS = 2;
853
+ */
854
+ EGRESS = 2,
855
+
856
+ /**
857
+ * SIP participants
858
+ *
859
+ * @generated from enum value: SIP = 3;
860
+ */
861
+ SIP = 3,
862
+
863
+ /**
864
+ * LiveKit agents
865
+ *
866
+ * @generated from enum value: AGENT = 4;
867
+ */
868
+ AGENT = 4,
869
+ }
870
+ // Retrieve enum metadata with: proto3.getEnumType(ParticipantInfo_Kind)
871
+ proto3.util.setEnumType(ParticipantInfo_Kind, "livekit.ParticipantInfo.Kind", [
872
+ { no: 0, name: "STANDARD" },
873
+ { no: 1, name: "INGRESS" },
874
+ { no: 2, name: "EGRESS" },
875
+ { no: 3, name: "SIP" },
876
+ { no: 4, name: "AGENT" },
877
+ ]);
878
+
807
879
  /**
808
880
  * @generated from message livekit.Encryption
809
881
  */
@@ -1020,6 +1092,11 @@ export class TrackInfo extends Message<TrackInfo> {
1020
1092
  */
1021
1093
  stream = "";
1022
1094
 
1095
+ /**
1096
+ * @generated from field: livekit.TimedVersion version = 18;
1097
+ */
1098
+ version?: TimedVersion;
1099
+
1023
1100
  constructor(data?: PartialMessage<TrackInfo>) {
1024
1101
  super();
1025
1102
  proto3.util.initPartial(data, this);
@@ -1045,6 +1122,7 @@ export class TrackInfo extends Message<TrackInfo> {
1045
1122
  { no: 15, name: "disable_red", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
1046
1123
  { no: 16, name: "encryption", kind: "enum", T: proto3.getEnumType(Encryption_Type) },
1047
1124
  { no: 17, name: "stream", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1125
+ { no: 18, name: "version", kind: "message", T: TimedVersion },
1048
1126
  ]);
1049
1127
 
1050
1128
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): TrackInfo {
@@ -1208,6 +1208,7 @@ export class LeaveRequest extends Message<LeaveRequest> {
1208
1208
  /**
1209
1209
  * sent when server initiates the disconnect due to server-restart
1210
1210
  * indicates clients should attempt full-reconnect sequence
1211
+ * NOTE: `can_reconnect` obsoleted by `action` starting in protocol version 13
1211
1212
  *
1212
1213
  * @generated from field: bool can_reconnect = 1;
1213
1214
  */
@@ -1218,6 +1219,16 @@ export class LeaveRequest extends Message<LeaveRequest> {
1218
1219
  */
1219
1220
  reason = DisconnectReason.UNKNOWN_REASON;
1220
1221
 
1222
+ /**
1223
+ * @generated from field: livekit.LeaveRequest.Action action = 3;
1224
+ */
1225
+ action = LeaveRequest_Action.DISCONNECT;
1226
+
1227
+ /**
1228
+ * @generated from field: livekit.RegionSettings regions = 4;
1229
+ */
1230
+ regions?: RegionSettings;
1231
+
1221
1232
  constructor(data?: PartialMessage<LeaveRequest>) {
1222
1233
  super();
1223
1234
  proto3.util.initPartial(data, this);
@@ -1228,6 +1239,8 @@ export class LeaveRequest extends Message<LeaveRequest> {
1228
1239
  static readonly fields: FieldList = proto3.util.newFieldList(() => [
1229
1240
  { no: 1, name: "can_reconnect", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
1230
1241
  { no: 2, name: "reason", kind: "enum", T: proto3.getEnumType(DisconnectReason) },
1242
+ { no: 3, name: "action", kind: "enum", T: proto3.getEnumType(LeaveRequest_Action) },
1243
+ { no: 4, name: "regions", kind: "message", T: RegionSettings },
1231
1244
  ]);
1232
1245
 
1233
1246
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): LeaveRequest {
@@ -1247,6 +1260,40 @@ export class LeaveRequest extends Message<LeaveRequest> {
1247
1260
  }
1248
1261
  }
1249
1262
 
1263
+ /**
1264
+ * indicates action clients should take on receiving this message
1265
+ *
1266
+ * @generated from enum livekit.LeaveRequest.Action
1267
+ */
1268
+ export enum LeaveRequest_Action {
1269
+ /**
1270
+ * should disconnect
1271
+ *
1272
+ * @generated from enum value: DISCONNECT = 0;
1273
+ */
1274
+ DISCONNECT = 0,
1275
+
1276
+ /**
1277
+ * should attempt a resume with `reconnect=1` in join URL
1278
+ *
1279
+ * @generated from enum value: RESUME = 1;
1280
+ */
1281
+ RESUME = 1,
1282
+
1283
+ /**
1284
+ * should attempt a reconnect, i. e. no `reconnect=1`
1285
+ *
1286
+ * @generated from enum value: RECONNECT = 2;
1287
+ */
1288
+ RECONNECT = 2,
1289
+ }
1290
+ // Retrieve enum metadata with: proto3.getEnumType(LeaveRequest_Action)
1291
+ proto3.util.setEnumType(LeaveRequest_Action, "livekit.LeaveRequest.Action", [
1292
+ { no: 0, name: "DISCONNECT" },
1293
+ { no: 1, name: "RESUME" },
1294
+ { no: 2, name: "RECONNECT" },
1295
+ ]);
1296
+
1250
1297
  /**
1251
1298
  * message to indicate published video track dimensions are changing
1252
1299
  *
@@ -1947,6 +1994,11 @@ export class SyncState extends Message<SyncState> {
1947
1994
  */
1948
1995
  offer?: SessionDescription;
1949
1996
 
1997
+ /**
1998
+ * @generated from field: repeated string track_sids_disabled = 6;
1999
+ */
2000
+ trackSidsDisabled: string[] = [];
2001
+
1950
2002
  constructor(data?: PartialMessage<SyncState>) {
1951
2003
  super();
1952
2004
  proto3.util.initPartial(data, this);
@@ -1960,6 +2012,7 @@ export class SyncState extends Message<SyncState> {
1960
2012
  { no: 3, name: "publish_tracks", kind: "message", T: TrackPublishedResponse, repeated: true },
1961
2013
  { no: 4, name: "data_channels", kind: "message", T: DataChannelInfo, repeated: true },
1962
2014
  { no: 5, name: "offer", kind: "message", T: SessionDescription },
2015
+ { no: 6, name: "track_sids_disabled", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
1963
2016
  ]);
1964
2017
 
1965
2018
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): SyncState {
@@ -5,7 +5,7 @@ import { debounce } from 'ts-debounce';
5
5
  import log, { LoggerNames, getLogger } from '../logger';
6
6
  import { NegotiationError, UnexpectedConnectionState } from './errors';
7
7
  import type { LoggerOptions } from './types';
8
- import { ddExtensionURI, isChromiumBased, isSVCCodec } from './utils';
8
+ import { ddExtensionURI, isSVCCodec } from './utils';
9
9
 
10
10
  /** @internal */
11
11
  interface TrackBitrateInfo {
@@ -42,8 +42,6 @@ export default class PCTransport extends EventEmitter {
42
42
 
43
43
  private config?: RTCConfiguration;
44
44
 
45
- private mediaConstraints: Record<string, unknown>;
46
-
47
45
  private log = log;
48
46
 
49
47
  private loggerOptions: LoggerOptions;
@@ -76,24 +74,16 @@ export default class PCTransport extends EventEmitter {
76
74
 
77
75
  onTrack?: (ev: RTCTrackEvent) => void;
78
76
 
79
- constructor(
80
- config?: RTCConfiguration,
81
- mediaConstraints: Record<string, unknown> = {},
82
- loggerOptions: LoggerOptions = {},
83
- ) {
77
+ constructor(config?: RTCConfiguration, loggerOptions: LoggerOptions = {}) {
84
78
  super();
85
79
  this.log = getLogger(loggerOptions.loggerName ?? LoggerNames.PCTransport);
86
80
  this.loggerOptions = loggerOptions;
87
81
  this.config = config;
88
- this.mediaConstraints = mediaConstraints;
89
82
  this._pc = this.createPC();
90
83
  }
91
84
 
92
85
  private createPC() {
93
- const pc = isChromiumBased()
94
- ? // @ts-expect-error chrome allows additional media constraints to be passed into the RTCPeerConnection constructor
95
- new RTCPeerConnection(this.config, this.mediaConstraints)
96
- : new RTCPeerConnection(this.config);
86
+ const pc = new RTCPeerConnection(this.config);
97
87
 
98
88
  pc.onicecandidate = (ev) => {
99
89
  if (!ev.candidate) return;
@@ -71,9 +71,8 @@ export class PCTransportManager {
71
71
 
72
72
  this.isPublisherConnectionRequired = !subscriberPrimary;
73
73
  this.isSubscriberConnectionRequired = subscriberPrimary;
74
- const googConstraints = { optional: [{ googDscp: true }] };
75
- this.publisher = new PCTransport(rtcConfig, googConstraints, loggerOptions);
76
- this.subscriber = new PCTransport(rtcConfig, undefined, loggerOptions);
74
+ this.publisher = new PCTransport(rtcConfig, loggerOptions);
75
+ this.subscriber = new PCTransport(rtcConfig, loggerOptions);
77
76
 
78
77
  this.publisher.onConnectionStateChange = this.updateState;
79
78
  this.subscriber.onConnectionStateChange = this.updateState;
@@ -106,6 +106,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
106
106
  return this._isClosed;
107
107
  }
108
108
 
109
+ get pendingReconnect() {
110
+ return !!this.reconnectTimeout;
111
+ }
112
+
109
113
  private lossyDC?: RTCDataChannel;
110
114
 
111
115
  // @ts-ignore noUnusedLocals
@@ -838,7 +842,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
838
842
  this.regionUrlProvider.updateToken(this.token);
839
843
  }
840
844
  this.reconnectTimeout = CriticalTimers.setTimeout(
841
- () => this.attemptReconnect(disconnectReason),
845
+ () =>
846
+ this.attemptReconnect(disconnectReason).finally(() => (this.reconnectTimeout = undefined)),
842
847
  delay,
843
848
  );
844
849
  };
@@ -1266,11 +1271,15 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1266
1271
  */
1267
1272
  const autoSubscribe = this.signalOpts?.autoSubscribe ?? true;
1268
1273
  const trackSids = new Array<string>();
1274
+ const trackSidsDisabled = new Array<string>();
1269
1275
 
1270
1276
  remoteTracks.forEach((track) => {
1271
1277
  if (track.isDesired !== autoSubscribe) {
1272
1278
  trackSids.push(track.trackSid);
1273
1279
  }
1280
+ if (!track.isEnabled) {
1281
+ trackSidsDisabled.push(track.trackSid);
1282
+ }
1274
1283
  });
1275
1284
 
1276
1285
  this.client.sendSyncState(
@@ -1294,6 +1303,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1294
1303
  }),
1295
1304
  publishTracks: getTrackPublicationInfo(localTracks),
1296
1305
  dataChannels: this.dataChannelsInfo(),
1306
+ trackSidsDisabled,
1297
1307
  }),
1298
1308
  );
1299
1309
  }