@srgssr/pillarbox-web 1.35.0 → 1.36.0

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.
@@ -90,7 +90,7 @@ function _toPropertyKey(t) {
90
90
  return "symbol" == typeof i ? i : i + "";
91
91
  }
92
92
 
93
- const version = "1.35.0";
93
+ const version = "1.35.1";
94
94
 
95
95
  /** @import VJSPlayer from 'video.js/dist/types/player' */
96
96
  /** @import AudioTrack from 'video.js/dist/types/tracks/audio-track' */
@@ -187,6 +187,79 @@ class Player extends vjsPlayer {
187
187
  return ranges;
188
188
  }
189
189
 
190
+ /**
191
+ * Create a floating video window always on top of other windows so that users may
192
+ * continue consuming media while they interact with other content sites, or
193
+ * applications on their device.
194
+ *
195
+ * This can use document picture-in-picture or element picture in picture
196
+ *
197
+ * Set `enableDocumentPictureInPicture` to `true` to use docPiP on a supported browser
198
+ * Else set `disablePictureInPicture` to `false` to disable elPiP on a supported browser
199
+ *
200
+ *
201
+ * @see [Spec]{@link https://w3c.github.io/picture-in-picture/}
202
+ * @see [Spec]{@link https://wicg.github.io/document-picture-in-picture/}
203
+ *
204
+ * @fires Player#enterpictureinpicture
205
+ *
206
+ * @return {Promise}
207
+ * A promise with a Picture-in-Picture window.
208
+ */
209
+ /* eslint-disable */
210
+ requestPictureInPicture() {
211
+ if (this.options_.enableDocumentPictureInPicture && window.documentPictureInPicture) {
212
+ const pipContainer = document.createElement(this.el().tagName);
213
+ pipContainer.classList = this.el().classList;
214
+ pipContainer.classList.add('vjs-pip-container');
215
+ if (this.posterImage) {
216
+ pipContainer.appendChild(this.posterImage.el().cloneNode(true));
217
+ }
218
+ if (this.titleBar) {
219
+ pipContainer.appendChild(this.titleBar.el().cloneNode(true));
220
+ }
221
+ pipContainer.appendChild(videojs.dom.createEl('p', {
222
+ className: 'vjs-pip-text'
223
+ }, {}, this.localize('Playing in picture-in-picture')));
224
+ return window.documentPictureInPicture.requestWindow({
225
+ // The aspect ratio won't be correct, Chrome bug https://crbug.com/1407629
226
+ width: this.videoWidth(),
227
+ height: this.videoHeight()
228
+ }).then(pipWindow => {
229
+ videojs.dom.copyStyleSheetsToWindow(pipWindow);
230
+ this.el_.parentNode.insertBefore(pipContainer, this.el_);
231
+ pipWindow.document.body.appendChild(this.el_);
232
+ pipWindow.document.body.classList.add('vjs-pip-window');
233
+ this.player_.isInPictureInPicture(true);
234
+ this.player_.trigger({
235
+ type: 'enterpictureinpicture',
236
+ pipWindow
237
+ });
238
+
239
+ // Listen for the PiP closing event to move the video back.
240
+ pipWindow.addEventListener('pagehide', event => {
241
+ console.log(event.target);
242
+ const pipVideo = event.target.querySelector('.vjs-v8');
243
+ pipContainer.parentNode.replaceChild(pipVideo, pipContainer);
244
+ this.player_.isInPictureInPicture(false);
245
+ this.player_.trigger('leavepictureinpicture');
246
+ });
247
+ return pipWindow;
248
+ });
249
+ }
250
+ if ('pictureInPictureEnabled' in document && this.disablePictureInPicture() === false) {
251
+ /**
252
+ * This event fires when the player enters picture in picture mode
253
+ *
254
+ * @event Player#enterpictureinpicture
255
+ * @type {Event}
256
+ */
257
+ return this.techGet_('requestPictureInPicture');
258
+ }
259
+ return Promise.reject('No PiP mode is available');
260
+ }
261
+ /* eslint-enable */
262
+
190
263
  /**
191
264
  * Get the percent (as a decimal) of the media that's been played.
192
265
  * This method is not a part of the native HTML video API.
@@ -451,6 +524,45 @@ class AudioTrackButton extends VJSAudioTrackButton {
451
524
  videojs.registerComponent('AudioTrackMenuItem', AudioTrackMenuItem);
452
525
  videojs.registerComponent('AudioTrackButton', AudioTrackButton);
453
526
 
527
+ /**
528
+ * @ignore
529
+ */
530
+ const VJSPictureInPictureToggle = videojs.getComponent('PictureInPictureToggle');
531
+ class PictureInPictureToggle extends VJSPictureInPictureToggle {
532
+ /**
533
+ * Displays or hides the button depending on the audio mode detection.
534
+ * Exits picture-in-picture if it is enabled when switching to audio mode.
535
+ */
536
+ /* eslint-disable */
537
+ handlePictureInPictureAudioModeChange() {
538
+ // This audio detection will not detect HLS or DASH audio-only streams because there was no reliable way to detect them at the time
539
+ const isSourceAudio = this.player_.currentType().substring(0, 5) === 'audio';
540
+ const isAudioMode = isSourceAudio || this.player_.audioPosterMode() || this.player_.audioOnlyMode();
541
+ if (!isAudioMode || this.player_.options_.enableDocumentPictureInPicture && 'documentPictureInPicture' in window) {
542
+ this.show();
543
+ return;
544
+ }
545
+ if (this.player_.isInPictureInPicture()) {
546
+ this.player_.exitPictureInPicture();
547
+ }
548
+ this.hide();
549
+ }
550
+ /* eslint-enable */
551
+
552
+ /**
553
+ * Show the `Component`s element if it is hidden by removing the
554
+ * 'vjs-hidden' class name from it only in browsers that support the Picture-in-Picture API.
555
+ */
556
+ show() {
557
+ // Does not allow to display the pictureInPictureToggle in browsers that do not support the Picture-in-Picture or DocumentPictureInPicture API.
558
+ if (typeof document.exitPictureInPicture !== 'function' && !(this.player_.options_.enableDocumentPictureInPicture && 'documentPictureInPicture' in window)) {
559
+ return;
560
+ }
561
+ this.removeClass('vjs-hidden');
562
+ }
563
+ }
564
+ videojs.registerComponent('PictureInPictureToggle', PictureInPictureToggle);
565
+
454
566
  /**
455
567
  * Pillarbox is an alias for the video.js namespace with additional options.
456
568
  *
@@ -2309,7 +2421,7 @@ class PillarboxMonitoring {
2309
2421
 
2310
2422
  // Calculate the position timestamp from the start date on Safari
2311
2423
  if (pillarbox.browser.IS_ANY_SAFARI) {
2312
- const startDate = Date.parse(this.player.$('video').getStartDate());
2424
+ const startDate = Date.parse(this.player.tech(true).el().getStartDate());
2313
2425
  position_timestamp = !isNaN(startDate) ? startDate + position : undefined;
2314
2426
  }
2315
2427
  return {