@opentok/client 2.35.0-alpha.23 → 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 b3cd7abe5
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: Wed, 13 May 2026 13:03:31 GMT
8
+ * Date: Tue, 19 May 2026 10:58:40 GMT
9
9
  */
10
10
 
11
11
  (function webpackUniversalModuleDefinition(root, factory) {
@@ -4628,43 +4628,58 @@ const _deviceHelpers = (0, _deviceHelpers2.default)(),
4628
4628
 
4629
4629
  /**
4630
4630
  * Enumerates the audio input devices (such as microphones) and video input devices
4631
- * (cameras) available to the browser.
4631
+ * (cameras) available to the browser. This returns a promise containing the array of
4632
+ * devices. Each object has three properties: <code>kind</code>,
4633
+ * <code>deviceId</code>, and <code>label</code>, each of which are strings.
4632
4634
  * <p>
4633
- * The array of devices is passed in as the <code>devices</code> parameter of
4634
- * the <code>callback</code> function passed into the method.
4635
+ * The <code>kind</code> property is set to <code>"audioInput"</code> for audio input
4636
+ * devices or <code>"videoInput"</code> for video input devices.
4637
+ * <p>
4638
+ * The <code>deviceId</code> property is a unique ID for the device. You can pass
4639
+ * the <code>deviceId</code> in as the <code>audioSource</code> or <code>videoSource</code>
4640
+ * property of the <code>options</code> parameter of the
4641
+ * <a href="#initPublisher">OT.initPublisher()</a> method.
4642
+ * <p>
4643
+ * The <code>label</code> property identifies the device. The <code>label</code>
4644
+ * property is set to an empty string if the user has not previously granted access to
4645
+ * a camera and microphone.
4635
4646
  *
4636
- * @param callback {Function} The callback function invoked when the list of devices
4647
+ * @param callback {Function} Optional callback function invoked when the list of devices
4637
4648
  * devices is available. This function takes two parameters:
4638
4649
  * <ul>
4639
4650
  * <li><code>error</code> &mdash; This is set to an error object when
4640
4651
  * there is an error in calling this method; it is set to <code>null</code>
4641
4652
  * when the call succeeds.</li>
4642
- *
4643
4653
  * <li><p><code>devices</code> &mdash; An array of objects corresponding to
4644
- * available microphones and cameras. Each object has three properties: <code>kind</code>,
4645
- * <code>deviceId</code>, and <code>label</code>, each of which are strings.
4646
- * <p>
4647
- * The <code>kind</code> property is set to <code>"audioInput"</code> for audio input
4648
- * devices or <code>"videoInput"</code> for video input devices.
4649
- * <p>
4650
- * The <code>deviceId</code> property is a unique ID for the device. You can pass
4651
- * the <code>deviceId</code> in as the <code>audioSource</code> or <code>videoSource</code>
4652
- * property of the <code>options</code> parameter of the
4653
- * <a href="#initPublisher">OT.initPublisher()</a> method.
4654
- * <p>
4655
- * The <code>label</code> property identifies the device. The <code>label</code>
4656
- * property is set to an empty string if the user has not previously granted access to
4657
- * a camera and microphone.</li>
4654
+ * available microphones and cameras.
4655
+ * </li>
4658
4656
  * </ul>
4659
4657
  * <i>Note:</i> The browser may limit the number of returned audio and video input devices
4660
4658
  * to one each before the user has granted access to a camera or microphone.
4661
4659
  *
4660
+ * @returns {Promise<Device[]>} A promise containing the list of devices
4661
+ *
4662
4662
  * @see <a href="#initPublisher">OT.initPublisher()</a>
4663
4663
  * @method OT.getDevices
4664
4664
  * @memberof OT
4665
4665
  */
4666
4666
  function getDevices(callback) {
4667
- getInputMediaDevices().then(devices => callback(undefined, devices), callback);
4667
+ const hasCallback = typeof callback === 'function';
4668
+ const promise = getInputMediaDevices().then(devices => {
4669
+ if (hasCallback) {
4670
+ callback(undefined, devices);
4671
+ }
4672
+ return devices;
4673
+ }, err => {
4674
+ if (hasCallback) {
4675
+ callback(err);
4676
+ }
4677
+ throw err;
4678
+ });
4679
+ if (hasCallback) {
4680
+ promise.catch(() => {});
4681
+ }
4682
+ return promise;
4668
4683
  }
4669
4684
 
4670
4685
  /***/ }),
@@ -23853,7 +23868,7 @@ function SubscriberFactory(_ref2) {
23853
23868
  }
23854
23869
  (0, _updateTrackOnStream.default)(mediaStream, oldTrack, newTrack);
23855
23870
  };
