senza-sdk 4.4.7 → 4.4.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "senza-sdk",
3
- "version": "4.4.7",
3
+ "version": "4.4.9",
4
4
  "main": "./src/api.js",
5
5
  "description": "API for Senza application",
6
6
  "license": "MIT",
@@ -20,6 +20,7 @@ let authToken;
20
20
 
21
21
  const API_VERSION = "1.0";
22
22
  let interfaceVersion;
23
+ let uiReadyHasBeenCalled = false;
23
24
 
24
25
  /** @namespace auth
25
26
  *@example
@@ -262,6 +263,7 @@ export function isRunningE2E() {
262
263
 
263
264
  /** Call this API once after application startup, when the ui is ready to accept keys/events */
264
265
  export function uiReady() {
266
+ uiReadyHasBeenCalled = true;
265
267
  if (window.cefQuery) {
266
268
  window.cefQuery({
267
269
  request: "uiReady",
@@ -278,6 +280,13 @@ export function uiReady() {
278
280
  }
279
281
  }
280
282
 
283
+ /**
284
+ * @private
285
+ */
286
+ export function _isUiReady() {
287
+ return uiReadyHasBeenCalled;
288
+ }
289
+
281
290
  import "./devHelper.js";
282
291
 
283
292
  /**
@@ -1,5 +1,5 @@
1
1
  import { Lifecycle as LifecycleInterface } from "../interface/lifecycle.js";
2
- import { getPlatformInfo } from "./api.js";
2
+ import { getPlatformInfo, _isUiReady } from "./api.js";
3
3
  import { alarmManager } from "./alarmManager.js";
4
4
  import {
5
5
  getFCID,
@@ -108,6 +108,8 @@ class Lifecycle extends LifecycleInterface {
108
108
  */
109
109
  this._isSuspendTriggeredByTimer = false;
110
110
 
111
+ this._isInTransitionToSuspended = false;
112
+
111
113
  }
112
114
 
113
115
  /**
@@ -705,7 +707,6 @@ class Lifecycle extends LifecycleInterface {
705
707
  return this._inTransitionToForeground || this._inTransitionToBackground || this._inTransitionToStandby;
706
708
  }
707
709
 
708
-
709
710
  getState() {
710
711
  if (window.cefQuery) {
711
712
  return new Promise((resolve, reject) => {
@@ -727,6 +728,13 @@ class Lifecycle extends LifecycleInterface {
727
728
  }
728
729
 
729
730
  moveToForeground() {
731
+ if (!_isUiReady()) {
732
+ sdkLogger.warn("lifecycle moveToForeground: UI is not ready yet. Make sure to call senza.uiReady() before calling lifecycle.moveToForeground()");
733
+ }
734
+ if (this._isInTransitionToSuspended) {
735
+ sdkLogger.error("lifecycle moveToForeground: Currently in transition to suspend, cannot move to foreground");
736
+ return Promise.resolve(false);
737
+ }
730
738
  // Reset activity timestamp when moving to foreground
731
739
  this._lastActivityTimestamp = Date.now();
732
740
 
@@ -911,7 +919,10 @@ class Lifecycle extends LifecycleInterface {
911
919
  }
912
920
 
913
921
  moveToBackground(isTriggeredByTimer = false) {
914
-
922
+ if (this._isInTransitionToSuspended) {
923
+ sdkLogger.error("lifecycle moveToBackground: Currently in transition to suspend, cannot move to background");
924
+ return Promise.resolve(false);
925
+ }
915
926
  // If the background transition is triggered by the auto background timer, set the flag
916
927
  this._isBackgroundTriggeredByTimer = isTriggeredByTimer;
917
928
 
@@ -1073,6 +1084,7 @@ class Lifecycle extends LifecycleInterface {
1073
1084
  return Promise.reject(errorMsg);
1074
1085
  }
1075
1086
 
1087
+ this._isInTransitionToSuspended = true;
1076
1088
  // Report metrics for time between background and suspend
1077
1089
  const duration = (Date.now() - this._backgroundTimestamp) / 1000;
1078
1090
 
@@ -1109,6 +1121,7 @@ class Lifecycle extends LifecycleInterface {
1109
1121
  resolve(true);
1110
1122
  },
1111
1123
  onFailure: (code, msg) => {
1124
+ this._isInTransitionToSuspended = false;
1112
1125
  logger.error(`moveToSuspended failed: ${code} ${msg}`);
1113
1126
  reject(new SenzaError(code, msg));
1114
1127
  }
@@ -15,7 +15,7 @@ import {
15
15
  isAppVersionAboveOrEqual
16
16
  } from "./utils";
17
17
  import { lifecycle } from "./lifecycle";
18
- import { writeLicenseResponse } from "./api";
18
+ import { writeLicenseResponse, _isUiReady } from "./api";
19
19
  import { mergeAutoTranslationLanguages } from "./subtitlesUtils";
20
20
 
21
21
  // This is the delay we wait for to detect if the web application is seeking multiple times
@@ -736,6 +736,9 @@ class RemotePlayer extends RemotePlayerInterface {
736
736
  *
737
737
  * */
738
738
  async load(url, position) {
739
+ if (!_isUiReady()) {
740
+ sdkLogger.warn("remotePlayer load: UI is not ready yet. Make sure to call senza.uiReady() before calling remotePlayer.load()");
741
+ }
739
742
  return this._load(url, position);
740
743
  }
741
744
 
@@ -942,6 +945,9 @@ class RemotePlayer extends RemotePlayerInterface {
942
945
  * @throws {RemotePlayerError} error object contains code & msg
943
946
  */
944
947
  play(autoTune = false) {
948
+ if (!_isUiReady()) {
949
+ sdkLogger.warn("remotePlayer play: UI is not ready yet. Make sure to call senza.uiReady() before calling remotePlayer.play()");
950
+ }
945
951
  if (!this._isInitialized) {
946
952
  throw new RemotePlayerError(6500, "Cannot call play() if remote player is not initialized");
947
953
  }
@@ -16,9 +16,9 @@ import {
16
16
  /**
17
17
  * @event Lifecycle#beforestatechange
18
18
  * @description Fired before transitioning to a new state. This event is cancelable.<br>
19
- * Currently only fired when transitioning to BACKGROUND state (e.g., from autoBackground feature).<br>
19
+ * Currently only fired when transitioning to BACKGROUND and SUSPENDED state (e.g., from autoBackground feature).<br>
20
20
  * The actual state transition will occur after all event listeners have completed processing.
21
- * Can be used to prevent automatic transitions to background state when using autoBackground feature.
21
+ * Can be used to prevent automatic transitions to background state when using autoBackground feature, or for suspneded from autoSuspended feature .
22
22
  * @property {UiState} state - Indicates the target state the lifecycle is trying to transition to.
23
23
  * @property {boolean} cancelable - true, indicating the event can be cancelled using preventDefault()
24
24
  * @example
@@ -87,13 +87,15 @@ class Lifecycle extends EventTarget {
87
87
  * @property {string} IN_TRANSITION_TO_FOREGROUND - ui is about to be displayed
88
88
  * @property {string} BACKGROUND - remote player is playing (full screen playback is displayed)
89
89
  * @property {string} IN_TRANSITION_TO_BACKGROUND - remote player is about to be playing
90
+ * @property {string} SUSPENDED - application is suspended. This state is used for the beforestatechange event only.
90
91
  */
91
92
  UiState = Object.freeze({
92
93
  UNKNOWN: "unknown",
93
94
  FOREGROUND: "foreground",
94
95
  IN_TRANSITION_TO_FOREGROUND: "inTransitionToForeground",
95
96
  BACKGROUND: "background",
96
- IN_TRANSITION_TO_BACKGROUND: "inTransitionToBackground"
97
+ IN_TRANSITION_TO_BACKGROUND: "inTransitionToBackground",
98
+ SUSPENDED: "suspended"
97
99
  });
98
100
 
99
101
  /**
@@ -1 +1 @@
1
- export const version = "4.4.7";
1
+ export const version = "4.4.9";