@srgssr/pillarbox-web 1.35.1 → 1.36.1

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.36.0";
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
  *
@@ -4092,25 +4204,23 @@ class SrgSsr {
4092
4204
  */
4093
4205
  static createTextTrack(_x5, _x6) {
4094
4206
  return _asyncToGenerator(function* (player, trackId, cues = []) {
4095
- const removeTrack = player.textTracks().getTrackById(trackId);
4207
+ const removeTrack = player.remoteTextTracks().getTrackById(trackId);
4096
4208
  if (removeTrack) {
4097
- player.textTracks().removeTrack(removeTrack);
4209
+ player.removeRemoteTextTrack(removeTrack);
4098
4210
  }
4211
+ const textTrack = player.addRemoteTextTrack({
4212
+ id: trackId,
4213
+ kind: 'metadata',
4214
+ label: trackId
4215
+ });
4216
+
4217
+ // Safari
4218
+ textTrack.track.mode = 'hidden';
4099
4219
 
4100
4220
  // See https://github.com/videojs/video.js/issues/8519
4101
- const textTrack = yield new Promise(resolve => {
4102
- setTimeout(() => {
4103
- resolve(new pillarbox.TextTrack({
4104
- id: trackId,
4105
- kind: 'metadata',
4106
- label: trackId,
4107
- tech: player.tech(true)
4108
- }));
4109
- }, 100);
4110
- });
4111
- SrgSsr.addTextTrackCues(textTrack, cues);
4112
- player.textTracks().addTrack(textTrack);
4113
- return textTrack;
4221
+ yield new Promise(resolve => setTimeout(resolve, 100));
4222
+ SrgSsr.addTextTrackCues(textTrack.track, cues);
4223
+ return textTrack.track;
4114
4224
  }).apply(this, arguments);
4115
4225
  }
4116
4226
 
@@ -4120,12 +4230,12 @@ class SrgSsr {
4120
4230
  * @param {Player} player
4121
4231
  */
4122
4232
  static cuechangeEventProxy(player) {
4123
- player.textTracks().on('addtrack', ({
4233
+ player.textTracks().on('addtrack', /** @param {{ track: TextTrack }} */({
4124
4234
  track
4125
4235
  }) => {
4126
4236
  if (!['srgssr-chapters', 'srgssr-intervals'].includes(track.id)) return;
4127
- track.on('cuechange', () => {
4128
- const [cue] = Array.from(track.activeCues);
4237
+ track.addEventListener('cuechange', () => {
4238
+ const [cue] = Array.from(track.activeCues || []);
4129
4239
  const type = track.id.includes('srgssr-chapters') ? 'srgssr/chapter' : 'srgssr/interval';
4130
4240
  player.trigger({
4131
4241
  type,
@@ -4227,7 +4337,7 @@ class SrgSsr {
4227
4337
  if (!blockedSegmentsTrack) return;
4228
4338
 
4229
4339
  /** @type {VTTCue} */
4230
- const [blockedCue] = Array.from(blockedSegmentsTrack.activeCues);
4340
+ const [blockedCue] = Array.from(blockedSegmentsTrack.activeCues || []);
4231
4341
  return blockedCue;
4232
4342
  }
4233
4343