senza-sdk 4.3.1-4a01fcf.0 → 4.3.1-ca3d96f.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.
@@ -1,4 +1,4 @@
1
- import { shaka } from "../interface/senzaShakaPlayer";
1
+ import { SenzaShakaPlayer as SenzaShakaInterface, shaka } from "../interface/senzaShakaPlayer";
2
2
 
3
3
  import { remotePlayer, lifecycle, getPlatformInfo } from "./api";
4
4
  import { sdkLogger, iso6393to1 } from "./utils";
@@ -33,26 +33,7 @@ class SenzaError extends shaka.util.Error {
33
33
  }
34
34
 
35
35
 
36
- /**
37
- * SenzaShakaPlayer subclass of Shaka that handles both local and remote playback.
38
- *
39
- * @class SenzaShakaPlayer
40
- *
41
- * @example
42
- * import { SenzaShakaPlayer } from "./senzaShakaPlayer.js";
43
- *
44
- * try {
45
- * const videoElement = document.getElementById("video");
46
- * const player = new SenzaShakaPlayer(videoElement);
47
- * await player.load("http://playable.url/file.mpd");
48
- * await videoElement.play(); // will start the playback
49
- *
50
- * } catch (err) {
51
- * console.error("SenzaShakaPlayer failed with error", err);
52
- * }
53
- */
54
-
55
- export class SenzaShakaPlayer extends shaka.Player {
36
+ export class SenzaShakaPlayer extends SenzaShakaInterface {
56
37
  /** @private {SenzaShakaPlayer|null} Previous instance of the player */
57
38
  static _prevInstance = null;
58
39
 
@@ -137,7 +118,7 @@ export class SenzaShakaPlayer extends shaka.Player {
137
118
  });
138
119
  }
139
120
  },
