@stream-io/video-client 0.0.41 → 0.0.43

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.
package/dist/index.cjs.js CHANGED
@@ -6076,6 +6076,14 @@ class Publisher {
6076
6076
  [TrackType.SCREEN_SHARE_AUDIO]: undefined,
6077
6077
  [TrackType.UNSPECIFIED]: undefined,
6078
6078
  };
6079
+ /**
6080
+ * An array maintaining the order how transceivers were added to the peer connection.
6081
+ * This is needed because some browsers (Firefox) don't reliably report
6082
+ * trackId and `mid` parameters.
6083
+ *
6084
+ * @private
6085
+ */
6086
+ this.transceiverInitOrder = [];
6079
6087
  this.trackKindMapping = {
6080
6088
  [TrackType.AUDIO]: 'audio',
6081
6089
  [TrackType.VIDEO]: 'video',
@@ -6169,6 +6177,8 @@ class Publisher {
6169
6177
  : undefined,
6170
6178
  sendEncodings: videoEncodings,
6171
6179
  });
6180
+ this.logger('debug', `Added ${TrackType[trackType]} transceiver`);
6181
+ this.transceiverInitOrder.push(trackType);
6172
6182
  this.transceiverRegistry[trackType] = transceiver;
6173
6183
  if ('setCodecPreferences' in transceiver && codecPreferences) {
6174
6184
  this.logger('info', `Setting ${TrackType[trackType]} codec preferences`, codecPreferences);
@@ -6328,6 +6338,13 @@ class Publisher {
6328
6338
  yield this.negotiate({ iceRestart: true });
6329
6339
  }
6330
6340
  });
6341
+ /**
6342
+ * Restarts the ICE connection and renegotiates with the SFU.
6343
+ */
6344
+ this.restartIce = () => {
6345
+ this.logger('debug', 'Restarting ICE connection');
6346
+ this.pc.restartIce();
6347
+ };
6331
6348
  this.onNegotiationNeeded = () => __awaiter(this, void 0, void 0, function* () {
6332
6349
  yield this.negotiate();
6333
6350
  });
@@ -6391,14 +6408,14 @@ class Publisher {
6391
6408
  this.getCurrentTrackInfos = (sdp) => {
6392
6409
  var _a;
6393
6410
  sdp = sdp || ((_a = this.pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp);
6394
- const extractMid = (defaultMid, track) => {
6411
+ const extractMid = (defaultMid, track, trackType) => {
6395
6412
  if (defaultMid)
6396
6413
  return defaultMid;
6397
6414
  if (!sdp) {
6398
6415
  this.logger('warn', 'No SDP found. Returning empty mid');
6399
6416
  return '';
6400
6417
  }
6401
- this.logger('warn', 'No mid found for track. Trying to find it from SDP');
6418
+ this.logger('debug', `No 'mid' found for track. Trying to find it from the Offer SDP`);
6402
6419
  const parsedSdp = SDP__namespace.parse(sdp);
6403
6420
  const media = parsedSdp.media.find((m) => {
6404
6421
  var _a, _b;
@@ -6407,7 +6424,12 @@ class Publisher {
6407
6424
  ((_b = (_a = m.msid) === null || _a === void 0 ? void 0 : _a.includes(track.id)) !== null && _b !== void 0 ? _b : true));
6408
6425
  });
6409
6426
  if (typeof (media === null || media === void 0 ? void 0 : media.mid) === 'undefined') {
6410
- this.logger('warn', `No mid found in SDP for track type ${track.kind} and id ${track.id}`);
6427
+ this.logger('debug', `No mid found in SDP for track type ${track.kind} and id ${track.id}. Attempting to find a heuristic mid`);
6428
+ const heuristicMid = this.transceiverInitOrder.indexOf(trackType);
6429
+ if (heuristicMid !== -1) {
6430
+ return String(heuristicMid);
6431
+ }
6432
+ this.logger('debug', 'No heuristic mid found. Returning empty mid');
6411
6433
  return '';
6412
6434
  }
6413
6435
  return String(media.mid);
@@ -6449,7 +6471,7 @@ class Publisher {
6449
6471
  trackId: track.id,
6450
6472
  layers: layers,
6451
6473
  trackType,
6452
- mid: extractMid(transceiver.mid, track),
6474
+ mid: extractMid(transceiver.mid, track, trackType),
6453
6475
  // FIXME OL: adjust these values
6454
6476
  stereo: false,
6455
6477
  dtx: TrackType.AUDIO === trackType && this.isDtxEnabled,
@@ -6463,7 +6485,12 @@ class Publisher {
6463
6485
  this.logger('error', `ICE Candidate error`, errorMessage);
6464
6486
  };
6465
6487
  this.onIceConnectionStateChange = () => {
6466
- this.logger('debug', `ICE Connection state changed`, this.pc.iceConnectionState);
6488
+ const state = this.pc.iceConnectionState;
6489
+ this.logger('debug', `ICE Connection state changed`, state);
6490
+ if (state === 'failed' || state === 'disconnected') {
6491
+ this.logger('warn', `ICE Connection state changed to ${state}. Attempting to restart ICE`);
6492
+ this.restartIce();
6493
+ }
6467
6494
  };
6468
6495
  this.onIceGatheringStateChange = () => {
6469
6496
  this.logger('debug', `ICE Gathering State`, this.pc.iceGatheringState);
@@ -6590,6 +6617,13 @@ class Subscriber {
6590
6617
  // replace the PeerConnection instance
6591
6618
  this.pc = pc;
6592
6619
  };
6620
+ /**
6621
+ * Restarts the ICE connection and renegotiates with the SFU.
6622
+ */
6623
+ this.restartIce = () => {
6624
+ logger$1('debug', 'Restarting ICE connection');
6625
+ this.pc.restartIce();
6626
+ };
6593
6627
  this.handleOnTrack = (e) => {
6594
6628
  const [primaryStream] = e.streams;
6595
6629
  // example: `e3f6aaf8-b03d-4911-be36-83f47d37a76a:TRACK_TYPE_VIDEO`
@@ -11777,7 +11811,7 @@ class StreamClient {
11777
11811
  };
11778
11812
  this.getUserAgent = () => {
11779
11813
  return (this.userAgent ||
11780
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.40"}`);
11814
+ `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.42"}`);
11781
11815
  };
11782
11816
  this.setUserAgent = (userAgent) => {
11783
11817
  this.userAgent = userAgent;