senza-sdk 4.2.48 → 4.2.50

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.2.48",
3
+ "version": "4.2.50",
4
4
  "main": "./src/api.js",
5
5
  "description": "API for Senza application",
6
6
  "license": "MIT",
package/src/lifecycle.js CHANGED
@@ -182,9 +182,10 @@ class Lifecycle extends EventTarget {
182
182
  /** @private Initialize the lifecycle
183
183
  * @param {Object} uiStreamerSettings - UI-streamer portion of the settings taken from session info
184
184
  * @param {Object} [uiStreamerSettings.autoBackground] - Auto background mode configuration
185
- * @param {boolean} [uiStreamerSettings.autoBackground.enable=false] - Whether auto background mode is enabled
186
- * @param {number} [uiStreamerSettings.autoBackground.onVideoDelay=30] - Seconds of inactivity before moving to background while playing video
187
- * @param {number} [uiStreamerSettings.autoBackground.onUIDelay=30] - Seconds of inactivity before moving to background while in UI (not playing)
185
+ * @param {boolean} [uiStreamerSettings.autoBackground.enabled=false] - Enable/disable auto background
186
+ * @param {Object} [uiStreamerSettings.autoBackground.timeout] - Timeout settings
187
+ * @param {number|false} [uiStreamerSettings.autoBackground.timeout.playing=30] - Timeout in seconds when video is playing, false to disable
188
+ * @param {number|false} [uiStreamerSettings.autoBackground.timeout.idle=false] - Timeout in seconds when in UI mode, false to disable
188
189
  * @param {number} [uiStreamerSettings.remotePlayerConfirmationTimeout=5000] - Timeout in milliseconds for remote player operations
189
190
  * @param {number} [uiStreamerSettings.remotePlayerApiVersion=1] - Remote player API version
190
191
  */
@@ -261,23 +262,83 @@ class Lifecycle extends EventTarget {
261
262
  this._remotePlayerConfirmationTimeout = uiStreamerSettings?.remotePlayerConfirmationTimeout ?? DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT;
262
263
  this._remotePlayerApiVersion = uiStreamerSettings?.remotePlayerApiVersion || 1;
263
264
 
264
- // Take autoBackground settings from uiStreamerSettings if available
265
- // The UI setting section format :
266
- // "autoBackground": {
267
- // "enable": true,
268
- // "onVideoDelay": 30,
269
- // "onUIDelay": 30
270
- // }
271
-
272
- this._autoBackgroundOnVideoDelay = uiStreamerSettings?.autoBackground?.onVideoDelay ?? this._autoBackgroundOnVideoDelay;
273
- this._autoBackgroundOnUIDelay = uiStreamerSettings?.autoBackground?.onUIDelay ?? this._autoBackgroundOnUIDelay;
274
- this._autoBackground = uiStreamerSettings?.autoBackground?.enable ?? this._autoBackground;
275
- /*if (this._autoBackground) {
265
+ // Apply autoBackground settings if provided
266
+ if (uiStreamerSettings?.autoBackground) {
267
+ this.configure({
268
+ autoBackground: uiStreamerSettings.autoBackground
269
+ });
270
+ }
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Configure lifecycle settings
276
+ * @param {Object} config - Configuration object
277
+ * @param {Object} [config.autoBackground] - Auto background settings
278
+ * @param {boolean} [config.autoBackground.enabled] - Enable/disable auto background
279
+ * @param {Object} [config.autoBackground.timeout] - Timeout settings
280
+ * @param {number|false} [config.autoBackground.timeout.playing=30] - Timeout in seconds when video is playing, false to disable
281
+ * @param {number|false} [config.autoBackground.timeout.idle=false] - Timeout in seconds when in UI mode, false to disable
282
+ */
283
+ configure(config) {
284
+ if (config?.autoBackground) {
285
+ const { enabled, timeout } = config.autoBackground;
286
+
287
+ // Update enabled state
288
+ if (typeof enabled === "boolean") {
289
+ this._autoBackground = enabled;
290
+ }
291
+ // Update timeouts
292
+ if (timeout) {
293
+ if (timeout.playing !== undefined) {
294
+ if (timeout.playing === false) {
295
+ this._autoBackgroundOnVideoDelay = -1;
296
+ } else if (typeof timeout.playing === "number") {
297
+ this._autoBackgroundOnVideoDelay = timeout.playing;
298
+ } else {
299
+ sdkLogger.warn("Invalid autoBackground.timeout.playing value, expected number or false");
300
+ }
301
+ }
302
+ if (timeout.idle !== undefined) {
303
+ if (timeout.idle === false) {
304
+ this._autoBackgroundOnUIDelay = -1;
305
+ } else if (typeof timeout.idle === "number") {
306
+ this._autoBackgroundOnUIDelay = timeout.idle;
307
+ } else {
308
+ sdkLogger.warn("Invalid autoBackground.timeout.idle value, expected number or false");
309
+ }
310
+ }
311
+ }
312
+ // Start or stop countdown based on new configuration
313
+ if (this._autoBackground) {
276
314
  this._startCountdown();
277
- }*/
315
+ } else {
316
+ this._stopCountdown();
317
+ }
278
318
  }
279
319
  }
280
320
 
321
+ /**
322
+ * Get the current configuration settings
323
+ * @returns {Object} The current configuration object
324
+ * @example
325
+ * const config = lifecycle.getConfiguration();
326
+ * console.log(config.autoBackground.enabled); // true/false
327
+ * console.log(config.autoBackground.timeout.playing); // 30
328
+ * console.log(config.autoBackground.timeout.idle); // false
329
+ */
330
+ getConfiguration() {
331
+ return {
332
+ autoBackground: {
333
+ enabled: this._autoBackground,
334
+ timeout: {
335
+ playing: this._autoBackgroundOnVideoDelay <= 0 ? false : this._autoBackgroundOnVideoDelay,
336
+ idle: this._autoBackgroundOnUIDelay <= 0 ? false : this._autoBackgroundOnUIDelay
337
+ }
338
+ }
339
+ };
340
+ }
341
+
281
342
  /**
282
343
  * This method moves the application into standby mode, i.e. last ui frame is displayed and ui resources are released.
283
344
  * It should be called whenever the application wishes to go into standby mode and release resources.
@@ -411,10 +472,10 @@ class Lifecycle extends EventTarget {
411
472
  this._stopCountdown();
412
473
 
413
474
  const timeoutDelay = isPlaying ? this._autoBackgroundOnVideoDelay : this._autoBackgroundOnUIDelay;
414
- sdkLogger.debug("Starting countdown timeout", timeoutDelay, isPlaying ? "(video)" : "(UI)");
415
475
 
416
476
  // Only start countdown if delay is positive
417
477
  if (timeoutDelay > 0) {
478
+ sdkLogger.debug("Starting countdown timeout", timeoutDelay, isPlaying ? "(video)" : "(UI)");
418
479
  this._countdown = setTimeout(() => {
419
480
  sdkLogger.debug("Countdown timeout reached, moving to background");
420
481
  this.moveToBackground();
@@ -586,7 +586,7 @@ class RemotePlayer extends EventTarget {
586
586
  currentFramePTS: metadata.mediaTime.toString(),
587
587
  ptsSessionId: this._ptsSessionId
588
588
  };
589
- const request = {target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message)};
589
+ const request = { target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message) };
590
590
  window.cefQuery({
591
591
  request: JSON.stringify(request),
592
592
  persistent: false
@@ -1,5 +1,5 @@
1
1
  import * as shaka from "shaka-player";
2
- import { remotePlayer, lifecycle } from "./api";
2
+ import { remotePlayer, lifecycle, getPlatformInfo } from "./api";
3
3
  import { sdkLogger, iso6393to1 } from "./utils";
4
4
 
5
5
  // Define custom error category
@@ -386,6 +386,18 @@ export class SenzaShakaPlayer extends shaka.Player {
386
386
  ]);
387
387
  };
388
388
 
389
+ // For live streams, we can set a default offset from the live edge
390
+ // This allows for synchronizing the start position for both local and remote players
391
+ // Note: For VOD content, negative start times are treated as 0
392
+ const { defaultInitialLiveOffset, minInitialLiveOffset } = getPlatformInfo()?.sessionInfo?.settings?.["ui-streamer"] || {};
393
+ if ((startTime === undefined || startTime === 0) && defaultInitialLiveOffset !== undefined) {
394
+ sdkLogger.debug(`load() was called with startTime=${startTime}, setting startTime to ${-defaultInitialLiveOffset}`);
395
+ startTime = -defaultInitialLiveOffset;
396
+ } else if (startTime <= 0 && minInitialLiveOffset !== undefined && startTime > -minInitialLiveOffset) {
397
+ sdkLogger.debug(`load() was called with startTime=${startTime}, setting startTime to ${-minInitialLiveOffset}`);
398
+ startTime = -minInitialLiveOffset;
399
+ }
400
+
389
401
  if (!this.isInRemotePlayback || remotePlayer.getAssetUri() !== url) {
390
402
  this._audioTracksMap = {};
391
403
  this._videoTracksMap = {};