@opentok/client 2.35.0-alpha.24 → 2.35.0-alpha.25

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.
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @license OpenTok.js 2.35.0 6076fa4b4
2
+ * @license OpenTok.js 2.35.0 a2a77b84b
3
3
  *
4
4
  * Copyright (c) 2010-2026 TokBox, Inc.
5
5
  * Subject to the applicable Software Development Kit (SDK) License Agreement:
6
6
  * https://www.vonage.com/legal/communications-apis/terms-of-use/
7
7
  *
8
- * Date: Mon, 18 May 2026 08:41:01 GMT
8
+ * Date: Tue, 19 May 2026 10:58:40 GMT
9
9
  */
10
10
 
11
11
  (function webpackUniversalModuleDefinition(root, factory) {
@@ -23868,7 +23868,7 @@ function SubscriberFactory(_ref2) {
23868
23868
  }
23869
23869
  (0, _updateTrackOnStream.default)(mediaStream, oldTrack, newTrack);
23870
23870
  };
23871
- const _audioConnector = createAudioConnector(webRTCStreams, {
23871
+ const _audioConnector = createAudioConnector({
23872
23872
  updateTrackOnStream
23873
23873
  });
23874
23874
 
@@ -25007,7 +25007,7 @@ function SubscriberFactory(_ref2) {
25007
25007
  }
25008
25008
  _context8.prev = 2;
25009
25009
  _context8.next = 5;
25010
- return _audioConnector.applyAudioConnectorOnRoutedToRelayedTransition();
25010
+ return _audioConnector.resetAndApplyAudioConnector(_webRTCStream);
25011
25011
  case 5:
25012
25012
  _logPendingSetAudioMediaProcessorConnector('Success', 'Audio connector applied on routed to relayed transition.');
25013
25013
  _context8.next = 11;
@@ -25700,7 +25700,7 @@ function SubscriberFactory(_ref2) {
25700
25700
  }
25701
25701
  _context15.prev = 10;
25702
25702
  _context15.next = 13;
25703
- return _audioConnector.applyAudioConnectorOnRelayedToRoutedTransition();
25703
+ return _audioConnector.setAudioMediaProcessorConnector(_webRTCStream);
25704
25704
  case 13:
25705
25705
  _logPendingSetAudioMediaProcessorConnector('Success', 'Audio connector applied on relayed to routed transition.');
25706
25706
  _context15.next = 19;
@@ -25717,13 +25717,18 @@ function SubscriberFactory(_ref2) {
25717
25717
  _context15.next = 21;
25718
25718
  return bindWebRTCStream(_webRTCStream);
25719
25719
  case 21:
25720
- _context15.next = 23;
25720
+ // Update the active source stream ID immediately to prevent any concurrent code
25721
+ // (e.g. setAudioMediaProcessorConnector) from applying operations to the outgoing
25722
+ // P2P stream after the MANTIS stream has been bound to the video element.
25723
+ _activeSourceStreamId = 'MANTIS';
25724
+ networkConditionChecker.setSourceStreamId(_activeSourceStreamId);
25725
+
25726
+ // remove and close p2p connection
25727
+ _context15.next = 25;
25721
25728
  return removePeerConnectionBySourceStreamId('P2P');
25722
- case 23:
25729
+ case 25:
25723
25730
  // Keep the loading spinner hidden so that the transition looks transparent.
25724
25731
  _widgetView.loading(false);
25725
- _activeSourceStreamId = 'MANTIS';
25726
- networkConditionChecker.setSourceStreamId(_activeSourceStreamId);
25727
25732
 
25728
25733
  // remove webRTCStream
25729
25734
  removeWebRTCStream('P2P');
@@ -26360,7 +26365,7 @@ function SubscriberFactory(_ref2) {
26360
26365
  _setAudioMediaProcessorConnector();
26361
26366
  } else {
26362
26367
  try {
26363
- _audioConnector.resetAudioStreamAndTrack(_activeSourceStreamId);
26368
+ _audioConnector.resetAudioStreamAndTrack();
26364
26369
  } catch (error) {
26365
26370
  logAnalyticsEvent('subscribeToAudio', 'Failure', {
26366
26371
  message: `Error resetting track: ${error.message}`
@@ -27664,19 +27669,18 @@ function SubscriberFactory(_ref2) {
27664
27669
  logAnalyticsEvent('setAudioMediaProcessorConnector', 'Attempt', {
27665
27670
  message: mediaProcessorConnector ? 'setting the connector' : 'clearing the connector'
27666
27671
  });
27667
- _audioConnector == null ? void 0 : _audioConnector.clearAudioMediaProcessorConnector(_activeSourceStreamId);
27672
+ _audioConnector == null ? void 0 : _audioConnector.clearAudioMediaProcessorConnector();
27668
27673
  if (mediaProcessorConnector) {
27669
- _context31.next = 6;
27674
+ _context31.next = 5;
27670
27675
  break;
27671
27676
  }
27672
- _audioConnector == null ? void 0 : _audioConnector.resetAudioStreamAndTrack();
27673
27677
  logAnalyticsEvent('setAudioMediaProcessorConnector', 'Success', {
27674
27678
  message: 'clearing the connector'
27675
27679
  });
27676
27680
  return _context31.abrupt("return");
27677
- case 6:
27681
+ case 5:
27678
27682
  if (_mediaProcessorConnector.default.isValidConnector(mediaProcessorConnector)) {
27679
- _context31.next = 11;
27683
+ _context31.next = 10;
27680
27684
  break;
27681
27685
  }
27682
27686
  message = 'Tried to set invalid MediaProcessorConnector';
@@ -27685,12 +27689,12 @@ function SubscriberFactory(_ref2) {
27685
27689
  message
27686
27690
  });
27687
27691
  throw otError(_Errors.default.INVALID_PARAMETER, new Error(`setAudioVideoMediaProcessorConnector: ${message}`));
27688
- case 11:
27692
+ case 10:
27689
27693
  _audioConnector.initializeConnector(mediaProcessorConnector);
27690
27694
  _pendingSetAudioMediaProcessorConnector = true;
27691
27695
  isTransitioning = amrState.isTransitioning();
27692
27696
  if (!(isTransitioning || !_isSubscribingToAudio)) {
27693
- _context31.next = 17;
27697
+ _context31.next = 16;
27694
27698
  break;
27695
27699
  }
27696
27700
  // After the transition finishes, or when re-subscribing to audio, we will apply the
@@ -27700,10 +27704,10 @@ function SubscriberFactory(_ref2) {
27700
27704
  subscribingToAudio: _isSubscribingToAudio
27701
27705
  });
27702
27706
  return _context31.abrupt("return");
27703
- case 17:
27707
+ case 16:
27704
27708
  _audioConnector.resetAudioStreamAndTrack();
27705
27709
  _setAudioMediaProcessorConnector();
27706
- case 19:
27710
+ case 18:
27707
27711
  case "end":
27708
27712
  return _context31.stop();
27709
27713
  }
@@ -27718,7 +27722,7 @@ function SubscriberFactory(_ref2) {
27718
27722
  return _regenerator.default.wrap(function _callee32$(_context32) {
27719
27723
  while (1) switch (_context32.prev = _context32.next) {
27720
27724
  case 0:
27721
- if (webRTCStreams[_activeSourceStreamId]) {
27725
+ if (_webRTCStream) {
27722
27726
  _context32.next = 2;
27723
27727
  break;
27724
27728
  }
@@ -27726,7 +27730,7 @@ function SubscriberFactory(_ref2) {
27726
27730
  case 2:
27727
27731
  _context32.prev = 2;
27728
27732
  _context32.next = 5;
27729
- return _audioConnector == null ? void 0 : _audioConnector.setAudioMediaProcessorConnector(_activeSourceStreamId);
27733
+ return _audioConnector == null ? void 0 : _audioConnector.setAudioMediaProcessorConnector(_webRTCStream);
27730
27734
  case 5:
27731
27735
  _logPendingSetAudioMediaProcessorConnector('Success');
27732
27736
  _context32.next = 13;
@@ -41693,7 +41697,7 @@ function staticConfigFactory(_temp) {
41693
41697
  _ref$axios = _ref.axios,
41694
41698
  axios = _ref$axios === void 0 ? _axios.default : _ref$axios,
41695
41699
  _ref$properties = _ref.properties,
41696
- properties = _ref$properties === void 0 ? {"version":"v2.35.0","buildHash":"6076fa4b4","minimumVersion":{"firefox":52,"chrome":49},"debug":false,"websiteURL":"http://www.tokbox.com","configURL":"https://config.opentok.com","ipWhitelistConfigURL":"","cdnURL":"","loggingURL":"https://hlg.tokbox.com/prod","apiURL":"https://anvil.opentok.com","vonageApiURL":""} : _ref$properties;
41700
+ properties = _ref$properties === void 0 ? {"version":"v2.35.0","buildHash":"a2a77b84b","minimumVersion":{"firefox":52,"chrome":49},"debug":false,"websiteURL":"http://www.tokbox.com","configURL":"https://config.opentok.com","ipWhitelistConfigURL":"","cdnURL":"","loggingURL":"https://hlg.tokbox.com/prod","apiURL":"https://anvil.opentok.com","vonageApiURL":""} : _ref$properties;
41697
41701
  /** @type builtInConfig */
41698
41702
  const builtInConfig = (0, _cloneDeep.default)(properties);
41699
41703
  /**
@@ -56804,11 +56808,12 @@ module.exports = __webpack_require__(58191)("forEach");
56804
56808
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
56805
56809
 
56806
56810
  "use strict";
56811
+ /* provided dependency */ var Promise = __webpack_require__(86964);
56807
56812
 
56808
56813
 
56809
56814
  var _interopRequireDefault = __webpack_require__(95709);
56810
56815
  exports.__esModule = true;
56811
- exports["default"] = void 0;
56816
+ exports["default"] = exports.TRANSIENT_DECODE_RECOVERY_WINDOW_MS = exports.TRANSIENT_DECODE_RECOVERY_TIMEOUT_MS = exports.TRANSIENT_DECODE_RECOVERY_MAX_ATTEMPTS = void 0;
56812
56817
  var _regenerator = _interopRequireDefault(__webpack_require__(92207));
56813
56818
  var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(79092));
56814
56819
  var _createClass2 = _interopRequireDefault(__webpack_require__(65044));
@@ -56837,6 +56842,12 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
56837
56842
 
56838
56843
  const VIDEO_BUFFER_TIMEOUT = _amrStateDurations.default.VIDEO_BUFFER_TIMEOUT,
56839
56844
  VIDEO_LOADING_TIMEOUT = _amrStateDurations.default.VIDEO_LOADING_TIMEOUT;
56845
+ const TRANSIENT_DECODE_RECOVERY_WINDOW_MS = 3000;
56846
+ exports.TRANSIENT_DECODE_RECOVERY_WINDOW_MS = TRANSIENT_DECODE_RECOVERY_WINDOW_MS;
56847
+ const TRANSIENT_DECODE_RECOVERY_TIMEOUT_MS = 2000;
56848
+ exports.TRANSIENT_DECODE_RECOVERY_TIMEOUT_MS = TRANSIENT_DECODE_RECOVERY_TIMEOUT_MS;
56849
+ const TRANSIENT_DECODE_RECOVERY_MAX_ATTEMPTS = 2;
56850
+ exports.TRANSIENT_DECODE_RECOVERY_MAX_ATTEMPTS = TRANSIENT_DECODE_RECOVERY_MAX_ATTEMPTS;
56840
56851
  const defaultLogging = (0, _log.default)('WidgetView');
56841
56852
 
56842
56853
  // eslint-disable-next-line no-unused-vars
@@ -56916,6 +56927,10 @@ function WidgetViewFactory(_temp) {
56916
56927
  this._showPoster = undefined;
56917
56928
  this._poster = undefined;
56918
56929
  this._cancelBind = undefined;
56930
+ this._decodeRecoveryAttempts = 0;
56931
+ this._decodeRecoveryTimeout = undefined;
56932
+ this._decodeRecoveryUntil = 0;
56933
+ this._decodeRecoveryToken = 0;
56919
56934
  (0, _eventing.default)(this);
56920
56935
  if (/^(contain|cover)$/.test(fitMode) === false) {
56921
56936
  logging.warn(`Invalid fit value "${fitMode}" passed. Only "contain" and "cover" can be used.`);
@@ -57065,11 +57080,13 @@ function WidgetViewFactory(_temp) {
57065
57080
  };
57066
57081
  _proto.rebindSrcObject = function rebindSrcObject() {
57067
57082
  if (this._videoElementFacade) {
57083
+ this._markDecodeRecoveryTransitionWindow();
57068
57084
  this._videoElementFacade._rebindSrcObject();
57069
57085
  }
57070
57086
  };
57071
57087
  _proto.pauseAndPlayVideoElement = function pauseAndPlayVideoElement() {
57072
57088
  if (this._videoElementFacade) {
57089
+ this._markDecodeRecoveryTransitionWindow();
57073
57090
  this._videoElementFacade._pauseAndPlay();
57074
57091
  }
57075
57092
  }
@@ -57144,6 +57161,77 @@ function WidgetViewFactory(_temp) {
57144
57161
  _proto._emitBindEvent = function _emitBindEvent(action, variation, options) {
57145
57162
  this.emit('bindEvent', action, variation, options);
57146
57163
  };
57164
+ _proto._clearDecodeRecoveryTimeout = function _clearDecodeRecoveryTimeout() {
57165
+ if (this._decodeRecoveryTimeout) {
57166
+ clearTimeout(this._decodeRecoveryTimeout);
57167
+ this._decodeRecoveryTimeout = undefined;
57168
+ }
57169
+ };
57170
+ _proto._markDecodeRecoveryTransitionWindow = function _markDecodeRecoveryTransitionWindow() {
57171
+ if (!env.isAndroidWebView) {
57172
+ return;
57173
+ }
57174
+ if (Date.now() > this._decodeRecoveryUntil) {
57175
+ this._decodeRecoveryAttempts = 0;
57176
+ }
57177
+ this._decodeRecoveryUntil = Date.now() + TRANSIENT_DECODE_RECOVERY_WINDOW_MS;
57178
+ };
57179
+ _proto._resetDecodeRecoveryState = function _resetDecodeRecoveryState() {
57180
+ this._clearDecodeRecoveryTimeout();
57181
+ this._decodeRecoveryAttempts = 0;
57182
+ this._decodeRecoveryToken += 1;
57183
+ };
57184
+ _proto._isTransientDecodeError = function _isTransientDecodeError(rawError, mappedError) {
57185
+ const isMappedDecodeError = (mappedError == null ? void 0 : mappedError.name) === 'OT_MEDIA_ERR_DECODE';
57186
+ const isRawDecodeError = !!((typeof window !== undefined ? window : global).MediaError && rawError && rawError.target && rawError.target.error && rawError.target.error.code === (typeof window !== undefined ? window : global).MediaError.MEDIA_ERR_DECODE);
57187
+ return isMappedDecodeError || isRawDecodeError;
57188
+ };
57189
+ _proto._attemptDecodeRecovery = function _attemptDecodeRecovery(rawError, mappedError) {
57190
+ if (!env.isAndroidWebView) {
57191
+ return false;
57192
+ }
57193
+ if (!this._isTransientDecodeError(rawError, mappedError)) {
57194
+ return false;
57195
+ }
57196
+ if (Date.now() > this._decodeRecoveryUntil) {
57197
+ this._resetDecodeRecoveryState();
57198
+ return false;
57199
+ }
57200
+ if (this._decodeRecoveryAttempts >= TRANSIENT_DECODE_RECOVERY_MAX_ATTEMPTS) {
57201
+ return false;
57202
+ }
57203
+ this._decodeRecoveryAttempts += 1;
57204
+ const decodeRecoveryToken = ++this._decodeRecoveryToken;
57205
+ const decodeRecoveryUntil = this._decodeRecoveryUntil;
57206
+ this._clearDecodeRecoveryTimeout();
57207
+ this._markDecodeRecoveryTransitionWindow();
57208
+ this._decodeRecoveryUntil = decodeRecoveryUntil;
57209
+ try {
57210
+ this.rebindSrcObject();
57211
+ this.pauseAndPlayVideoElement();
57212
+ } catch (err) {
57213
+ logging.debug('decode recovery failed to trigger rebind/pause+play:', err);
57214
+ } finally {
57215
+ this._decodeRecoveryUntil = decodeRecoveryUntil;
57216
+ }
57217
+ const recoveryPlay = this._videoElementFacade && this._videoElementFacade.play ? this._videoElementFacade.play() : Promise.resolve();
57218
+ Promise.resolve(recoveryPlay).then(() => {
57219
+ if (this._decodeRecoveryToken !== decodeRecoveryToken) {
57220
+ return;
57221
+ }
57222
+ this._resetDecodeRecoveryState();
57223
+ }).catch(err => {
57224
+ logging.debug('decode recovery play failed:', err);
57225
+ });
57226
+ this._decodeRecoveryTimeout = setTimeout(() => {
57227
+ if (this._decodeRecoveryToken !== decodeRecoveryToken) {
57228
+ return;
57229
+ }
57230
+ this._decodeRecoveryTimeout = undefined;
57231
+ this.trigger('error', mappedError);
57232
+ }, TRANSIENT_DECODE_RECOVERY_TIMEOUT_MS);
57233
+ return true;
57234
+ };
57147
57235
  _proto._createVideoElementFacade = function _createVideoElementFacade(_ref3) {
57148
57236
  let _inject = _ref3._inject,
57149
57237
  audioVolume = _ref3.audioVolume,
@@ -57159,8 +57247,23 @@ function WidgetViewFactory(_temp) {
57159
57247
  });
57160
57248
  const videoFacadeEvents = (0, _eventHelper.default)(this._videoElementFacade);
57161
57249
  this._videoFacadeEvents = videoFacadeEvents;
57162
- videoFacadeEvents.on('error', () => {
57163
- this.trigger('error');
57250
+ videoFacadeEvents.on('error', (rawError, mappedError) => {
57251
+ if (this._attemptDecodeRecovery(rawError, mappedError)) {
57252
+ return;
57253
+ }
57254
+ this.trigger('error', mappedError);
57255
+ });
57256
+ // We now want to log binding duration to monitor the blink: OPENTOK-46931
57257
+ // We propagate the event from videoFacade level to Subscriber
57258
+ videoFacadeEvents.on('bindEvent', (action, variation, options) => {
57259
+ if (action === 'transitionVideo') {
57260
+ if (variation === 'Attempt') {
57261
+ this._markDecodeRecoveryTransitionWindow();
57262
+ } else if (variation === 'Success') {
57263
+ this._resetDecodeRecoveryState();
57264
+ }
57265
+ }
57266
+ this._emitBindEvent(action, variation, options);
57164
57267
  });
57165
57268
  videoFacadeEvents.on('videoDimensionsChanged', (oldValue, newValue) => {
57166
57269
  this.trigger('videoDimensionsChanged', oldValue, newValue);
@@ -57320,12 +57423,7 @@ function WidgetViewFactory(_temp) {
57320
57423
  return _context4.abrupt("return");
57321
57424
  case 20:
57322
57425
  this._emitBindEvent('loadVideoBuffer', 'Success');
57323
- // We now want to log binding duration to monitor the blink: OPENTOK-46931
57324
- // We propagate the event from videoFacade level to Subscriber
57325
- this._videoFacadeEvents.on('bindEvent', (action, variation, options) => {
57326
- this._emitBindEvent(action, variation, options);
57327
- });
57328
- case 22:
57426
+ case 21:
57329
57427
  case "end":
57330
57428
  return _context4.stop();
57331
57429
  }
@@ -57364,6 +57462,7 @@ function WidgetViewFactory(_temp) {
57364
57462
  logging.debug('bindVideo ', {
57365
57463
  webRTCStream
57366
57464
  });
57465
+ this._markDecodeRecoveryTransitionWindow();
57367
57466
  hasExistingElement = !!this._videoElementFacade;
57368
57467
  cancellation = this._getNewBindCancellation();
57369
57468
  if (!hasExistingElement) {
@@ -57375,15 +57474,15 @@ function WidgetViewFactory(_temp) {
57375
57474
  });
57376
57475
  }
57377
57476
  if (!(webRTCStream instanceof MediaStream && hasVideo && isSubscribingToVideo)) {
57378
- _context5.next = 9;
57477
+ _context5.next = 10;
57379
57478
  break;
57380
57479
  }
57381
- _context5.next = 9;
57480
+ _context5.next = 10;
57382
57481
  return this._tryToLoadVideoBuffer(webRTCStream, cancellation, throwIfBufferFails, hasVideo && isSubscribingToVideo);
57383
- case 9:
57384
- _context5.next = 11;
57482
+ case 10:
57483
+ _context5.next = 12;
57385
57484
  return this._bindToStream(webRTCStream, cancellation);
57386
- case 11:
57485
+ case 12:
57387
57486
  if (!hasExistingElement) {
57388
57487
  this._triggerVideoElementCreated();
57389
57488
  }
@@ -57392,16 +57491,16 @@ function WidgetViewFactory(_temp) {
57392
57491
  defaultVideoElementFacade: this._videoElementFacade,
57393
57492
  maxWaitTime: 5000
57394
57493
  });
57395
- _context5.next = 16;
57494
+ _context5.next = 17;
57396
57495
  return this._waitForVideoResolution(webRTCStream);
57397
- case 16:
57496
+ case 17:
57398
57497
  logging.debug('Waiting for video to be playing');
57399
- _context5.next = 19;
57498
+ _context5.next = 20;
57400
57499
  return whenVideoPlaying;
57401
- case 19:
57500
+ case 20:
57402
57501
  logging.debug('Video is playing');
57403
57502
  throwIfBindCancelled(cancellation);
57404
- case 21:
57503
+ case 22:
57405
57504
  case "end":
57406
57505
  return _context5.stop();
57407
57506
  }
@@ -57418,6 +57517,7 @@ function WidgetViewFactory(_temp) {
57418
57517
  }
57419
57518
  };
57420
57519
  _proto.destroyVideo = function destroyVideo() {
57520
+ this._resetDecodeRecoveryState();
57421
57521
  if (this._videoElementFacade) {
57422
57522
  this._videoElementFacade.destroy();
57423
57523
  this._videoElementFacade = null;
@@ -62331,7 +62431,7 @@ function NativeVideoElementWrapperFactory(deps) {
62331
62431
  }, _callee);
62332
62432
  })));
62333
62433
  const onError = event => {
62334
- this.trigger('error', videoElementErrorMap(event.target.error));
62434
+ this.trigger('error', event, videoElementErrorMap(event.target.error));
62335
62435
  };
62336
62436
  this._domElementEvents.on('error', onError, false);
62337
62437
  this._domElementEvents.on('pause', _playVideoOnPause);
@@ -103595,36 +103695,37 @@ var _log = _interopRequireDefault(__webpack_require__(48669));
103595
103695
  var _updateTrackOnStream = _interopRequireDefault(__webpack_require__(29634));
103596
103696
  var _createAudioTrackHolder = _interopRequireDefault(__webpack_require__(37268));
103597
103697
  const logging = (0, _log.default)('Subscriber');
103598
- const routedSourceStreamId = 'MANTIS';
103599
- const relayedSourceStreamId = 'P2P';
103600
- const createAudioConnector = function createAudioConnector(streams, deps) {
103698
+ const createAudioConnector = function createAudioConnector(deps) {
103601
103699
  if (deps === void 0) {
103602
103700
  deps = {};
103603
103701
  }
103604
103702
  const updateTrackOnStream = deps.updateTrackOnStream || _updateTrackOnStream.default;
103605
103703
  const createAudioTrackHolder = deps.createAudioTrackHolder || _createAudioTrackHolder.default;
103606
- const mediaStreams = streams;
103607
103704
  let _audioMediaProcessorConnector;
103705
+ let _stream;
103608
103706
  let _originalAudioTrack;
103609
103707
  let _audioTrackHolder;
103610
- const clearConnectorAndAudioHolder = () => {
103611
- var _audioMediaProcessorC;
103612
- (_audioMediaProcessorC = _audioMediaProcessorConnector) == null ? void 0 : _audioMediaProcessorC.destroy();
103613
- _audioMediaProcessorConnector = null;
103708
+ const clearAudioHolder = () => {
103614
103709
  if (_audioTrackHolder) {
103615
103710
  _audioTrackHolder.srcObject = null;
103616
103711
  _audioTrackHolder = null;
103617
103712
  }
103713
+ _stream = null;
103618
103714
  _originalAudioTrack = null;
103619
103715
  };
103716
+ const clearConnectorAndAudioHolder = () => {
103717
+ var _audioMediaProcessorC;
103718
+ (_audioMediaProcessorC = _audioMediaProcessorConnector) == null ? void 0 : _audioMediaProcessorC.destroy();
103719
+ _audioMediaProcessorConnector = null;
103720
+ clearAudioHolder();
103721
+ };
103620
103722
  const applyAudioConnector = /*#__PURE__*/function () {
103621
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(sourceStreamId) {
103622
- var _mediaStreams$sourceS2;
103623
- var _mediaStreams$sourceS, originalAudioTrack, message, error, filteredAudioTrack;
103723
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(stream) {
103724
+ var originalAudioTrack, message, error, filteredAudioTrack;
103624
103725
  return _regenerator.default.wrap(function _callee$(_context) {
103625
103726
  while (1) switch (_context.prev = _context.next) {
103626
103727
  case 0:
103627
- _mediaStreams$sourceS = (_mediaStreams$sourceS2 = mediaStreams[sourceStreamId]) == null ? void 0 : _mediaStreams$sourceS2.getAudioTracks(), originalAudioTrack = _mediaStreams$sourceS[0];
103728
+ originalAudioTrack = stream === _stream ? _originalAudioTrack : stream == null ? void 0 : stream.getAudioTracks()[0];
103628
103729
  if (originalAudioTrack) {
103629
103730
  _context.next = 7;
103630
103731
  break;
@@ -103632,42 +103733,59 @@ const createAudioConnector = function createAudioConnector(streams, deps) {
103632
103733
  message = 'Connector not set as no audio track is present.';
103633
103734
  error = new Error(message);
103634
103735
  logging.error(`setAudioMediaProcessorConnector: ${message}`);
103635
- _audioMediaProcessorConnector = null;
103736
+ clearConnectorAndAudioHolder();
103636
103737
  throw error;
103637
103738
  case 7:
103638
103739
  _context.prev = 7;
103639
103740
  // We create a video element to hold a new stream containing the original audio track.
103640
103741
  // If the track is not used in a stream, it is stopped and no audio is heard through
103641
103742
  // the filtered track.
103743
+ if (_audioTrackHolder) {
103744
+ _audioTrackHolder.srcObject = null;
103745
+ }
103642
103746
  _audioTrackHolder = createAudioTrackHolder(originalAudioTrack);
103643
- _context.next = 11;
103747
+ if (_audioMediaProcessorConnector) {
103748
+ _context.next = 15;
103749
+ break;
103750
+ }
103751
+ message = 'Audio Media Processor Connector has not been initialized.';
103752
+ error = new Error(message);
103753
+ logging.error(`setAudioMediaProcessorConnector: ${message}`);
103754
+ throw error;
103755
+ case 15:
103756
+ _context.next = 17;
103644
103757
  return _audioMediaProcessorConnector.setTrack(originalAudioTrack);
103645
- case 11:
103758
+ case 17:
103646
103759
  filteredAudioTrack = _context.sent;
103760
+ _stream = stream;
103647
103761
  _originalAudioTrack = originalAudioTrack;
103648
- updateTrackOnStream(mediaStreams[sourceStreamId], originalAudioTrack, filteredAudioTrack);
103649
- _context.next = 20;
103762
+ updateTrackOnStream(stream, originalAudioTrack, filteredAudioTrack);
103763
+ _context.next = 27;
103650
103764
  break;
103651
- case 16:
103652
- _context.prev = 16;
103765
+ case 23:
103766
+ _context.prev = 23;
103653
103767
  _context.t0 = _context["catch"](7);
103654
103768
  clearConnectorAndAudioHolder();
103655
103769
  throw _context.t0;
103656
- case 20:
103770
+ case 27:
103657
103771
  case "end":
103658
103772
  return _context.stop();
103659
103773
  }
103660
- }, _callee, null, [[7, 16]]);
103774
+ }, _callee, null, [[7, 23]]);
103661
103775
  }));
103662
103776
  return function applyAudioConnector(_x) {
103663
103777
  return _ref.apply(this, arguments);
103664
103778
  };
103665
103779
  }();
103666
- const resetAudioStream = sourceStreamId => {
103780
+ const resetAudioStream = () => {
103667
103781
  try {
103668
- const _mediaStreams$sourceS3 = mediaStreams[sourceStreamId].getAudioTracks(),
103669
- filteredAudioTrack = _mediaStreams$sourceS3[0];
103670
- updateTrackOnStream(mediaStreams[sourceStreamId], filteredAudioTrack, _originalAudioTrack);
103782
+ var _stream2;
103783
+ const audioTracks = (_stream2 = _stream) == null ? void 0 : _stream2.getAudioTracks();
103784
+ if (audioTracks != null && audioTracks.length) {
103785
+ const filteredAudioTrack = audioTracks[0];
103786
+ updateTrackOnStream(_stream, filteredAudioTrack, _originalAudioTrack);
103787
+ }
103788
+ clearAudioHolder();
103671
103789
  } catch (error) {
103672
103790
  throw Error(`setAudioMediaProcessorConnector: Error resetting track: ${error.message}`);
103673
103791
  }
@@ -103677,15 +103795,17 @@ const createAudioConnector = function createAudioConnector(streams, deps) {
103677
103795
  return _audioMediaProcessorConnector;
103678
103796
  },
103679
103797
  initializeConnector(mediaProcessorConnector) {
103798
+ var _audioMediaProcessorC2;
103799
+ (_audioMediaProcessorC2 = _audioMediaProcessorConnector) == null ? void 0 : _audioMediaProcessorC2.destroy();
103680
103800
  _audioMediaProcessorConnector = new _mediaProcessorConnector.default(mediaProcessorConnector);
103681
103801
  },
103682
- setAudioMediaProcessorConnector(sourceStreamId) {
103802
+ setAudioMediaProcessorConnector(stream) {
103683
103803
  return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
103684
103804
  return _regenerator.default.wrap(function _callee2$(_context2) {
103685
103805
  while (1) switch (_context2.prev = _context2.next) {
103686
103806
  case 0:
103687
103807
  _context2.next = 2;
103688
- return applyAudioConnector(sourceStreamId);
103808
+ return applyAudioConnector(stream);
103689
103809
  case 2:
103690
103810
  case "end":
103691
103811
  return _context2.stop();
@@ -103693,63 +103813,39 @@ const createAudioConnector = function createAudioConnector(streams, deps) {
103693
103813
  }, _callee2);
103694
103814
  }))();
103695
103815
  },
103696
- applyAudioConnectorOnRoutedToRelayedTransition() {
103816
+ resetAndApplyAudioConnector(stream) {
103697
103817
  var _this = this;
103698
103818
  return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
103819
+ var hadAudioMediaProcessorConnector;
103699
103820
  return _regenerator.default.wrap(function _callee3$(_context3) {
103700
103821
  while (1) switch (_context3.prev = _context3.next) {
103701
103822
  case 0:
103702
- // We restore the Mantis stream's original track, so when we transition again,
103703
- // we can apply a filter to the unfiltered track.
103704
- _this.resetAudioStreamAndTrack(routedSourceStreamId);
103705
- if (_audioMediaProcessorConnector) {
103706
- _context3.next = 3;
103823
+ hadAudioMediaProcessorConnector = !!_audioMediaProcessorConnector;
103824
+ _this.resetAudioStreamAndTrack();
103825
+ if (hadAudioMediaProcessorConnector) {
103826
+ _context3.next = 4;
103707
103827
  break;
103708
103828
  }
103709
103829
  return _context3.abrupt("return");
103710
- case 3:
103711
- _context3.next = 5;
103712
- return applyAudioConnector(relayedSourceStreamId);
103713
- case 5:
103830
+ case 4:
103831
+ _context3.next = 6;
103832
+ return applyAudioConnector(stream);
103833
+ case 6:
103714
103834
  case "end":
103715
103835
  return _context3.stop();
103716
103836
  }
103717
103837
  }, _callee3);
103718
103838
  }))();
103719
103839
  },
103720
- applyAudioConnectorOnRelayedToRoutedTransition() {
103721
- return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
103722
- return _regenerator.default.wrap(function _callee4$(_context4) {
103723
- while (1) switch (_context4.prev = _context4.next) {
103724
- case 0:
103725
- if (_audioMediaProcessorConnector) {
103726
- _context4.next = 2;
103727
- break;
103728
- }
103729
- return _context4.abrupt("return");
103730
- case 2:
103731
- _context4.next = 4;
103732
- return applyAudioConnector(routedSourceStreamId);
103733
- case 4:
103734
- case "end":
103735
- return _context4.stop();
103736
- }
103737
- }, _callee4);
103738
- }))();
103739
- },
103740
- clearAudioMediaProcessorConnector(sourceStreamId) {
103741
- if (!_originalAudioTrack) {
103742
- return;
103743
- }
103744
- resetAudioStream(sourceStreamId);
103840
+ clearAudioMediaProcessorConnector() {
103841
+ this.resetAudioStreamAndTrack();
103745
103842
  clearConnectorAndAudioHolder();
103746
103843
  },
103747
- resetAudioStreamAndTrack(sourceStreamId) {
103844
+ resetAudioStreamAndTrack() {
103748
103845
  if (!_originalAudioTrack) {
103749
103846
  return;
103750
103847
  }
103751
- resetAudioStream(sourceStreamId);
103752
- _originalAudioTrack = null;
103848
+ resetAudioStream();
103753
103849
  }
103754
103850
  };
103755
103851
  };