senza-sdk 4.2.32 → 4.2.34
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/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/api.js +2 -0
- package/src/lifecycle.js +84 -11
- package/src/remotePlayer.js +7 -1
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -174,6 +174,8 @@ export async function init() {
|
|
|
174
174
|
triggerEvent.data = { eventName: originalTriggerEvent.eventName, payload: originalTriggerEvent.payload };
|
|
175
175
|
} else if (triggerEvent.type === "videoPlaybackEvent") {
|
|
176
176
|
triggerEvent.data = { eventCode: originalTriggerEvent.eventCode, errorCode: originalTriggerEvent.errorCode };
|
|
177
|
+
} else if (triggerEvent.type === "getLicense") {
|
|
178
|
+
sdkLogger.info("The license request is available on the license-request event which is triggered after uiReady is called");
|
|
177
179
|
}
|
|
178
180
|
} catch (e) {
|
|
179
181
|
sdkLogger.error(`failed to parse trigger event string ${triggerEventStr}: ${e.message}`);
|
package/src/lifecycle.js
CHANGED
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
import { sessionInfo } from "./SessionInfo";
|
|
13
13
|
import { DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT, remotePlayer } from "./remotePlayer";
|
|
14
14
|
|
|
15
|
+
// Default values for autoBackground settings. These values are used if the UIStreamer settings are not provided.
|
|
16
|
+
const DEFAULT_AUTO_BACKGROUND_VIDEO_DELAY = 30;
|
|
17
|
+
const DEFAULT_AUTO_BACKGROUND_UI_DELAY = -1;
|
|
18
|
+
const DEFAULT_AUTO_BACKGROUND_ENABLED = false;
|
|
19
|
+
|
|
15
20
|
/**
|
|
16
21
|
* Lifecycle is a singleton class that manages the application lifecycle states.<br>
|
|
17
22
|
* @fires onstatechange
|
|
@@ -69,13 +74,19 @@ class Lifecycle extends EventTarget {
|
|
|
69
74
|
* @type {boolean}
|
|
70
75
|
* @private
|
|
71
76
|
*/
|
|
72
|
-
this._autoBackground =
|
|
77
|
+
this._autoBackground = DEFAULT_AUTO_BACKGROUND_ENABLED;
|
|
73
78
|
|
|
74
79
|
/**
|
|
75
80
|
* @type {integer}
|
|
76
81
|
* @private
|
|
77
82
|
*/
|
|
78
|
-
this.
|
|
83
|
+
this._autoBackgroundOnVideoDelay = DEFAULT_AUTO_BACKGROUND_VIDEO_DELAY;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @type {integer}
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
this._autoBackgroundOnUIDelay = DEFAULT_AUTO_BACKGROUND_UI_DELAY;
|
|
79
90
|
|
|
80
91
|
typeof document !== "undefined" && document.addEventListener("hs/uistatechange", (e) => {
|
|
81
92
|
sdkLogger.log("Got hs/uistatechange", e.detail);
|
|
@@ -105,9 +116,24 @@ class Lifecycle extends EventTarget {
|
|
|
105
116
|
}
|
|
106
117
|
}
|
|
107
118
|
});
|
|
119
|
+
|
|
120
|
+
// Add playModeChange listener
|
|
121
|
+
remotePlayer.addEventListener("playModeChange", (event) => {
|
|
122
|
+
if (this._autoBackground && this.state === this.UiState.FOREGROUND) {
|
|
123
|
+
sdkLogger.log("Resetting auto background timer due to play mode change", event.detail.isPlaying);
|
|
124
|
+
this._startCountdown(event.detail.isPlaying);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
108
127
|
}
|
|
109
128
|
|
|
110
129
|
/** @private Initialize the lifecycle
|
|
130
|
+
* @param {Object} uiStreamerSettings - UI-streamer portion of the settings taken from session info
|
|
131
|
+
* @param {Object} [uiStreamerSettings.autoBackground] - Auto background mode configuration
|
|
132
|
+
* @param {boolean} [uiStreamerSettings.autoBackground.enable=false] - Whether auto background mode is enabled
|
|
133
|
+
* @param {number} [uiStreamerSettings.autoBackground.onVideoDelay=30] - Seconds of inactivity before moving to background while playing video
|
|
134
|
+
* @param {number} [uiStreamerSettings.autoBackground.onUIDelay=30] - Seconds of inactivity before moving to background while in UI (not playing)
|
|
135
|
+
* @param {number} [uiStreamerSettings.remotePlayerConfirmationTimeout=5000] - Timeout in milliseconds for remote player operations
|
|
136
|
+
* @param {number} [uiStreamerSettings.remotePlayerApiVersion=1] - Remote player API version
|
|
111
137
|
*/
|
|
112
138
|
async _init(uiStreamerSettings) {
|
|
113
139
|
if (window.cefQuery) {
|
|
@@ -128,6 +154,21 @@ class Lifecycle extends EventTarget {
|
|
|
128
154
|
this._isInitialized = true;
|
|
129
155
|
this._remotePlayerConfirmationTimeout = uiStreamerSettings?.remotePlayerConfirmationTimeout ?? DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT;
|
|
130
156
|
this._remotePlayerApiVersion = uiStreamerSettings?.remotePlayerApiVersion || 1;
|
|
157
|
+
|
|
158
|
+
// Take autoBackground settings from uiStreamerSettings if available
|
|
159
|
+
// The UI setting section format :
|
|
160
|
+
// "autoBackground": {
|
|
161
|
+
// "enable": true,
|
|
162
|
+
// "onVideoDelay": 30,
|
|
163
|
+
// "onUIDelay": 30
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
this._autoBackgroundOnVideoDelay = uiStreamerSettings?.autoBackground?.onVideoDelay ?? this._autoBackgroundOnVideoDelay;
|
|
167
|
+
this._autoBackgroundOnUIDelay = uiStreamerSettings?.autoBackground?.onUIDelay ?? this._autoBackgroundOnUIDelay;
|
|
168
|
+
this._autoBackground = uiStreamerSettings?.autoBackground?.enable ?? this._autoBackground;
|
|
169
|
+
/*if (this._autoBackground) {
|
|
170
|
+
this._startCountdown();
|
|
171
|
+
}*/
|
|
131
172
|
}
|
|
132
173
|
}
|
|
133
174
|
|
|
@@ -177,7 +218,10 @@ class Lifecycle extends EventTarget {
|
|
|
177
218
|
|
|
178
219
|
/**
|
|
179
220
|
* Controls the autoBackground feature<br>
|
|
180
|
-
* When enabled, the application will automatically move to the background state after
|
|
221
|
+
* When enabled, the application will automatically move to the background state after a configurable
|
|
222
|
+
* period of inactivity. The delay depends on whether video is playing ({@link Lifecycle#autoBackgroundDelay})
|
|
223
|
+
* or the UI is idle ({@link Lifecycle#autoBackgroundOnUIDelay}).
|
|
224
|
+
* The application will return to the foreground state when a key is pressed.
|
|
181
225
|
* @type {boolean}
|
|
182
226
|
*/
|
|
183
227
|
set autoBackground(enabled) {
|
|
@@ -194,30 +238,58 @@ class Lifecycle extends EventTarget {
|
|
|
194
238
|
}
|
|
195
239
|
|
|
196
240
|
/**
|
|
197
|
-
*
|
|
241
|
+
* The number of seconds of user inactivity before the application moves to the background state while playing video.
|
|
242
|
+
* This setting is used when remotePlayer is in playing state.
|
|
198
243
|
* @type {integer}
|
|
199
244
|
* @default 30
|
|
200
245
|
*/
|
|
201
246
|
set autoBackgroundDelay(delay) {
|
|
202
|
-
this.
|
|
247
|
+
this._autoBackgroundOnVideoDelay = delay;
|
|
203
248
|
|
|
204
|
-
if (this.autoBackground) {
|
|
249
|
+
if (this.autoBackground && remotePlayer._isPlaying) {
|
|
250
|
+
this._startCountdown();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The number of seconds of user inactivity before the application moves to the background state while in the UI (not playing).
|
|
256
|
+
* This setting is used when remotePlayer is not in playing state.
|
|
257
|
+
* @type {integer}
|
|
258
|
+
* @default 30
|
|
259
|
+
*/
|
|
260
|
+
set autoBackgroundOnUIDelay(delay) {
|
|
261
|
+
this._autoBackgroundOnUIDelay = delay;
|
|
262
|
+
|
|
263
|
+
if (this.autoBackground && !remotePlayer._isPlaying) {
|
|
205
264
|
this._startCountdown();
|
|
206
265
|
}
|
|
207
266
|
}
|
|
208
267
|
|
|
209
268
|
get autoBackgroundDelay() {
|
|
210
|
-
return this.
|
|
269
|
+
return this._autoBackgroundOnVideoDelay;
|
|
211
270
|
}
|
|
212
271
|
|
|
272
|
+
get autoBackgroundOnUIDelay() {
|
|
273
|
+
return this._autoBackgroundOnUIDelay;
|
|
274
|
+
}
|
|
213
275
|
/**
|
|
214
276
|
* @private
|
|
215
277
|
*/
|
|
216
|
-
_startCountdown() {
|
|
278
|
+
_startCountdown(isPlaying = remotePlayer._isPlaying) {
|
|
217
279
|
this._stopCountdown();
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
280
|
+
|
|
281
|
+
const timeoutDelay = isPlaying ? this._autoBackgroundOnVideoDelay : this._autoBackgroundOnUIDelay;
|
|
282
|
+
sdkLogger.debug("Starting countdown timeout", timeoutDelay, isPlaying ? "(video)" : "(UI)");
|
|
283
|
+
|
|
284
|
+
// Only start countdown if delay is positive
|
|
285
|
+
if (timeoutDelay > 0) {
|
|
286
|
+
this._countdown = setTimeout(() => {
|
|
287
|
+
sdkLogger.debug("Countdown timeout reached, moving to background");
|
|
288
|
+
this.moveToBackground();
|
|
289
|
+
}, timeoutDelay * 1000);
|
|
290
|
+
} else {
|
|
291
|
+
sdkLogger.debug("Countdown not started - delay is negative or zero");
|
|
292
|
+
}
|
|
221
293
|
}
|
|
222
294
|
|
|
223
295
|
/**
|
|
@@ -225,6 +297,7 @@ class Lifecycle extends EventTarget {
|
|
|
225
297
|
*/
|
|
226
298
|
_stopCountdown() {
|
|
227
299
|
if (this._countdown) {
|
|
300
|
+
sdkLogger.debug("Stopping countdown timer");
|
|
228
301
|
clearTimeout(this._countdown);
|
|
229
302
|
}
|
|
230
303
|
this._countdown = null;
|
package/src/remotePlayer.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import {
|
|
3
2
|
getFCID,
|
|
4
3
|
isAudioSyncEnabled,
|
|
@@ -552,6 +551,13 @@ class RemotePlayer extends EventTarget {
|
|
|
552
551
|
|
|
553
552
|
/** @private change the internal load mode and store the new mode in session storage */
|
|
554
553
|
_changePlayMode(newPlayMode) {
|
|
554
|
+
if (this._isPlaying !== newPlayMode) {
|
|
555
|
+
// Create event with play mode detail
|
|
556
|
+
const event = new CustomEvent("playModeChange", {
|
|
557
|
+
detail: { isPlaying: newPlayMode }
|
|
558
|
+
});
|
|
559
|
+
this.dispatchEvent(event);
|
|
560
|
+
}
|
|
555
561
|
this._isPlaying = newPlayMode;
|
|
556
562
|
window?.sessionStorage?.setItem("senzaSdk_isPlaying", String(newPlayMode));
|
|
557
563
|
}
|