23856
- const _audioConnector = createAudioConnector(webRTCStreams, {
23871
+ const _audioConnector = createAudioConnector({
23857
23872
  updateTrackOnStream
23858
23873
  });
23859
23874
 
@@ -24992,7 +25007,7 @@ function SubscriberFactory(_ref2) {
24992
25007
  }
24993
25008
  _context8.prev = 2;
24994
25009
  _context8.next = 5;
24995
- return _audioConnector.applyAudioConnectorOnRoutedToRelayedTransition();
25010
+ return _audioConnector.resetAndApplyAudioConnector(_webRTCStream);
24996
25011
  case 5:
24997
25012
  _logPendingSetAudioMediaProcessorConnector('Success', 'Audio connector applied on routed to relayed transition.');
24998
25013
  _context8.next = 11;
@@ -25685,7 +25700,7 @@ function SubscriberFactory(_ref2) {
25685
25700
  }
25686
25701
  _context15.prev = 10;
25687
25702
  _context15.next = 13;
25688
- return _audioConnector.applyAudioConnectorOnRelayedToRoutedTransition();
25703
+ return _audioConnector.setAudioMediaProcessorConnector(_webRTCStream);
25689
25704
  case 13:
25690
25705
  _logPendingSetAudioMediaProcessorConnector('Success', 'Audio connector applied on relayed to routed transition.');
25691
25706
  _context15.next = 19;
@@ -25702,13 +25717,18 @@ function SubscriberFactory(_ref2) {
25702
25717
  _context15.next = 21;
25703
25718
  return bindWebRTCStream(_webRTCStream);
25704
25719
  case 21:
25705
- _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;
25706
25728
  return removePeerConnectionBySourceStreamId('P2P');
25707
- case 23:
25729
+ case 25:
25708
25730
  // Keep the loading spinner hidden so that the transition looks transparent.
25709
25731
  _widgetView.loading(false);
25710
- _activeSourceStreamId = 'MANTIS';
25711
- networkConditionChecker.setSourceStreamId(_activeSourceStreamId);
25712
25732
 
25713
25733
  // remove webRTCStream
25714
25734
  removeWebRTCStream('P2P');
@@ -26345,7 +26365,7 @@ function SubscriberFactory(_ref2) {
26345
26365
  _setAudioMediaProcessorConnector();
26346
26366
  } else {
26347
26367
  try {
26348
- _audioConnector.resetAudioStreamAndTrack(_activeSourceStreamId);
26368
+ _audioConnector.resetAudioStreamAndTrack();
26349
26369
  } catch (error) {
26350
26370
  logAnalyticsEvent('subscribeToAudio', 'Failure', {
26351
26371
  message: `Error resetting track: ${error.message}`
@@ -27649,19 +27669,18 @@ function SubscriberFactory(_ref2) {
27649
27669
  logAnalyticsEvent('setAudioMediaProcessorConnector', 'Attempt', {
27650
27670
  message: mediaProcessorConnector ? 'setting the connector' : 'clearing the connector'
27651
27671
  });
27652
- _audioConnector == null ? void 0 : _audioConnector.clearAudioMediaProcessorConnector(_activeSourceStreamId);
27672
+ _audioConnector == null ? void 0 : _audioConnector.clearAudioMediaProcessorConnector();
27653
27673
  if (mediaProcessorConnector) {
27654
- _context31.next = 6;
27674
+ _context31.next = 5;
27655
27675
  break;
27656
27676
  }
27657
- _audioConnector == null ? void 0 : _audioConnector.resetAudioStreamAndTrack();
27658
27677
  logAnalyticsEvent('setAudioMediaProcessorConnector', 'Success', {
27659
27678
  message: 'clearing the connector'
27660
27679
  });
27661
27680
  return _context31.abrupt("return");
27662
- case 6:
27681
+ case 5:
27663
27682
  if (_mediaProcessorConnector.default.isValidConnector(mediaProcessorConnector)) {
27664
- _context31.next = 11;
27683
+ _context31.next = 10;
27665
27684
  break;
27666
27685
  }
27667
27686
  message = 'Tried to set invalid MediaProcessorConnector';
@@ -27670,12 +27689,12 @@ function SubscriberFactory(_ref2) {
27670
27689
  message
27671
27690
  });
27672
27691
  throw otError(_Errors.default.INVALID_PARAMETER, new Error(`setAudioVideoMediaProcessorConnector: ${message}`));
27673
- case 11:
27692
+ case 10:
27674
27693
  _audioConnector.initializeConnector(mediaProcessorConnector);
27675
27694
  _pendingSetAudioMediaProcessorConnector = true;
27676
27695
  isTransitioning = amrState.isTransitioning();
27677
27696
  if (!(isTransitioning || !_isSubscribingToAudio)) {
27678
- _context31.next = 17;
27697
+ _context31.next = 16;
27679
27698
  break;
27680
27699
  }
27681
27700
  // After the transition finishes, or when re-subscribing to audio, we will apply the
@@ -27685,10 +27704,10 @@ function SubscriberFactory(_ref2) {
27685
27704
  subscribingToAudio: _isSubscribingToAudio
27686
27705
  });
27687
27706
  return _context31.abrupt("return");
27688
- case 17:
27707
+ case 16:
27689
27708
  _audioConnector.resetAudioStreamAndTrack();
27690
27709
  _setAudioMediaProcessorConnector();
27691
- case 19:
27710
+ case 18:
27692
27711
  case "end":
27693
27712
  return _context31.stop();
27694
27713
  }
@@ -27703,7 +27722,7 @@ function SubscriberFactory(_ref2) {
27703
27722
  return _regenerator.default.wrap(function _callee32$(_context32) {
27704
27723
  while (1) switch (_context32.prev = _context32.next) {
27705
27724
  case 0:
27706
- if (webRTCStreams[_activeSourceStreamId]) {
27725
+ if (_webRTCStream) {
27707
27726
  _context32.next = 2;
27708
27727
  break;
27709
27728
  }
@@ -27711,7 +27730,7 @@ function SubscriberFactory(_ref2) {
27711
27730
  case 2:
27712
27731
  _context32.prev = 2;
27713
27732
  _context32.next = 5;
27714
- return _audioConnector == null ? void 0 : _audioConnector.setAudioMediaProcessorConnector(_activeSourceStreamId);
27733
+ return _audioConnector == null ? void 0 : _audioConnector.setAudioMediaProcessorConnector(_webRTCStream);
27715
27734
  case 5:
27716
27735
  _logPendingSetAudioMediaProcessorConnector('Success');
27717
27736
  _context32.next = 13;
@@ -29218,6 +29237,8 @@ function RaptorSocketFactory(deps) {
29218
29237
  var _interopRequireDefault = __webpack_require__(95709);
29219
29238
  exports.__esModule = true;
29220
29239
  exports["default"] = getUserMediaFactory;
29240
+ var _regenerator = _interopRequireDefault(__webpack_require__(92207));
29241
+ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(79092));
29221
29242
  var _assign = _interopRequireDefault(__webpack_require__(86139));
29222
29243
  var _isObject = _interopRequireDefault(__webpack_require__(23805));
29223
29244
  var _eventing = _interopRequireDefault(__webpack_require__(12607));
@@ -29505,23 +29526,41 @@ function getUserMediaFactory(deps) {
29505
29526
  // it when creating `finalized` above.
29506
29527
  const error = parseErrorEvent(browserError);
29507
29528
  if (error.name === Errors.UNABLE_TO_CAPTURE_SCREEN) {
29508
- return new Promise((resolve, reject) => {
29509
- screenSharing.checkCapability(response => {
29510
- if (response.extensionRequired === 'chrome') {
29511
- if (response.extensionRegistered && !response.extensionInstalled) {
29512
- const newErr = otError(Errors.SCREEN_SHARING_EXTENSION_NOT_INSTALLED, error);
29513
- newErr.message = 'Screen sharing extension not installed see https://tokbox.com/developer/guides/screen-sharing/js/#chrome-extension';
29514
- reject(newErr);
29515
- } else if (!response.extensionRegistered) {
29516
- const newErr = otError(Errors.SCREEN_SHARING_EXTENSION_NOT_REGISTERED, error);
29517
- newErr.message = 'Screen sharing extension not registered see https://tokbox.com/developer/guides/screen-sharing/js/#chrome-extension';
29518
- reject(newErr);
29529
+ return new Promise( /*#__PURE__*/function () {
29530
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_, reject) {
29531
+ var response, newErr;
29532
+ return _regenerator.default.wrap(function _callee$(_context2) {
29533
+ while (1) switch (_context2.prev = _context2.next) {
29534
+ case 0:
29535
+ _context2.next = 2;
29536
+ return screenSharing.checkCapability();
29537
+ case 2:
29538
+ response = _context2.sent;
29539
+ if (response.extensionRequired === 'chrome') {
29540
+ if (response.extensionRegistered && !response.extensionInstalled) {
29541
+ newErr = otError(Errors.SCREEN_SHARING_EXTENSION_NOT_INSTALLED, error);
29542
+ newErr.message = 'Screen sharing extension not installed see https://tokbox.com/developer/guides/screen-sharing/js/#chrome-extension';
29543
+ reject(newErr);
29544
+ } else if (!response.extensionRegistered) {
29545
+ newErr = otError(Errors.SCREEN_SHARING_EXTENSION_NOT_REGISTERED, error);
29546
+ newErr.message = 'Screen sharing extension not registered see https://tokbox.com/developer/guides/screen-sharing/js/#chrome-extension';
29547
+ reject(newErr);
29548
+ } else {
29549
+ reject(error);
29550
+ }
29551
+ } else {
29552
+ reject(error);
29553
+ }
29554
+ case 4:
29555
+ case "end":
29556
+ return _context2.stop();
29519
29557
  }
29520
- } else {
29521
- reject(error);
29522
- }
29523
- });
29524
- });
29558
+ }, _callee);
29559
+ }));
29560
+ return function (_x, _x2) {
29561
+ return _ref.apply(this, arguments);
29562
+ };
29563
+ }());
29525
29564
  }
29526
29565
  throw error;
29527
29566
  }).then(stream => {
@@ -41658,7 +41697,7 @@ function staticConfigFactory(_temp) {
41658
41697
  _ref$axios = _ref.axios,
41659
41698
  axios = _ref$axios === void 0 ? _axios.default : _ref$axios,
41660
41699
  _ref$properties = _ref.properties,
41661
- properties = _ref$properties === void 0 ? {"version":"v2.35.0","buildHash":"b3cd7abe5","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;
41662
41701
  /** @type builtInConfig */
41663
41702
  const builtInConfig = (0, _cloneDeep.default)(properties);
41664
41703
  /**
@@ -56769,11 +56808,12 @@ module.exports = __webpack_require__(58191)("forEach");
56769
56808
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
56770
56809
 
56771
56810
  "use strict";
56811
+ /* provided dependency */ var Promise = __webpack_require__(86964);
56772
56812
 
56773
56813
 
56774
56814
  var _interopRequireDefault = __webpack_require__(95709);
56775
56815
  exports.__esModule = true;
56776
- 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;
56777
56817
  var _regenerator = _interopRequireDefault(__webpack_require__(92207));
56778
56818
  var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(79092));
56779
56819
  var _createClass2 = _interopRequireDefault(__webpack_require__(65044));
@@ -56802,6 +56842,12 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
56802
56842
 
56803
56843
  const VIDEO_BUFFER_TIMEOUT = _amrStateDurations.default.VIDEO_BUFFER_TIMEOUT,
56804
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;
56805
56851
  const defaultLogging = (0, _log.default)('WidgetView');
56806
56852
 
56807
56853
  // eslint-disable-next-line no-unused-vars
@@ -56881,6 +56927,10 @@ function WidgetViewFactory(_temp) {
56881
56927
  this._showPoster = undefined;
56882
56928
  this._poster = undefined;
56883
56929
  this._cancelBind = undefined;
56930
+ this._decodeRecoveryAttempts = 0;
56931
+ this._decodeRecoveryTimeout = undefined;
56932
+ this._decodeRecoveryUntil = 0;
56933
+ this._decodeRecoveryToken = 0;
56884
56934
  (0, _eventing.default)(this);
56885
56935
  if (/^(contain|cover)$/.test(fitMode) === false) {
56886
56936
  logging.warn(`Invalid fit value "${fitMode}" passed. Only "contain" and "cover" can be used.`);
@@ -57030,11 +57080,13 @@ function WidgetViewFactory(_temp) {
57030
57080
  };
57031
57081
  _proto.rebindSrcObject = function rebindSrcObject() {
57032
57082
  if (this._videoElementFacade) {
57083
+ this._markDecodeRecoveryTransitionWindow();
57033
57084
  this._videoElementFacade._rebindSrcObject();
57034
57085
  }
57035
57086
  };
57036
57087
  _proto.pauseAndPlayVideoElement = function pauseAndPlayVideoElement() {
57037
57088
  if (this._videoElementFacade) {
57089
+ this._markDecodeRecoveryTransitionWindow();
57038
57090
  this._videoElementFacade._pauseAndPlay();
57039
57091
  }
57040
57092
  }
@@ -57109,6 +57161,77 @@ function WidgetViewFactory(_temp) {
57109
57161
  _proto._emitBindEvent = function _emitBindEvent(action, variation, options) {
57110
57162
  this.emit('bindEvent', action, variation, options);
57111
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
+ };
57112
57235
  _proto._createVideoElementFacade = function _createVideoElementFacade(_ref3) {
57113
57236
  let _inject = _ref3._inject,
57114
57237
  audioVolume = _ref3.audioVolume,
@@ -57124,8 +57247,23 @@ function WidgetViewFactory(_temp) {
57124
57247
  });
57125
57248
  const videoFacadeEvents = (0, _eventHelper.default)(this._videoElementFacade);
57126
57249
  this._videoFacadeEvents = videoFacadeEvents;
57127
- videoFacadeEvents.on('error', () => {
57128
- 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);
57129
57267
  });
57130
57268
  videoFacadeEvents.on('videoDimensionsChanged', (oldValue, newValue) => {
57131
57269
  this.trigger('videoDimensionsChanged', oldValue, newValue);
@@ -57285,12 +57423,7 @@ function WidgetViewFactory(_temp) {
57285
57423
  return _context4.abrupt("return");
57286
57424
  case 20:
57287
57425
  this._emitBindEvent('loadVideoBuffer', 'Success');
57288
- // We now want to log binding duration to monitor the blink: OPENTOK-46931
57289
- // We propagate the event from videoFacade level to Subscriber
57290
- this._videoFacadeEvents.on('bindEvent', (action, variation, options) => {
57291
- this._emitBindEvent(action, variation, options);
57292
- });
57293
- case 22:
57426
+ case 21:
57294
57427
  case "end":
57295
57428
  return _context4.stop();
57296
57429
  }
@@ -57329,6 +57462,7 @@ function WidgetViewFactory(_temp) {
57329
57462
  logging.debug('bindVideo ', {
57330
57463
  webRTCStream
57331
57464
  });
57465
+ this._markDecodeRecoveryTransitionWindow();
57332
57466
  hasExistingElement = !!this._videoElementFacade;
57333
57467
  cancellation = this._getNewBindCancellation();
57334
57468
  if (!hasExistingElement) {
@@ -57340,15 +57474,15 @@ function WidgetViewFactory(_temp) {
57340
57474
  });
57341
57475
  }
57342
57476
  if (!(webRTCStream instanceof MediaStream && hasVideo && isSubscribingToVideo)) {
57343
- _context5.next = 9;
57477
+ _context5.next = 10;
57344
57478
  break;
57345
57479
  }
57346
- _context5.next = 9;
57480
+ _context5.next = 10;
57347
57481
  return this._tryToLoadVideoBuffer(webRTCStream, cancellation, throwIfBufferFails, hasVideo && isSubscribingToVideo);
57348
- case 9:
57349
- _context5.next = 11;
57482
+ case 10:
57483
+ _context5.next = 12;
57350
57484
  return this._bindToStream(webRTCStream, cancellation);
57351
- case 11:
57485
+ case 12:
57352
57486
  if (!hasExistingElement) {
57353
57487
  this._triggerVideoElementCreated();
57354
57488
  }
@@ -57357,16 +57491,16 @@ function WidgetViewFactory(_temp) {
57357
57491
  defaultVideoElementFacade: this._videoElementFacade,
57358
57492
  maxWaitTime: 5000
57359
57493
  });
57360
- _context5.next = 16;
57494
+ _context5.next = 17;
57361
57495
  return this._waitForVideoResolution(webRTCStream);
57362
- case 16:
57496
+ case 17:
57363
57497
  logging.debug('Waiting for video to be playing');
57364
- _context5.next = 19;
57498
+ _context5.next = 20;
57365
57499
  return whenVideoPlaying;
57366
- case 19:
57500
+ case 20:
57367
57501
  logging.debug('Video is playing');
57368
57502
  throwIfBindCancelled(cancellation);
57369
- case 21:
57503
+ case 22:
57370
57504
  case "end":
57371
57505
  return _context5.stop();
57372
57506
  }
@@ -57383,6 +57517,7 @@ function WidgetViewFactory(_temp) {
57383
57517
  }
57384
57518
  };
57385
57519
  _proto.destroyVideo = function destroyVideo() {
57520
+ this._resetDecodeRecoveryState();
57386
57521
  if (this._videoElementFacade) {
57387
57522
  this._videoElementFacade.destroy();
57388
57523
  this._videoElementFacade = null;
@@ -59400,42 +59535,24 @@ function screenSharingFactory(deps) {
59400
59535
  screenSharing.pickHelper = () => screenSharingPickHelper();
59401
59536
 
59402
59537
  /**
59403
- * Checks for support for publishing screen-sharing streams on the client browser. The object
59404
- * passed to the callback function defines whether screen sharing is supported, as well as
59538
+ * Checks for support for publishing screen-sharing streams on the client browser. The returned
59539
+ * object in the promise defines whether screen sharing is supported, as well as
59405
59540
  * which screen-sharing sources (application, screen, or window) are supported. It also indicates
59406
59541
  * whether an extension is required, installed, and registered (if needed).
59407
59542
  * <p>
59408
59543
  * <pre>
59409
- * OT.checkScreenSharingCapability(function(response) {
59410
- * if (!response.supported || response.extensionRegistered === false) {
59411
- * // This browser does not support screen sharing
59412
- * } else if (response.extensionInstalled === false) {
59413
- * // Prompt to install the extension
59414
- * } else {
59415
- * // Screen sharing is available.
59416
- * }
59417
- * });
59544
+ * const response = await OT.checkScreenSharingCapability();
59545
+ * if (!response.supported || response.extensionRegistered === false) {
59546
+ * // This browser does not support screen sharing
59547
+ * } else if (response.extensionInstalled === false) {
59548
+ * // Prompt to install the extension
59549
+ * } else {
59550
+ * // Screen sharing is available.
59551
+ * }
59418
59552
  * </pre>
59419
59553
  * <p>
59420
- * Chrome 72+, Firefox 52+, Safari 13+, Edge 79+, and Opera 59+ have screen-sharing
59421
- * support built-in, with no extension required. (Note that support for the Vonage Video API
59422
- * plugin for Internet Explorer is removed in Vonage Video API 2.17.) Screen sharing is
59423
- * <i>not</i> supported in mobile browsers. In Electron, screen sharing is supported if
59424
- * the <code>webPreferences.contextIsolation</code> option of the Electron BrowserWindow is
59425
- * set to <code>false</code> or if the app uses a preload script to access the desktop capturer.
59426
- * (The default value of <code>webPreferences.contextIsolation</code> option is <code>true</code>
59427
- * in Electron 12 and <code>false</code> in previous versions). To publish a screen-sharing video
59428
- * in older versions of Chrome or Opera, the client adds an extension that enables publishing a
59429
- * screen-sharing video stream on your domain. The Vonage Video API
59430
- * <a href="https://github.com/opentok/screensharing-extensions">screensharing-extensions</a>
59431
- * sample includes code for creating an extension for screen-sharing support in
59432
- * older versions of Chrome and Opera.
59433
- * <p>
59434
- * For more information, see the <a href="https://tokbox.com/developer/guides/screen-sharing/js/">
59435
- * Vonage Video API Screen Sharing</a> developer guide.
59436
59554
  *
59437
- * @param {function} callback The callback invoked with the support options object passed as
59438
- * the parameter. This object has the following properties that indicate support for publishing
59555
+ * This object has the following properties that indicate support for publishing
59439
59556
  * screen-sharing streams in the client:
59440
59557
  * <p>
59441
59558
  * <ul>
@@ -59482,47 +59599,80 @@ function screenSharingFactory(deps) {
59482
59599
  * </li>
59483
59600
  * </ul>
59484
59601
  *
59602
+ * Chrome 72+, Firefox 52+, Safari 13+, Edge 79+, and Opera 59+ have screen-sharing
59603
+ * support built-in, with no extension required. (Note that support for the Vonage Video API
59604
+ * plugin for Internet Explorer is removed in Vonage Video API 2.17.) Screen sharing is
59605
+ * <i>not</i> supported in mobile browsers. In Electron, screen sharing is supported if
59606
+ * the <code>webPreferences.contextIsolation</code> option of the Electron BrowserWindow is
59607
+ * set to <code>false</code> or if the app uses a preload script to access the desktop capturer.
59608
+ * (The default value of <code>webPreferences.contextIsolation</code> option is <code>true</code>
59609
+ * in Electron 12 and <code>false</code> in previous versions). To publish a screen-sharing video
59610
+ * in older versions of Chrome or Opera, the client adds an extension that enables publishing a
59611
+ * screen-sharing video stream on your domain. The Vonage Video API
59612
+ * <a href="https://github.com/opentok/screensharing-extensions">screensharing-extensions</a>
59613
+ * sample includes code for creating an extension for screen-sharing support in
59614
+ * older versions of Chrome and Opera.
59615
+ * <p>
59616
+ * For more information, see the <a href="https://tokbox.com/developer/guides/screen-sharing/js/">
59617
+ * Vonage Video API Screen Sharing</a> developer guide.
59618
+ *
59619
+ * @param {function} callback Optional callback invoked with the support options object passed as
59620
+ * the parameter.
59621
+ *
59622
+ * @returns {Promise<ScreenSharingCapabilityResponse>} A promise with the capability
59623
+ *
59485
59624
  * @see <a href="OT.html#initPublisher">OT.initPublisher()</a>
59486
59625
  * @see <a href="OT.html#registerScreenSharingExtension">OT.registerScreenSharingExtension()</a>
59487
59626
  * @method OT.checkScreenSharingCapability
59488
59627
  * @memberof OT
59489
59628
  */
59490
- screenSharing.checkCapability = callback => {
59491
- const response = {
59492
- supported: false,
59493
- extensionRequired: undefined,
59494
- extensionRegistered: undefined,
59495
- extensionInstalled: undefined,
59496
- supportedSources: {}
59497
- };
59498
-
59499
- // find a supported browser
59629
+ screenSharing.checkCapability = function (callback) {
59630
+ if (callback === void 0) {
59631
+ callback = () => {};
59632
+ }
59633
+ return new Promise(resolve => {
59634
+ const response = {
59635
+ supported: false,
59636
+ extensionRequired: undefined,
59637
+ extensionRegistered: undefined,
59638
+ extensionInstalled: undefined,
59639
+ supportedSources: {}
59640
+ };
59500
59641
 
59501
- const helper = screenSharingPickHelper();
59502
- if (helper.name === undefined) {
59503
- setTimeout(callback.bind(null, response));
59504
- return;
59505
- }
59506
- response.supported = true;
59507
- response.extensionRequired = helper.proto.extensionRequired ? helper.name : undefined;
59508
- response.supportedSources = {
59509
- screen: helper.proto.sources.screen,
59510
- application: helper.proto.sources.application,
59511
- window: helper.proto.sources.window,
59512
- browser: helper.proto.sources.browser
59513
- };
59514
- if (!helper.instance) {
59515
- response.extensionRegistered = false;
59516
- if (response.extensionRequired) {
59517
- response.extensionInstalled = false;
59642
+ // find a supported browser
59643
+ const helper = screenSharingPickHelper();
59644
+ if (helper.name === undefined) {
59645
+ setTimeout(() => {
59646
+ callback(response);
59647
+ });
59648
+ resolve(response);
59649
+ return;
59518
59650
  }
59519
- setTimeout(callback.bind(null, response));
59520
- return;
59521
- }
59522
- response.extensionRegistered = response.extensionRequired ? true : undefined;
59523
- helper.instance.isInstalled(installed => {
59524
- response.extensionInstalled = response.extensionRequired || OTHelpers.env.name === 'Firefox' ? installed : undefined;
59525
- callback(response);
59651
+ response.supported = true;
59652
+ response.extensionRequired = helper.proto.extensionRequired ? helper.name : undefined;
59653
+ response.supportedSources = {
59654
+ screen: helper.proto.sources.screen,
59655
+ application: helper.proto.sources.application,
59656
+ window: helper.proto.sources.window,
59657
+ browser: helper.proto.sources.browser
59658
+ };
59659
+ if (!helper.instance) {
59660
+ response.extensionRegistered = false;
59661
+ if (response.extensionRequired) {
59662
+ response.extensionInstalled = false;
59663
+ }
59664
+ setTimeout(() => {
59665
+ callback(response);
59666
+ });
59667
+ resolve(response);
59668
+ return;
59669
+ }
59670
+ response.extensionRegistered = response.extensionRequired ? true : undefined;
59671
+ helper.instance.isInstalled(installed => {
59672
+ response.extensionInstalled = response.extensionRequired || OTHelpers.env.name === 'Firefox' ? installed : undefined;
59673
+ callback(response);
59674
+ resolve(response);
59675
+ });
59526
59676
  });
59527
59677
  };
59528
59678
  screenSharing.registerExtensionHelper('electron', electronExtensionHelper);
@@ -59538,7 +59688,7 @@ function screenSharingFactory(deps) {
59538
59688
  videoSource = opt.videoSource,
59539
59689
  constraints = opt.constraints;
59540
59690
  return new Promise((resolve, reject) => {
59541
- screenSharing.checkCapability(response => {
59691
+ screenSharing.checkCapability().then(response => {
59542
59692
  if (!response.supported) {
59543
59693
  let errorMessage = 'Screen Sharing is not supported in this browser';
59544
59694
  if (OTHelpers.env.isElectron) {
@@ -61739,41 +61889,51 @@ function reportIssueFactory(deps) {
61739
61889
  * <a href="https://tokbox.com/developer/tools/inspector/">Inspector</a> or when discussing
61740
61890
  * an issue with the Vonage API support team.
61741
61891
  *
61742
- * @param completionHandler {Function} A function that is called when the call to this method
61892
+ * @param completionHandler {Function} Optional Function that is called when the call to this method
61743
61893
  * succeeds or fails. This function has two parameters. The first parameter is an
61744
61894
  * <a href="Error.html">Error</a> object that is set when the call to the
61745
61895
  * <code>reportIssue()</code> method fails (for example, if the client is not connected to the
61746
61896
  * network) or <code>null</code> when the call to the <code>reportIssue()</code> method succeeds.
61747
61897
  * The second parameter is set to the report ID (a unique string) when the call succeeds.
61748
61898
  *
61899
+ * @returns {Promise<string>} A promise resolving to the report ID
61900
+ *
61749
61901
  * @method OT.reportIssue
61750
61902
  * @memberof OT
61751
61903
  */
61752
61904
  return function reportIssue(completionHandler) {
61753
- if (completionHandler === void 0) {
61754
- completionHandler = () => {};
61755
- }
61756
- const reportIssueId = uuid();
61757
- function onDone(err) {
61758
- if (err) {
61759
- completionHandler(otError(errors.REPORT_ISSUE_FAILED, new Error('Error calling OT.reportIssue(). Check the client\'s network connection.'), ExceptionCodes.REPORT_ISSUE_ERROR));
61905
+ const hasCompletionHandler = typeof completionHandler === 'function';
61906
+ const callback = hasCompletionHandler ? completionHandler : () => {};
61907
+ const promise = new Promise((resolve, reject) => {
61908
+ const reportIssueId = uuid();
61909
+ function onDone(err) {
61910
+ if (err) {
61911
+ const error = otError(errors.REPORT_ISSUE_FAILED, new Error('Error calling OT.reportIssue(). Check the client\'s network connection.'), ExceptionCodes.REPORT_ISSUE_ERROR);
61912
+ callback(error);
61913
+ reject(error);
61914
+ } else {
61915
+ callback(null, reportIssueId);
61916
+ resolve(reportIssueId);
61917
+ }
61918
+ }
61919
+ if (sessionObjects.sessions.length() === 0) {
61920
+ analytics.logEvent({
61921
+ action: 'ReportIssue',
61922
+ variation: 'Event',
61923
+ payload: {
61924
+ reportIssueId
61925
+ }
61926
+ }, null, onDone);
61760
61927
  } else {
61761
- completionHandler(null, reportIssueId);
61928
+ Promise.all(sessionObjects.sessions.map(session => session.reportIssue({
61929
+ id: reportIssueId
61930
+ }))).then(() => onDone(), err => onDone(err));
61762
61931
  }
61932
+ });
61933
+ if (hasCompletionHandler) {
61934
+ promise.catch(() => {});
61763
61935
  }
61764
- if (sessionObjects.sessions.length() === 0) {
61765
- analytics.logEvent({
61766
- action: 'ReportIssue',
61767
- variation: 'Event',
61768
- payload: {
61769
- reportIssueId
61770
- }
61771
- }, null, onDone);
61772
- } else {
61773
- Promise.all(sessionObjects.sessions.map(session => session.reportIssue({
61774
- id: reportIssueId
61775
- }))).then(() => onDone(), err => onDone(err));
61776
- }
61936
+ return promise;
61777
61937
  };
61778
61938
  }
61779
61939
 
@@ -62271,7 +62431,7 @@ function NativeVideoElementWrapperFactory(deps) {
62271
62431
  }, _callee);
62272
62432
  })));
62273
62433
  const onError = event => {
62274
- this.trigger('error', videoElementErrorMap(event.target.error));
62434
+ this.trigger('error', event, videoElementErrorMap(event.target.error));
62275
62435
  };
62276
62436
  this._domElementEvents.on('error', onError, false);
62277
62437
  this._domElementEvents.on('pause', _playVideoOnPause);
@@ -67254,6 +67414,7 @@ exports["default"] = _default;
67254
67414
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
67255
67415
 
67256
67416
  "use strict";
67417
+ /* provided dependency */ var Promise = __webpack_require__(86964);
67257
67418
 
67258
67419
 
67259
67420
  var _interopRequireDefault = __webpack_require__(95709);
@@ -67958,7 +68119,7 @@ function initPublisherFactory(deps) {
67958
68119
  * @method OT.initPublisher
67959
68120
  * @memberof OT
67960
68121
  */
67961
- return function initPublisher(targetElement, properties, completionHandler) {
68122
+ function initPublisher(targetElement, properties, completionHandler) {
67962
68123
  logging.debug(`OT.initPublisher(${targetElement})`);
67963
68124
 
67964
68125
  // To support legacy (apikey, targetElement, properties) users
@@ -68015,7 +68176,6 @@ function initPublisherFactory(deps) {
68015
68176
  };
68016
68177
  let removeHandlersAndCallComplete = function removeHandlersAndCallComplete(err) {
68017
68178
  publisher.off('initSuccess', removeInitSuccessAndCallComplete);
68018
-
68019
68179
  // We're only handling the error case here as we're just
68020
68180
  // initing the publisher, not actually attempting to publish.
68021
68181
  if (err) {
@@ -68026,7 +68186,24 @@ function initPublisherFactory(deps) {
68026
68186
  publisher.once('publishComplete', removeHandlersAndCallComplete);
68027
68187
  publisher.publish(targetElement);
68028
68188
  return publisher;
68029
- };
68189
+ }
68190
+
68191
+ /**
68192
+ * The <code>initPublisher</code> function is also available in a promisifed flavour.
68193
+ * Note that this function will only resolve to a publisher object if there were no
68194
+ * errors involved in its creation.
68195
+ */
68196
+ initPublisher.promise = (targetElement, properties) => new Promise((resolve, reject) => {
68197
+ const args = [targetElement, properties].filter(arg => arg !== undefined);
68198
+ const publisher = initPublisher(...args, error => {
68199
+ if (error) {
68200
+ reject(error);
68201
+ } else {
68202
+ resolve(publisher);
68203
+ }
68204
+ });
68205
+ });
68206
+ return initPublisher;
68030
68207
  }
68031
68208
 
68032
68209
  /***/ }),
@@ -68176,6 +68353,7 @@ module.exports = baseRest;
68176
68353
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
68177
68354
 
68178
68355
  "use strict";
68356
+ /* provided dependency */ var Promise = __webpack_require__(86964);
68179
68357
 
68180
68358
 
68181
68359
  var _interopRequireDefault = __webpack_require__(95709);
@@ -68185,13 +68363,24 @@ var _get_rtc_stats_report_adapter = _interopRequireDefault(__webpack_require__(5
68185
68363
  var _createRtcStatsReportParser = _interopRequireDefault(__webpack_require__(14848));
68186
68364
  // This returns the array-ified list of stats our users are accustomed to
68187
68365
  var _default = (peerConnection, track, completion) => {
68188
- (0, _get_rtc_stats_report_adapter.default)(peerConnection, track, (err, rtcStatsReport) => {
68189
- if (err) {
68190
- completion(err);
68191
- return;
68192
- }
68193
- completion(null, (0, _createRtcStatsReportParser.default)()(rtcStatsReport));
68366
+ const hasCompletion = typeof completion === 'function';
68367
+ const callback = hasCompletion ? completion : () => {};
68368
+ const promise = new Promise((resolve, reject) => {
68369
+ (0, _get_rtc_stats_report_adapter.default)(peerConnection, track, (err, rtcStatsReport) => {
68370
+ if (err) {
68371
+ callback(err);
68372
+ reject(err);
68373
+ return;
68374
+ }
68375
+ const parsedReport = (0, _createRtcStatsReportParser.default)()(rtcStatsReport);
68376
+ callback(null, parsedReport);
68377
+ resolve(parsedReport);
68378
+ });
68194
68379
  });
68380
+ if (hasCompletion) {
68381
+ promise.catch(() => {});
68382
+ }
68383
+ return promise;
68195
68384
  };
68196
68385
  exports["default"] = _default;
68197
68386
 
@@ -103506,36 +103695,37 @@ var _log = _interopRequireDefault(__webpack_require__(48669));
103506
103695
  var _updateTrackOnStream = _interopRequireDefault(__webpack_require__(29634));
103507
103696
  var _createAudioTrackHolder = _interopRequireDefault(__webpack_require__(37268));
103508
103697
  const logging = (0, _log.default)('Subscriber');
103509
- const routedSourceStreamId = 'MANTIS';
103510
- const relayedSourceStreamId = 'P2P';
103511
- const createAudioConnector = function createAudioConnector(streams, deps) {
103698
+ const createAudioConnector = function createAudioConnector(deps) {
103512
103699
  if (deps === void 0) {
103513
103700
  deps = {};
103514
103701
  }
103515
103702
  const updateTrackOnStream = deps.updateTrackOnStream || _updateTrackOnStream.default;
103516
103703
  const createAudioTrackHolder = deps.createAudioTrackHolder || _createAudioTrackHolder.default;
103517
- const mediaStreams = streams;
103518
103704
  let _audioMediaProcessorConnector;
103705
+ let _stream;
103519
103706
  let _originalAudioTrack;
103520
103707
  let _audioTrackHolder;
103521
- const clearConnectorAndAudioHolder = () => {
103522
- var _audioMediaProcessorC;
103523
- (_audioMediaProcessorC = _audioMediaProcessorConnector) == null ? void 0 : _audioMediaProcessorC.destroy();
103524
- _audioMediaProcessorConnector = null;
103708
+ const clearAudioHolder = () => {
103525
103709
  if (_audioTrackHolder) {
103526
103710
  _audioTrackHolder.srcObject = null;
103527
103711
  _audioTrackHolder = null;
103528
103712
  }
103713
+ _stream = null;
103529
103714
  _originalAudioTrack = null;
103530
103715
  };
103716
+ const clearConnectorAndAudioHolder = () => {
103717
+ var _audioMediaProcessorC;
103718
+ (_audioMediaProcessorC = _audioMediaProcessorConnector) == null ? void 0 : _audioMediaProcessorC.destroy();
103719
+ _audioMediaProcessorConnector = null;
103720
+ clearAudioHolder();
103721
+ };
103531
103722
  const applyAudioConnector = /*#__PURE__*/function () {
103532
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(sourceStreamId) {
103533
- var _mediaStreams$sourceS2;
103534
- 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;
103535
103725
  return _regenerator.default.wrap(function _callee$(_context) {
103536
103726
  while (1) switch (_context.prev = _context.next) {
103537
103727
  case 0:
103538
- _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];
103539
103729
  if (originalAudioTrack) {
103540
103730
  _context.next = 7;
103541
103731
  break;
@@ -103543,42 +103733,59 @@ const createAudioConnector = function createAudioConnector(streams, deps) {
103543
103733
  message = 'Connector not set as no audio track is present.';
103544
103734
  error = new Error(message);
103545
103735
  logging.error(`setAudioMediaProcessorConnector: ${message}`);
103546
- _audioMediaProcessorConnector = null;
103736
+ clearConnectorAndAudioHolder();
103547
103737
  throw error;
103548
103738
  case 7:
103549
103739
  _context.prev = 7;
103550
103740
  // We create a video element to hold a new stream containing the original audio track.
103551
103741
  // If the track is not used in a stream, it is stopped and no audio is heard through
103552
103742
  // the filtered track.
103743
+ if (_audioTrackHolder) {
103744
+ _audioTrackHolder.srcObject = null;
103745
+ }
103553
103746
  _audioTrackHolder = createAudioTrackHolder(originalAudioTrack);
103554
- _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;
103555
103757
  return _audioMediaProcessorConnector.setTrack(originalAudioTrack);
103556
- case 11:
103758
+ case 17:
103557
103759
  filteredAudioTrack = _context.sent;
103760
+ _stream = stream;
103558
103761
  _originalAudioTrack = originalAudioTrack;
103559
- updateTrackOnStream(mediaStreams[sourceStreamId], originalAudioTrack, filteredAudioTrack);
103560
- _context.next = 20;
103762
+ updateTrackOnStream(stream, originalAudioTrack, filteredAudioTrack);
103763
+ _context.next = 27;
103561
103764
  break;
103562
- case 16:
103563
- _context.prev = 16;
103765
+ case 23:
103766
+ _context.prev = 23;
103564
103767
  _context.t0 = _context["catch"](7);
103565
103768
  clearConnectorAndAudioHolder();
103566
103769
  throw _context.t0;
103567
- case 20:
103770
+ case 27:
103568
103771
  case "end":
103569
103772
  return _context.stop();
103570
103773
  }
103571
- }, _callee, null, [[7, 16]]);
103774
+ }, _callee, null, [[7, 23]]);
103572
103775
  }));
103573
103776
  return function applyAudioConnector(_x) {
103574
103777
  return _ref.apply(this, arguments);
103575
103778
  };
103576
103779
  }();
103577
- const resetAudioStream = sourceStreamId => {
103780
+ const resetAudioStream = () => {
103578
103781
  try {
103579
- const _mediaStreams$sourceS3 = mediaStreams[sourceStreamId].getAudioTracks(),
103580
- filteredAudioTrack = _mediaStreams$sourceS3[0];
103581
- 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();
103582
103789
  } catch (error) {
103583
103790
  throw Error(`setAudioMediaProcessorConnector: Error resetting track: ${error.message}`);
103584
103791
  }
@@ -103588,15 +103795,17 @@ const createAudioConnector = function createAudioConnector(streams, deps) {
103588
103795
  return _audioMediaProcessorConnector;
103589
103796
  },
103590
103797
  initializeConnector(mediaProcessorConnector) {
103798
+ var _audioMediaProcessorC2;
103799
+ (_audioMediaProcessorC2 = _audioMediaProcessorConnector) == null ? void 0 : _audioMediaProcessorC2.destroy();
103591
103800
  _audioMediaProcessorConnector = new _mediaProcessorConnector.default(mediaProcessorConnector);
103592
103801
  },
103593
- setAudioMediaProcessorConnector(sourceStreamId) {
103802
+ setAudioMediaProcessorConnector(stream) {
103594
103803
  return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
103595
103804
  return _regenerator.default.wrap(function _callee2$(_context2) {
103596
103805
  while (1) switch (_context2.prev = _context2.next) {
103597
103806
  case 0:
103598
103807
  _context2.next = 2;
103599
- return applyAudioConnector(sourceStreamId);
103808
+ return applyAudioConnector(stream);
103600
103809
  case 2:
103601
103810
  case "end":
103602
103811
  return _context2.stop();
@@ -103604,63 +103813,39 @@ const createAudioConnector = function createAudioConnector(streams, deps) {
103604
103813
  }, _callee2);
103605
103814
  }))();
103606
103815
  },
103607
- applyAudioConnectorOnRoutedToRelayedTransition() {
103816
+ resetAndApplyAudioConnector(stream) {
103608
103817
  var _this = this;
103609
103818
  return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
103819
+ var hadAudioMediaProcessorConnector;
103610
103820
  return _regenerator.default.wrap(function _callee3$(_context3) {
103611
103821
  while (1) switch (_context3.prev = _context3.next) {
103612
103822
  case 0:
103613
- // We restore the Mantis stream's original track, so when we transition again,
103614
- // we can apply a filter to the unfiltered track.
103615
- _this.resetAudioStreamAndTrack(routedSourceStreamId);
103616
- if (_audioMediaProcessorConnector) {
103617
- _context3.next = 3;
103823
+ hadAudioMediaProcessorConnector = !!_audioMediaProcessorConnector;
103824
+ _this.resetAudioStreamAndTrack();
103825
+ if (hadAudioMediaProcessorConnector) {
103826
+ _context3.next = 4;
103618
103827
  break;
103619
103828
  }
103620
103829
  return _context3.abrupt("return");
103621
- case 3:
103622
- _context3.next = 5;
103623
- return applyAudioConnector(relayedSourceStreamId);
103624
- case 5:
103830
+ case 4:
103831
+ _context3.next = 6;
103832
+ return applyAudioConnector(stream);
103833
+ case 6:
103625
103834
  case "end":
103626
103835
  return _context3.stop();
103627
103836
  }
103628
103837
  }, _callee3);
103629
103838
  }))();
103630
103839
  },
103631
- applyAudioConnectorOnRelayedToRoutedTransition() {
103632
- return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
103633
- return _regenerator.default.wrap(function _callee4$(_context4) {
103634
- while (1) switch (_context4.prev = _context4.next) {
103635
- case 0:
103636
- if (_audioMediaProcessorConnector) {
103637
- _context4.next = 2;
103638
- break;
103639
- }
103640
- return _context4.abrupt("return");
103641
- case 2:
103642
- _context4.next = 4;
103643
- return applyAudioConnector(routedSourceStreamId);
103644
- case 4:
103645
- case "end":
103646
- return _context4.stop();
103647
- }
103648
- }, _callee4);
103649
- }))();
103650
- },
103651
- clearAudioMediaProcessorConnector(sourceStreamId) {
103652
- if (!_originalAudioTrack) {
103653
- return;
103654
- }
103655
- resetAudioStream(sourceStreamId);
103840
+ clearAudioMediaProcessorConnector() {
103841
+ this.resetAudioStreamAndTrack();
103656
103842
  clearConnectorAndAudioHolder();
103657
103843
  },
103658
- resetAudioStreamAndTrack(sourceStreamId) {
103844
+ resetAudioStreamAndTrack() {
103659
103845
  if (!_originalAudioTrack) {
103660
103846
  return;
103661
103847
  }
103662
- resetAudioStream(sourceStreamId);
103663
- _originalAudioTrack = null;
103848
+ resetAudioStream();
103664
103849
  }
103665
103850
  };
103666
103851
  };