140
- "pause" : () => {
121
+ "pause": () => {
141
122
  this._resetPlayPromise();
142
123
  this.remotePlayer.pause()
143
124
  .catch(error => {
@@ -342,14 +323,6 @@ export class SenzaShakaPlayer extends shaka.Player {
342
323
  return undefined;
343
324
  }
344
325
 
345
- /**
346
- * Creates an instance of SenzaShakaPlayer, which is a subclass of shaka.Player.
347
- *
348
- * @param {HTMLVideoElement} videoElement - The video element to be used for local playback. This parameter is optional. If not provided, the video element can be attached later using the attach method.
349
- * @param {HTMLElement=} videoContainer - The videoContainer to construct UITextDisplayer
350
- * @param {function(shaka.Player)=} dependencyInjector Optional callback
351
- * which is called to inject mocks into the Player. Used for testing.
352
- */
353
326
  constructor(videoElement, videoContainer, dependencyInjector) {
354
327
  super(videoElement, videoContainer, dependencyInjector);
355
328
 
@@ -367,7 +340,7 @@ export class SenzaShakaPlayer extends shaka.Player {
367
340
  this._addRemotePlayerEventListeners();
368
341
  SenzaShakaPlayer._prevInstance = this;
369
342
  const playTimeout = getPlatformInfo()?.sessionInfo?.settings?.["ui-streamer"]?.playingEventTimeout;
370
- this._playingTimeout = (playTimeout >= 0) ? playTimeout*1000 : this._playingTimeout;
343
+ this._playingTimeout = (playTimeout >= 0) ? playTimeout * 1000 : this._playingTimeout;
371
344
 
372
345
  // Initialize minSuggestedPresentationDelay from UI settings or use default
373
346
  const uiSettings = getPlatformInfo()?.sessionInfo?.settings?.["ui-streamer"];
@@ -447,27 +420,11 @@ export class SenzaShakaPlayer extends shaka.Player {
447
420
  this._attachVideoElementToRemotePlayer();
448
421
  }
449
422
 
450
- /**
451
- * Overrides the attach method of shaka.Player to attach the video element.
452
- *
453
- * @param {HTMLVideoElement} videoElement - The video element to be used for local playback.
454
- * @param {boolean} [initializeMediaSource=true] - Whether to initialize the media source.
455
- */
456
423
  async attach(videoElement, initializeMediaSource = true) {
457
424
  await super.attach(videoElement, initializeMediaSource);
458
425
  this._attach(videoElement);
459
426
  }
460
427
 
461
- /**
462
- * Detach the player from the current media element. Leaves the player in a
463
- * state where it cannot play media, until it has been attached to something
464
- * else.
465
- *
466
- * @param {boolean=} keepAdManager
467
- *
468
- * @return {!Promise}
469
- * @export
470
- */
471
428
  async detach(keepAdManager = false) {
472
429
  // Clear any pending timeout
473
430
  this._resetPlayPromise();
@@ -498,14 +455,6 @@ export class SenzaShakaPlayer extends shaka.Player {
498
455
  this.videoElement = null;
499
456
  }
500
457
 
501
- /**
502
- * Unloads the currently playing stream, if any.
503
- *
504
- * @param {boolean=} initializeMediaSource
505
- * @param {boolean=} keepAdManager
506
- * @return {!Promise}
507
- * @export
508
- */
509
458
  async unload(initializeMediaSource = true, keepAdManager = false) {
510
459
  // Call the remote player's unload method
511
460
  try {
@@ -520,27 +469,14 @@ export class SenzaShakaPlayer extends shaka.Player {
520
469
  await super.unload(initializeMediaSource, keepAdManager);
521
470
  }
522
471
 
523
- /**
524
- * Overrides the getTextTracks method to use the remote player's text tracks.
525
- * @returns {Array} An array of text tracks.
526
- */
527
472
  getTextLanguages() {
528
473
  return Object.keys(this._textTracksMap);
529
474
  }
530
475
 
531
- /**
532
- * Overrides the getAudioTracks method to use the remote player's audio tracks.
533
- * @returns {Array} An array of audio tracks.
534
- */
535
476
  getAudioLanguages() {
536
477
  return Object.keys(this._audioTracksMap);
537
478
  }
538
479
 
539
- /**
540
- * Overrides the selectAudioLanguage method to use the remote player's audio track selection.
541
- * @param {string} language - The language to select.
542
- * @param {string=} role - The role of the track to select. (e.g. 'main', 'caption', or 'commentary')
543
- */
544
480
  selectAudioLanguage(language, role) {
545
481
  sdkLogger.log("Selecting audio language:", language, "with role: ", role);
546
482
  if (this._audioTracksMap[language]) {
@@ -551,11 +487,6 @@ export class SenzaShakaPlayer extends shaka.Player {
551
487
  super.selectAudioLanguage(language, role);
552
488
  }
553
489
 
554
- /**
555
- * Overrides the selectTextLanguage method to use the remote player's text track selection.
556
- * @param {string} language - The language to select.
557
- * @param {string=} role - The role of the track to select.
558
- */
559
490
  selectTextLanguage(language, role) {
560
491
  sdkLogger.log("Selecting text language:", language, "with role:", role);
561
492
  if (this._textTracksMap[language]) {
@@ -566,20 +497,12 @@ export class SenzaShakaPlayer extends shaka.Player {
566
497
  super.selectTextLanguage(language, role);
567
498
  }
568
499
 
569
- /**
570
- * Overrides the setTextTrackVisibility method to use the remote player's text track visibility settings.
571
- * @param {boolean} visible - Whether the text tracks should be visible.
572
- */
573
500
  setTextTrackVisibility(visible) {
574
501
  sdkLogger.log("Setting text track visibility to:", visible);
575
502
  remotePlayer.setTextTrackVisibility(visible);
576
503
  super.setTextTrackVisibility(visible);
577
504
  }
578
505
 
579
- /**
580
- * Helper function that makes it easier to check if lifecycle.state is
581
- * either background or inTransitionToBackground.
582
- */
583
506
  get isInRemotePlayback() {
584
507
  return lifecycle.state === lifecycle.UiState.BACKGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_BACKGROUND;
585
508
  }
@@ -645,12 +568,6 @@ export class SenzaShakaPlayer extends shaka.Player {
645
568
  this.dispatchEvent(new shaka.util.FakeEvent("error", errorMap));
646
569
  }
647
570
 
648
- /**
649
- * Loads a media URL into both local and remote players.
650
- *
651
- * @param {string} url - The URL of the media to load.
652
- * @returns {Promise<void>}
653
- */
654
571
  async load(url, startTime, mimeType) {
655
572
 
656
573
  // Create a promise that will resolve when _remotePlayerLoad is called
@@ -737,13 +654,6 @@ export class SenzaShakaPlayer extends shaka.Player {
737
654
 
738
655
  }
739
656
 
740
- /***
741
- *
742
- * Configure the Player instance.
743
- * @param {Object} config the configuration object
744
- * @returns {Boolean}
745
- */
746
-
747
657
  async destroy() {
748
658
  await lifecycle.moveToForeground();
749
659
  SenzaShakaPlayer._prevInstance = null;
@@ -751,10 +661,6 @@ export class SenzaShakaPlayer extends shaka.Player {
751
661
  return super.destroy();
752
662
  }
753
663
 
754
- /**
755
- * A temporary override for older versions of Shaka.
756
- * Senza doesn't support out-of-band subtitles
757
- */
758
664
  addTextTrack(uri, language, kind, mimeType, codec, label, forced = false) {
759
665
  sdkLogger.warn("addTextTrack is deprecated, please use addTextTrackAsync");
760
666
  super.addTextTrackAsync(uri, language, kind, mimeType, codec, label, forced).then(subs => {
@@ -762,20 +668,6 @@ export class SenzaShakaPlayer extends shaka.Player {
762
668
  });
763
669
  }
764
670
 
765
- /**
766
- * Override the configure method to add custom configuration handling
767
- * Supports the following additional configuration options:
768
- * - shouldStopOnRemotePlayerError: boolean - If true, local player will be stopped on remote player error
769
- *
770
- * @override
771
- * @param {Object} config - Configuration object to be merged with existing config
772
- * @param {boolean} [config.shouldStopOnRemotePlayerError=true] - Whether to stop local player on remote player error
773
- * @example
774
- * player.configure({
775
- * shouldStopOnRemotePlayerError: false, // Don't stop local playback on remote player error
776
- * // ... other shaka configurations
777
- * });
778
- */
779
671
  configure(config) {
780
672
  sdkLogger.log("configure player with: ", JSON.stringify(config));
781
673
 
@@ -1,31 +1,28 @@
1
1
  import { noop } from "./utils";
2
+
3
+ /**
4
+ * alarm event
5
+ *
6
+ * @event AlarmManager#MyAlarm
7
+ * @description Fired when time of 'MyAlarm' arrives. If this alarm triggers the application load and the application doesn't call
8
+ * lifecycle.moveToForeground() in the alarm callback (i.e. the application remains in the background after the callback is completed),
9
+ * the application will be unloaded.
10
+ * NOTE: If you perform async operations in the callback (without moving to foreground), you must wait for the async
11
+ * operation to finish before returning from the callback, otherwise the application will be unloaded before the async operation is finished.<br>
12
+ * @example
13
+ * alarmManager.addEventListener("MyAlarm", async (e) => {
14
+ * console.log("alarm MyAlarm arrived with data", e.detail);
15
+ * await fetch("http://www.example.com");
16
+ * });
17
+ * alarmManager.addAlarm("MyAlarm", Date.now() + 60*60*1000, "MyData");
18
+ */
19
+
2
20
  /**
3
- * @class AlarmManager
4
21
  * AlarmManager is a singleton class that manages the alarms in the application. It fires events whose types are the names of the alarms.
5
22
  * @fires MyAlarm
6
23
  */
7
24
  export class AlarmManager extends EventTarget {
8
25
 
9
- /**
10
- * alarm event
11
- *
12
- * @event AlarmManager#MyAlarm
13
- * @description Fired when time of 'MyAlarm' arrives. If this alarm triggers the application load and the application doesn't call
14
- * lifecycle.moveToForeground() in the alarm callback (i.e. the application remains in the background after the callback is completed),
15
- * the application will be unloaded.
16
- * NOTE: If you perform async operations in the callback (without moving to foreground), you must wait for the async
17
- * operation to finish before returning from the callback, otherwise the application will be unloaded before the async operation is finished.<br>
18
- * @example
19
- * alarmManager.addEventListener("MyAlarm", async (e) => {
20
- * console.log("alarm MyAlarm arrived with data", e.detail);
21
- * await fetch("http://www.example.com");
22
- * });
23
- * alarmManager.addAlarm("MyAlarm", Date.now() + 60*60*1000, "MyData");
24
- */
25
- constructor() {
26
- super();
27
- }
28
-
29
26
  addEventListener(type, callback) {
30
27
  noop("AlarmManager.addEventListener", type, callback);
31
28
  }
@@ -67,3 +64,13 @@ export class AlarmManager extends EventTarget {
67
64
  return noop("AlarmManager.getActiveAlarms");
68
65
  }
69
66
  }
67
+
68
+ /**
69
+ * @module
70
+ * @type {AlarmManager}
71
+ * @example
72
+ * import { alarmManager } from "senza-sdk";
73
+ *
74
+ * @return {AlarmManager} pointer to the AlarmManager singleton
75
+ */
76
+ "needed for the module doc comment to be recognized";
@@ -1,30 +1,24 @@
1
1
  import { sdkLogger, noop } from "./utils.js";
2
2
 
3
- const wifiInfo = {};
4
-
3
+ const wifiInfo = {
4
+ level: 0,
5
+ quality: 0,
6
+ ssid: "unknown",
7
+ bssid: "unknown"
8
+ };
9
+ /**
10
+ * @deprecated Instead, call deviceManager.getWifiInfo() periodically
11
+ * @event DeviceManager#wifiInfoUpdated
12
+ * @example
13
+ * deviceManager.addEventListener("wifiInfoUpdated", () => {
14
+ * console.info("Wifi info has been updated to", deviceManager.wifiInfo);
15
+ * });
16
+ *
17
+ */
5
18
  /**
6
- * @class DeviceManager
7
19
  * DeviceManager is a singleton class that manages the device
8
20
  */
9
21
  export class DeviceManager extends EventTarget {
10
-
11
- constructor() {
12
- super();
13
- wifiInfo.level = 0;
14
- wifiInfo.quality = 0;
15
- wifiInfo.ssid = "unknown";
16
- wifiInfo.bssid = "unknown";
17
- /**
18
- * @deprecated Instead, call deviceManager.getWifiInfo() periodically
19
- * @event DeviceManager#wifiInfoUpdated
20
- * @example
21
- * deviceManager.addEventListener("wifiInfoUpdated", () => {
22
- * console.info("Wifi info has been updated to", deviceManager.wifiInfo);
23
- * });
24
- *
25
- */
26
- }
27
-
28
22
  /**
29
23
  * @property {object} DeviceInfo
30
24
  * @property {string} DeviceInfo.deviceId
@@ -131,3 +125,18 @@ export class DeviceManager extends EventTarget {
131
125
  return Promise.resolve({});
132
126
  }
133
127
  }
128
+
129
+
130
+ /**
131
+ * @module
132
+ * @type {DeviceManager}
133
+ * @example
134
+ * import { deviceManager } from "senza-sdk";
135
+ * const wifiInfo = await deviceManager.getWifiInfo();
136
+ * console.info(wifiInfo.ssid);
137
+ * await deviceManager.clearWifi();
138
+ * deviceManager.reboot();
139
+ *
140
+ * @return {DeviceManager} pointer to the DeviceManager singleton
141
+ */
142
+ "needed for the module doc comment to be recognized";
@@ -1,13 +1,42 @@
1
- /* eslint-disable no-empty-function */
2
- /* eslint-disable no-unused-vars */
3
1
  import {
4
2
  sdkLogger,
5
3
  noop
6
4
  } from "./utils.js";
5
+ /**
6
+ * @event Lifecycle#onstatechange
7
+ * @description Fired after transition from one state to another.<br>
8
+ * The flow is: foreground --> inTransitionToBackground --> background --> inTransitionToForeground --> foreground
9
+ * @property {UiState} state - Indicates the new state.
10
+ * @example
11
+ * lifecycle.addEventListener("onstatechange", (e) => {
12
+ * console.log("new state is", e.state);
13
+ * });
14
+ */
15
+
16
+ /**
17
+ * @event Lifecycle#userinactivity
18
+ * @description Fired after the ui has been inactive (i.e. no key presses) for a configurable number of seconds.<br>
19
+ * @property {number} timeout - the number of seconds after which the application will be unloaded.
20
+ * @example
21
+ * lifecycle.addEventListener("userinactivity", (e) => {
22
+ * console.log(`Application will be unloaded in ${e.timeout} seconds`);
23
+ * });
24
+ * @alpha API has not yet been released
25
+ */
26
+
27
+ /**
28
+ * @event Lifecycle#userdisconnected
29
+ * @description Fired when the user session ends .
30
+ * This event is useful for cleaning up application state or saving data before the application closes. Event callback should return promise to ensure that the event is handled before the application is terminated
31
+ * @example
32
+ * lifecycle.addEventListener("userdisconnected", () => {
33
+ * console.log("User session ended, cleaning up application state");
34
+ * // Perform any necessary cleanup here
35
+ * });
36
+ */
7
37
 
8
38
  /**
9
39
  * Lifecycle is a singleton class that manages the application lifecycle states.<br>
10
- * @class Lifecycle
11
40
  * @fires onstatechange
12
41
  * @fires userinactivity
13
42
  * @fires userdisconnected
@@ -50,42 +79,6 @@ export class Lifecycle extends EventTarget {
50
79
  IN_TRANSITION_TO_BACKGROUND: "inTransitionToBackground"
51
80
  });
52
81
 
53
- /**
54
- * @event Lifecycle#onstatechange
55
- * @description Fired after transition from one state to another.<br>
56
- * The flow is: foreground --> inTransitionToBackground --> background --> inTransitionToForeground --> foreground
57
- * @property {UiState} state - Indicates the new state.
58
- * @example
59
- * lifecycle.addEventListener("onstatechange", (e) => {
60
- * console.log("new state is", e.state);
61
- * });
62
- */
63
-
64
- /**
65
- * @event Lifecycle#userinactivity
66
- * @description Fired after the ui has been inactive (i.e. no key presses) for a configurable number of seconds.<br>
67
- * @property {number} timeout - the number of seconds after which the application will be unloaded.
68
- * @example
69
- * lifecycle.addEventListener("userinactivity", (e) => {
70
- * console.log(`Application will be unloaded in ${e.timeout} seconds`);
71
- * });
72
- * @alpha API has not yet been released
73
- */
74
-
75
- /**
76
- * @event Lifecycle#userdisconnected
77
- * @description Fired when the user session ends .
78
- * This event is useful for cleaning up application state or saving data before the application closes. Event callback should return promise to ensure that the event is handled before the application is terminated
79
- * @example
80
- * lifecycle.addEventListener("userdisconnected", () => {
81
- * console.log("User session ended, cleaning up application state");
82
- * // Perform any necessary cleanup here
83
- * });
84
- */
85
- constructor() {
86
- super();
87
- }
88
-
89
82
  /**
90
83
  * Configure lifecycle settings
91
84
  * @param {Object} config - Configuration object
@@ -96,6 +89,7 @@ export class Lifecycle extends EventTarget {
96
89
  * @param {number|false} [config.autoBackground.timeout.idle=false] - Timeout in seconds when in UI mode, false to disable
97
90
  */
98
91
  configure(config) {
92
+ noop("lifecycle.configure", config);
99
93
  }
100
94
 
101
95
  /**
@@ -276,3 +270,14 @@ export class Lifecycle extends EventTarget {
276
270
  super.removeEventListener(type, listener, options);
277
271
  }
278
272
  }
273
+
274
+
275
+ /**
276
+ * @module
277
+ * @type {Lifecycle}
278
+ * @example
279
+ * import { lifecycle } from "senza-sdk";
280
+ *
281
+ * @return {Lifecycle} pointer to the Lifecycle singleton
282
+ */
283
+ "needed for the module doc comment to be recognized";
@@ -1,39 +1,36 @@
1
1
 
2
2
  import { noop } from "./utils";
3
+
4
+ /**
5
+ * @typedef {object} MessageDetails - object which contains the content of the message
6
+ * @property {string} eventName - The name of the event message, a property of MessageDetails
7
+ * @property {object} payload - The payload for this event, a property of MessageDetails
8
+ * @property {string} fcid - The flow context for this message, a property of MessageDetails
9
+ */
10
+
11
+ /**
12
+ * message event
13
+ *
14
+ * @event MessageManager#message
15
+ * @type {CustomEvent}
16
+ * @property {MessageDetails} detail - object containing data related to the event:
17
+
18
+ *
19
+ * @description Fired when an external event arrives. This is a generic handler for all messages received for any registered group <br>
20
+ * @example
21
+ * messageManager.addEventListener("message", (e) => {
22
+ * console.log("message arrived with data", e.detail);
23
+ * });
24
+ *
25
+ */
26
+
3
27
  /**
4
28
  * MessageManager is a singleton class that manages the external messages received by the application. It fires custom events as "message" with the payload as the content
5
29
  * @class MessageManager
6
30
  * @fires MessageManager#message
7
31
  */
8
-
9
32
  export class MessageManager extends EventTarget {
10
33
 
11
- /**
12
- * @typedef {object} MessageDetails - object which contains the content of the message
13
- * @property {string} eventName - The name of the event message, a property of MessageDetails
14
- * @property {object} payload - The payload for this event, a property of MessageDetails
15
- * @property {string} fcid - The flow context for this message, a property of MessageDetails
16
- */
17
-
18
- /**
19
- * message event
20
- *
21
- * @event MessageManager#message
22
- * @type {CustomEvent}
23
- * @property {MessageDetails} detail - object containing data related to the event:
24
-
25
- *
26
- * @description Fired when an external event arrives. This is a generic handler for all messages received for any registered group <br>
27
- * @example
28
- * messageManager.addEventListener("message", (e) => {
29
- * console.log("message arrived with data", e.detail);
30
- * });
31
- *
32
- */
33
- constructor() {
34
- super();
35
- }
36
-
37
34
  /** Register to specific group(s). This function replaces the previously registered groups
38
35
  * @param {Array<String>} groups group events to receive messages.
39
36
  * @return {Promise} Promise which is resolved when the registerGroups command has been successfully processed.
@@ -44,3 +41,13 @@ export class MessageManager extends EventTarget {
44
41
  return noop("MessageManager.registerGroups", groups);
45
42
  }
46
43
  }
44
+
45
+ /**
46
+ * @module
47
+ * @type {MessageManager}
48
+ * @example
49
+ * import { MessageManager } from "senza-sdk";
50
+ *
51
+ * @return {MessageManager} pointer to the MessageManager singleton
52
+ */
53
+ "needed for the module doc comment to be recognized";
@@ -1,14 +1,9 @@
1
1
  import { noop } from "./utils";
2
2
  /**
3
- * @class PlatformManager
4
3
  * PlatformManager is a singleton class that manages the platform
5
4
  */
6
5
  export class PlatformManager extends EventTarget {
7
6
 
8
- constructor() {
9
- super();
10
- }
11
-
12
7
  /**
13
8
  * @returns {Object} appConfig object
14
9
  * @property {String[]} territories - a list of territories configured for the tenant.
@@ -33,3 +28,14 @@ export class PlatformManager extends EventTarget {
33
28
  }
34
29
  }
35
30
 
31
+ /**
32
+ * @module
33
+ * @type {PlatformManager}
34
+ * @example
35
+ * import { platformManager } from "senza-sdk";
36
+ * console.info(platformManager.appConfig);
37
+ * platformManager.setTimezone("Europe/Brussels");
38
+ *
39
+ * @return {PlatformManager} pointer to the PlatformManager singleton
40
+ */
41
+ "needed for the module doc comment to be recognized";