twilio-video 2.18.1 → 2.18.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@ The Twilio Programmable Video SDKs use [Semantic Versioning](http://www.semver.o
2
2
 
3
3
  **Version 1.x reached End of Life on September 8th, 2021.** See the changelog entry [here](https://www.twilio.com/changelog/end-of-life-complete-for-unsupported-versions-of-the-programmable-video-sdk). Support for the 1.x version ended on December 4th, 2020.
4
4
 
5
+ 2.18.2 (December 15, 2021)
6
+ ==========================
7
+
8
+ Bug Fixes
9
+ ---------
10
+
11
+ - Fixed a bug where setting `clientTrackSwitchOffControl` to `auto` caused the RemoteVideoTracks to get switched off while playing in picture-in-picture mode. Note that this fix does not apply to Firefox as it does not yet implement [picture-in-picture](https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API) APIs. (VIDEO-6677)
12
+
5
13
  2.18.1 (October 29, 2021)
6
14
  =========================
7
15
 
package/COMMON_ISSUES.md CHANGED
@@ -36,10 +36,10 @@ before opening a new issue. We recommend regularly upgrading to the latest versi
36
36
 
37
37
  ### Chrome mobile
38
38
  <details>
39
- <summary>Chrome on iOS 15.1 crashes when publishing or muting a VideoTrack that is using an H264 codec</summary>
39
+ <summary>Android 12: Video distortion on Chrome when hardware acceleration is enabled</summary>
40
40
  <p>
41
41
 
42
- This issue happens due to a regression on iOS 15.1 where using an H264 codec causes the browser to crash when joining a room or when muting the VideoTrack. Please use VP8 as a workaround for now. See more details [here](https://github.com/twilio/twilio-video.js/issues/1611).
42
+ This is a VP8 encoder issue on Android 12. Please see this [github ticket](https://github.com/twilio/twilio-video.js/issues/1627) and this [Chrome bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1237677) for more details.
43
43
  </p>
44
44
  </details>
45
45
  <details>
@@ -61,13 +61,12 @@ before opening a new issue. We recommend regularly upgrading to the latest versi
61
61
 
62
62
  ### Safari desktop
63
63
  <details>
64
- <summary>Safari 15.1 crashes when muting a VideoTrack that is using an H264 codec</summary>
64
+ <summary>Browser crashes when muting a VideoTrack that is using an H264 codec on Safari 15.1</summary>
65
65
  <p>
66
66
 
67
- This issue happens due to a regression on Safari 15.1 where muting a VideoTrack that is using an H264 codec causes the browser to crash. Please use VP8 as a workaround for now. See more details [here](https://github.com/twilio/twilio-video.js/issues/1611).
67
+ Due to a regression on Safari 15.1, the browser crashes when a VideoTrack is muted that is using an H264 codec. Please use VP8 as a workaround for now. See more details [here](https://github.com/twilio/twilio-video.js/issues/1611).
68
68
  </p>
69
69
  </details>
70
-
71
70
  <details>
72
71
  <summary>Failures to publish tracks on Safari 15</summary>
73
72
  <p>
@@ -114,17 +113,101 @@ before opening a new issue. We recommend regularly upgrading to the latest versi
114
113
 
115
114
  ### Safari mobile
116
115
  <details>
117
- <summary>iOS 15.1: Browser crashes when publishing or muting a VideoTrack that is using an H264 codec</summary>
116
+ <summary>iOS 15: VideoTracks goes black and the page freezes on certain interruptions</summary>
117
+ <p>
118
+
119
+ Certain interruptions such as incoming calls, backgrounding the browser or switching between apps causes VideoTracks on Chrome and Safari on iOS 15.1 to go black. Sometimes, the whole page also freezes and become unresponsive causing audio and video to cut off. These issues are regressions on iOS 15.1. See the following bugs for more details.
120
+
121
+ * [Page freezing](https://bugs.webkit.org/show_bug.cgi?id=230922#c12)
122
+ * [VideoTrack going black](https://bugs.webkit.org/show_bug.cgi?id=232599)
123
+
124
+ A workaround can be implemented to prevent the VideoTrack from going black. This workaround however doesn't prevent the issue where sometimes the page freezes. It is recommended to apply this workaround on Chrome and Safari on iOS 15.1.
125
+
126
+ ```js
127
+ // Keeps track of video elements and their event listeners
128
+ const videoElements = {};
129
+
130
+ // Listen to onPlay and onPause events and intelligently re-attach the video element
131
+ function shimVideoElement(track, el) {
132
+ let wasInterrupted = false;
133
+
134
+ const onPause = () => {
135
+ wasInterrupted = true;
136
+ };
137
+
138
+ const onPlay = () => {
139
+ if (wasInterrupted) {
140
+ track.detach(el);
141
+ track.attach(el);
142
+ wasInterrupted = false;
143
+ }
144
+ };
145
+
146
+ el.addEventListener('pause', onPause);
147
+ el.addEventListener('play', onPlay);
148
+
149
+ // Track this element so we can remove the listeners
150
+ videoElements[el] = { onPause, onPlay };
151
+ }
152
+ ```
153
+
154
+ Apply the workaround after attaching the video element.
155
+
156
+ ```js
157
+ videoTrack.attach(videoElement);
158
+ shimVideoElement(videoTrack, videoElement);
159
+ ```
160
+
161
+ Remove the listeners before detaching the video element.
162
+
163
+ ```js
164
+ const { onPause, onPlay } = videoElements[videoElement];
165
+ videoElement.removeEventListener('pause', onPause);
166
+ videoElement.removeEventListener('play', onPlay);
167
+ ```
168
+ </p>
169
+ </details>
170
+ <details>
171
+ <summary>iOS 15: Browser crashes when publishing or muting a VideoTrack that is using an H264 codec</summary>
118
172
  <p>
119
173
 
120
- This issue happens due to a regression on iOS 15.1 where using an H264 codec causes the browser to crash when joining a room or when muting the VideoTrack. Please use VP8 as a workaround for now. See more details [here](https://github.com/twilio/twilio-video.js/issues/1611).
174
+ Chrome and Safari on iOS 15.1 crashes when a VideoTrack is muted or published using an H264 codec. This issue happens due to a regression on iOS 15.1. Please use VP8 as a workaround for now. See more details [here](https://github.com/twilio/twilio-video.js/issues/1611).
121
175
  </p>
122
176
  </details>
123
177
  <details>
124
178
  <summary>iOS 15: Low audio volume in Safari</summary>
125
179
  <p>
126
180
 
127
- Safari on iOS version 15, sometimes routes audio to the earpiece and not the speakers by default. Which customers some time perceive as low audio volume. Find more details [here](https://github.com/twilio/twilio-video.js/issues/1586) and in this [WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=230902).
181
+ Safari on iOS version 15, sometimes routes audio to the earpiece and not the speakers by default. Which customers some time perceive as low audio volume. Find more details [here](https://github.com/twilio/twilio-video.js/issues/1586) and in this [WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=230902). As a workaround, you can pipe all remote audio tracks into a single audio context for iOS 15. Using a gain node, you can increase the gain value to increase the audio volume levels. See example below.
182
+
183
+ ```js
184
+ // Make sure to reuse the audioContext object as browsers
185
+ // have limits to the number of AudioContext instances you can create.
186
+ const audioContext = new (window.AudioContext || window.webkitAudioContext)();
187
+
188
+ function attachAudioTrack(remoteAudioTrack) {
189
+ const audioNode = audioContext.createMediaStreamSource(new MediaStream([remoteAudioTrack.mediaStreamTrack]));
190
+ const gainNode = audioContext.createGain();
191
+
192
+ // Adjust this value depending on your customers' preference
193
+ gainNode.gain.value = 20;
194
+
195
+ audioNode.connect(gainNode);
196
+ gainNode.connect(audioContext.destination);
197
+ }
198
+
199
+ // Attach the RemoteAudioTrack once received.
200
+ attachAudioTrack(remoteAudioTrack);
201
+ ```
202
+
203
+ This workaround has the following potential side effects.
204
+
205
+ * There is a possibility of the introduction of echo. Please adjust the gain value and check for echo while testing the workaround.
206
+ * The output volume might end up really high if the user switches headsets.
207
+ * The default volume might end up really high once Apple rolls out the fix for this issue.
208
+
209
+ Keeping the side effects in mind, you might need to adjust your UI to improve the experience. For example, you can turn off this workaround by default and have a "call to action" in your UI that allows the user to turn the volume up if they cannot hear any audio. This button will then apply the workaround. Another option is to listen for `devicechange` events to determine if the user switches headsets. When this happens, you will have the ability to reset the gain value.
210
+
128
211
  </p>
129
212
  </details>
130
213
  <details>
package/README.md CHANGED
@@ -74,7 +74,7 @@ Releases of twilio-video.js are hosted on a CDN, and you can include these
74
74
  directly in your web app using a &lt;script&gt; tag.
75
75
 
76
76
  ```html
77
- <script src="//sdk.twilio.com/js/video/releases/2.18.1/twilio-video.min.js"></script>
77
+ <script src="//sdk.twilio.com/js/video/releases/2.18.2/twilio-video.min.js"></script>
78
78
 
79
79
  ```
80
80
 
@@ -1,4 +1,4 @@
1
- /*! twilio-video.js 2.18.1
1
+ /*! twilio-video.js 2.18.2
2
2
 
3
3
  The following license applies to all parts of this software except as
4
4
  documented below.
@@ -3469,6 +3469,8 @@ function restartWhenInadvertentlyStopped(localMediaTrack) {
3469
3469
  // after the MediaStreamTrack is re-acquired.
3470
3470
  var promise = (trackChangeInProgress && trackChangeInProgress.promise) || Promise.resolve();
3471
3471
  return promise.finally(function () { return localMediaRestartDeferreds.resolveDeferred(kind); });
3472
+ }).catch(function (ex) {
3473
+ log.error("error in maybeRestart: " + ex.message);
3472
3474
  });
3473
3475
  }
3474
3476
  function onMute() {
@@ -5414,6 +5416,12 @@ var RemoteVideoTrack = /** @class */ (function (_super) {
5414
5416
  _invisibleElements: {
5415
5417
  value: new WeakSet(),
5416
5418
  },
5419
+ _elToPipCallbacks: {
5420
+ value: new WeakMap(),
5421
+ },
5422
+ _elToPipWindows: {
5423
+ value: new WeakMap(),
5424
+ },
5417
5425
  _turnOffTimer: {
5418
5426
  value: new Timeout(function () {
5419
5427
  _this._setRenderHint({ enabled: false });
@@ -5507,6 +5515,45 @@ var RemoteVideoTrack = /** @class */ (function (_super) {
5507
5515
  }
5508
5516
  return this;
5509
5517
  };
5518
+ RemoteVideoTrack.prototype._unObservePip = function (el) {
5519
+ var pipCallbacks = this._elToPipCallbacks.get(el);
5520
+ if (pipCallbacks) {
5521
+ el.removeEventListener('enterpictureinpicture', pipCallbacks.onEnterPip);
5522
+ el.removeEventListener('leavepictureinpicture', pipCallbacks.onLeavePip);
5523
+ this._elToPipCallbacks.delete(el);
5524
+ }
5525
+ };
5526
+ RemoteVideoTrack.prototype._observePip = function (el) {
5527
+ var _this = this;
5528
+ var pipCallbacks = this._elToPipCallbacks.get(el);
5529
+ if (!pipCallbacks) {
5530
+ var onEnterPip = function (event) { return _this._onEnterPip(event, el); };
5531
+ var onLeavePip = function (event) { return _this._onLeavePip(event, el); };
5532
+ var onResizePip = function (event) { return _this._onResizePip(event, el); };
5533
+ el.addEventListener('enterpictureinpicture', onEnterPip);
5534
+ el.addEventListener('leavepictureinpicture', onLeavePip);
5535
+ this._elToPipCallbacks.set(el, { onEnterPip: onEnterPip, onLeavePip: onLeavePip, onResizePip: onResizePip });
5536
+ }
5537
+ };
5538
+ RemoteVideoTrack.prototype._onEnterPip = function (event, videoEl) {
5539
+ this._log.debug('onEnterPip');
5540
+ var pipWindow = event.pictureInPictureWindow;
5541
+ this._elToPipWindows.set(videoEl, pipWindow);
5542
+ var onResizePip = this._elToPipCallbacks.get(videoEl).onResizePip;
5543
+ pipWindow.addEventListener('resize', onResizePip);
5544
+ maybeUpdateEnabledHint(this);
5545
+ };
5546
+ RemoteVideoTrack.prototype._onLeavePip = function (event, videoEl) {
5547
+ this._log.debug('onLeavePip');
5548
+ this._elToPipWindows.delete(videoEl);
5549
+ var onResizePip = this._elToPipCallbacks.get(videoEl).onResizePip;
5550
+ var pipWindow = event.pictureInPictureWindow;
5551
+ pipWindow.removeEventListener('resize', onResizePip);
5552
+ maybeUpdateEnabledHint(this);
5553
+ };
5554
+ RemoteVideoTrack.prototype._onResizePip = function () {
5555
+ maybeUpdateDimensionHint(this);
5556
+ };
5510
5557
  RemoteVideoTrack.prototype.attach = function (el) {
5511
5558
  var result = _super.prototype.attach.call(this, el);
5512
5559
  if (this._clientTrackSwitchOffControl === 'auto') {
@@ -5519,6 +5566,7 @@ var RemoteVideoTrack = /** @class */ (function (_super) {
5519
5566
  if (this._enableDocumentVisibilityTurnOff) {
5520
5567
  this._documentVisibilityTurnOffCleanup = this._documentVisibilityTurnOffCleanup || setupDocumentVisibilityTurnOff(this);
5521
5568
  }
5569
+ this._observePip(result);
5522
5570
  return result;
5523
5571
  };
5524
5572
  RemoteVideoTrack.prototype.detach = function (el) {
@@ -5529,6 +5577,7 @@ var RemoteVideoTrack = /** @class */ (function (_super) {
5529
5577
  _this._intersectionObserver.unobserve(element);
5530
5578
  _this._resizeObserver.unobserve(element);
5531
5579
  _this._invisibleElements.delete(element);
5580
+ _this._unObservePip(element);
5532
5581
  });
5533
5582
  if (this._attachments.size === 0) {
5534
5583
  if (this._documentVisibilityTurnOffCleanup) {
@@ -5627,32 +5676,39 @@ function setupDocumentVisibilityTurnOff(removeVideoTrack) {
5627
5676
  documentVisibilityMonitor.offVisibilityChange(1, onVisibilityChanged);
5628
5677
  };
5629
5678
  }
5630
- function maybeUpdateEnabledHint(removeVideoTrack) {
5631
- if (removeVideoTrack._clientTrackSwitchOffControl !== 'auto') {
5679
+ function maybeUpdateEnabledHint(remoteVideoTrack) {
5680
+ if (remoteVideoTrack._clientTrackSwitchOffControl !== 'auto') {
5632
5681
  return;
5633
5682
  }
5634
- var visibleElements = removeVideoTrack._getAllAttachedElements().filter(function (el) { return !removeVideoTrack._invisibleElements.has(el); });
5635
- var enabled = document.visibilityState === 'visible' && visibleElements.length > 0;
5683
+ var visibleElements = remoteVideoTrack._getAllAttachedElements().filter(function (el) { return !remoteVideoTrack._invisibleElements.has(el); });
5684
+ var pipWindows = remoteVideoTrack._getAllAttachedElements().filter(function (el) { return remoteVideoTrack._elToPipWindows.has(el); });
5685
+ // even when document is invisible we may have track playing in pip window.
5686
+ var enabled = pipWindows.length > 0 || (document.visibilityState === 'visible' && visibleElements.length > 0);
5636
5687
  if (enabled === true) {
5637
- removeVideoTrack._turnOffTimer.clear();
5638
- removeVideoTrack._setRenderHint({ enabled: true });
5688
+ remoteVideoTrack._turnOffTimer.clear();
5689
+ remoteVideoTrack._setRenderHint({ enabled: true });
5639
5690
  }
5640
- else if (!removeVideoTrack._turnOffTimer.isSet) {
5691
+ else if (!remoteVideoTrack._turnOffTimer.isSet) {
5641
5692
  // set the track to be turned off after some delay.
5642
- removeVideoTrack._turnOffTimer.start();
5693
+ remoteVideoTrack._turnOffTimer.start();
5643
5694
  }
5644
5695
  }
5645
- function maybeUpdateDimensionHint(removeVideoTrack) {
5646
- if (removeVideoTrack._contentPreferencesMode !== 'auto') {
5696
+ function maybeUpdateDimensionHint(remoteVideoTrack) {
5697
+ if (remoteVideoTrack._contentPreferencesMode !== 'auto') {
5647
5698
  return;
5648
5699
  }
5649
- var visibleElements = removeVideoTrack._getAllAttachedElements().filter(function (el) { return !removeVideoTrack._invisibleElements.has(el); });
5650
- if (visibleElements.length > 0) {
5651
- var _a = __read(visibleElements.sort(function (el1, el2) {
5700
+ var visibleElements = remoteVideoTrack._getAllAttachedElements().filter(function (el) { return !remoteVideoTrack._invisibleElements.has(el); });
5701
+ var pipElements = remoteVideoTrack._getAllAttachedElements().map(function (el) {
5702
+ var pipWindow = remoteVideoTrack._elToPipWindows.get(el);
5703
+ return pipWindow ? { clientHeight: pipWindow.height, clientWidth: pipWindow.width } : { clientHeight: 0, clientWidth: 0 };
5704
+ });
5705
+ var totalElements = visibleElements.concat(pipElements);
5706
+ if (totalElements.length > 0) {
5707
+ var _a = __read(totalElements.sort(function (el1, el2) {
5652
5708
  return el2.clientHeight + el2.clientWidth - el1.clientHeight - el1.clientWidth - 1;
5653
5709
  }), 1), _b = _a[0], clientHeight = _b.clientHeight, clientWidth = _b.clientWidth;
5654
5710
  var renderDimensions = { height: clientHeight, width: clientWidth };
5655
- removeVideoTrack._setRenderHint({ renderDimensions: renderDimensions });
5711
+ remoteVideoTrack._setRenderHint({ renderDimensions: renderDimensions });
5656
5712
  }
5657
5713
  }
5658
5714
  /**
@@ -11533,19 +11589,17 @@ var MediaSignaling = /** @class */ (function (_super) {
11533
11589
  var receiverPromise = this._getReceiver(id).then(function (receiver) {
11534
11590
  if (receiver.kind !== 'data') {
11535
11591
  _this._log.error('Expected a DataTrackReceiver');
11536
- throw new Error('Expected a DataTrackReceiver');
11537
11592
  }
11538
11593
  if (_this._receiverPromise !== receiverPromise) {
11539
11594
  return;
11540
11595
  }
11541
11596
  try {
11542
11597
  _this._transport = receiver.toDataTransport();
11598
+ _this.emit('ready', _this._transport);
11543
11599
  }
11544
11600
  catch (ex) {
11545
- _this._log.error('Failed to toDataTransport');
11546
- throw new Error('Failed to toDataTransport');
11601
+ _this._log.error("Failed to toDataTransport: " + ex.message);
11547
11602
  }
11548
- _this.emit('ready', _this._transport);
11549
11603
  receiver.once('close', function () { return _this._teardown(); });
11550
11604
  });
11551
11605
  this._receiverPromise = receiverPromise;
@@ -12843,7 +12897,9 @@ var PeerConnectionV2 = /** @class */ (function (_super) {
12843
12897
  log.debug("Starting ICE reconnect timeout: " + delay);
12844
12898
  this._iceReconnectTimeout.start();
12845
12899
  }
12846
- this.offer();
12900
+ this.offer().catch(function (ex) {
12901
+ log.error("offer failed in _initiateIceRestart with: " + ex.message);
12902
+ });
12847
12903
  };
12848
12904
  /**
12849
12905
  * Schedule an ICE Restart.
@@ -31275,7 +31331,7 @@ module.exports={
31275
31331
  "name": "twilio-video",
31276
31332
  "title": "Twilio Video",
31277
31333
  "description": "Twilio Video JavaScript Library",
31278
- "version": "2.18.1",
31334
+ "version": "2.18.2",
31279
31335
  "homepage": "https://twilio.com",
31280
31336
  "author": "Mark Andrus Roberts <mroberts@twilio.com>",
31281
31337
  "contributors": [
@@ -31370,7 +31426,8 @@ module.exports={
31370
31426
  "lint:js": "eslint ./lib ./test/*.js ./docker/**/*.js ./test/framework/*.js ./test/lib/*.js ./test/integration/** ./test/unit/** ",
31371
31427
  "lint:ts": "eslint ./tsdef/*.ts ./lib/**/*.ts",
31372
31428
  "lint": "npm-run-all lint:js lint:ts",
31373
- "test:unit": "npm-run-all build:es5 test:unit:js test:unit:ts",
31429
+ "printVersion": "node --version && npm --version",
31430
+ "test:unit": "npm-run-all printVersion build:es5 test:unit:js test:unit:ts",
31374
31431
  "test:unit:js": "nyc --report-dir=./coverage/js --extension=.js --include=lib/**/* --reporter=html --reporter=lcov --reporter=text mocha ./test/unit/index.js",
31375
31432
  "test:unit:ts": "nyc --report-dir=./coverage/ts --extension=.ts --include=lib/**/* --reporter=html --reporter=lcov --reporter=text mocha -r ts-node/register ./test/unit/index.ts",
31376
31433
  "test:serversiderender": "mocha ./test/serversiderender/index.js",