senza-sdk 4.2.17 → 4.2.18

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.17",
3
+ "version": "4.2.18",
4
4
  "main": "./src/api.js",
5
5
  "description": "API for Senza application",
6
6
  "license": "MIT",
@@ -48,4 +48,4 @@
48
48
  "dependencies": {
49
49
  "shaka-player": "^4.12.5"
50
50
  }
51
- }
51
+ }
package/src/lifecycle.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { alarmManager, getPlatformInfo } from "./api";
2
2
  import { getFCID, isAudioSyncEnabled, clearTimer, sdkLogger, StreamType, SwitchMode, SenzaError } from "./utils";
3
3
  import { sessionInfo } from "./SessionInfo";
4
- import { DEFAULT_PLAY_TIMEOUT, DEFAULT_STOP_TIMEOUT, remotePlayer } from "./remotePlayer";
4
+ import { DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT, remotePlayer } from "./remotePlayer";
5
5
 
6
6
  /**
7
7
  * Lifecycle is a singleton class that manages the application lifecycle states.<br>
@@ -117,8 +117,7 @@ class Lifecycle extends EventTarget {
117
117
  });
118
118
  });
119
119
  this._isInitialized = true;
120
- this._playTimeout = uiStreamerSettings?.playTimeout ?? DEFAULT_PLAY_TIMEOUT;
121
- this._stopTimeout = uiStreamerSettings?.stopTimeout ?? DEFAULT_STOP_TIMEOUT;
120
+ this._remotePlayerConfirmationTimeout = uiStreamerSettings?.remotePlayerConfirmationTimeout ?? DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT;
122
121
  }
123
122
  }
124
123
 
@@ -270,7 +269,7 @@ class Lifecycle extends EventTarget {
270
269
  }
271
270
  });
272
271
  logger.log(`window.cefQuery for stop returned query id ${queryId}`);
273
- const stopTimeout = this._stopTimeout + 1000;
272
+ const stopTimeout = this._remotePlayerConfirmationTimeout + 1000;
274
273
  timerId = setTimeout(() => {
275
274
  logger.log(`stop reached timeout of ${stopTimeout} ms, canceling query id ${queryId}`);
276
275
  this._inTransition = false;
@@ -375,7 +374,7 @@ class Lifecycle extends EventTarget {
375
374
  });
376
375
  if (sessionInfo.sessionInfoObj?.settings?.["ui-streamer"]?.remotePlayerApiVersion >= 2) {
377
376
  logger.log(`window.cefQuery for play returned query id ${queryId}`);
378
- const playTimeout = this._playTimeout + 1000;
377
+ const playTimeout = this._remotePlayerConfirmationTimeout + 1000;
379
378
  timerId = setTimeout(() => {
380
379
  logger.log(`play reached timeout of ${playTimeout} ms, canceling query id ${queryId}`);
381
380
  this._inTransition = false;
@@ -3,13 +3,11 @@ import { getFCID, isAudioSyncEnabled, clearTimer, sdkLogger, StreamType, SwitchM
3
3
  import { lifecycle } from "./lifecycle";
4
4
  import { writeLicenseResponse } from "./api";
5
5
  import { mergeAutoTranslationLanguages } from "./subtitlesUtils";
6
- import { sessionInfo } from "./SessionInfo";
7
6
 
8
7
  const INVALID_SET_PLAYABLE_URI_CODE = 99;
9
- const DEFAULT_SET_PLAYABLE_URI_TIMEOUT = 5000;
10
- const DEFAULT_UNLOAD_TIMEOUT = 5000;
11
- export const DEFAULT_PLAY_TIMEOUT = 5000;
12
- export const DEFAULT_STOP_TIMEOUT = 5000;
8
+
9
+ // Default timeout for waiting for the remote player confirmation
10
+ export const DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT = 5000;
13
11
 
14
12
  const cloneDeep = (element) => {
15
13
  return JSON.parse(JSON.stringify(element));
@@ -413,10 +411,9 @@ class RemotePlayer extends EventTarget {
413
411
  this._loadMode = playerState?.isLoaded ? this.LoadMode.LOADED : this.LoadMode.NOT_LOADED;
414
412
  this._loadedUrl = playerState?.playbackUrl || "";
415
413
  this._isInitialized = true;
416
- this._setPlayableUriTimeout = uiStreamerSettings?.setPlayableUriTimeout ?? DEFAULT_SET_PLAYABLE_URI_TIMEOUT;
417
- this._unloadTimeout = uiStreamerSettings?.unloadTimeout ?? DEFAULT_UNLOAD_TIMEOUT;
418
- this._playTimeout = uiStreamerSettings?.playTimeout ?? DEFAULT_PLAY_TIMEOUT;
414
+ this._remotePlayerConfirmationTimeout = uiStreamerSettings?.remotePlayerConfirmationTimeout ?? DEFAULT_REMOTE_PLAYER_CONFIRMATION_TIMEOUT;
419
415
  this._requestVideoFrameInfo = uiStreamerSettings?.requestVideoFrameInfo ?? true;
416
+ this._remotePlayerApiVersion = uiStreamerSettings?.remotePlayerApiVersion || 1;
420
417
 
421
418
  let playbackMetadata = {};
422
419
  try {
@@ -628,7 +625,7 @@ class RemotePlayer extends EventTarget {
628
625
  playbackPosition,
629
626
  fcid: FCID
630
627
  };
631
- if (sessionInfo.sessionInfoObj?.settings?.["ui-streamer"]?.remotePlayerApiVersion >= 2) {
628
+ if (this._remotePlayerApiVersion >= 2) {
632
629
  message.type = "remotePlayer.load";
633
630
  message.class = "remotePlayer";
634
631
  message.action = "load";
@@ -668,7 +665,7 @@ class RemotePlayer extends EventTarget {
668
665
  }
669
666
  });
670
667
  logger.log(`window.cefQuery for setPlayableUri returned query id ${queryId}`);
671
- const loadTimeout = this._setPlayableUriTimeout + 1000;
668
+ const loadTimeout = this._remotePlayerConfirmationTimeout + 1000;
672
669
  timerId = setTimeout(() => {
673
670
  logger.log(`setPlayableUri reached timeout of ${loadTimeout} ms, canceling query id ${queryId}`);
674
671
  window.cefQueryCancel(queryId);
@@ -733,7 +730,7 @@ class RemotePlayer extends EventTarget {
733
730
  }
734
731
  });
735
732
  logger.log(`window.cefQuery for unload returned query id ${queryId}`);
736
- const unLoadTimeout = this._unloadTimeout + 1000;
733
+ const unLoadTimeout = this._remotePlayerConfirmationTimeout + 1000;
737
734
  timerId = setTimeout(() => {
738
735
  logger.log(`unload reached timeout of ${unLoadTimeout} ms, canceling query id ${queryId}`);
739
736
  window.cefQueryCancel(queryId);
@@ -784,7 +781,7 @@ class RemotePlayer extends EventTarget {
784
781
  playbackPosition: this.currentTime
785
782
  };
786
783
  let waitForResponse = false;
787
- if (sessionInfo.sessionInfoObj?.settings?.["ui-streamer"]?.remotePlayerApiVersion >= 2) {
784
+ if (this._remotePlayerApiVersion >= 2) {
788
785
  if (isAudioSyncEnabled()) {
789
786
  message.switchMode = SwitchMode.SEAMLESS;
790
787
  message.streamType = StreamType.AUDIO;
@@ -816,7 +813,7 @@ class RemotePlayer extends EventTarget {
816
813
  });
817
814
  logger.log(`window.cefQuery for play returned query id ${queryId}`);
818
815
  if (waitForResponse) {
819
- const playTimeout = this._playTimeout + 1000;
816
+ const playTimeout = this._remotePlayerConfirmationTimeout + 1000;
820
817
  timerId = setTimeout(() => {
821
818
  logger.log(`play reached timeout of ${playTimeout} ms, canceling query id ${queryId}`);
822
819
  window.cefQueryCancel(queryId);
@@ -829,7 +826,10 @@ class RemotePlayer extends EventTarget {
829
826
  return Promise.resolve(undefined);
830
827
  }
831
828
 
832
- /** pauses the currently playing audio or video
829
+ /** Pauses the currently playing audio or video
830
+ * When pausing in background, it will pause all streams (audio, video, subtitles) to support pausing in background.
831
+ * When pausing in foreground, if audio in ui enabled, it will only pause audio stream.
832
+ * When pausing in foreground, if audio is not enabled, remote player is not playing and therefore no call is sent.
833
833
  * @returns {Promise}
834
834
  * @throws {RemotePlayerError} error object contains code & msg
835
835
  *
@@ -842,6 +842,11 @@ class RemotePlayer extends EventTarget {
842
842
  if (this._loadMode !== this.LoadMode.LOADED) {
843
843
  throw new RemotePlayerError(6001, "Cannot call pause() if player is not loaded");
844
844
  }
845
+ const isForegroundState = lifecycle.state === lifecycle.UiState.FOREGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_FOREGROUND;
846
+ if (this._remotePlayerApiVersion >= 2 && !isAudioSyncEnabled() && isForegroundState) {
847
+ sdkLogger.info("remotePlayer pause: application in foreground, remote player is not playing.");
848
+ return Promise.resolve();
849
+ }
845
850
  const FCID = getFCID();
846
851
  const logger = sdkLogger.withFields({ FCID });
847
852
  logger.log("remotePlayer pause: sending pause request");
@@ -851,20 +856,39 @@ class RemotePlayer extends EventTarget {
851
856
  action: "pause",
852
857
  fcid: FCID
853
858
  };
854
- const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
859
+ if (this._remotePlayerApiVersion >= 2) {
860
+ message.streamType = isAudioSyncEnabled() && isForegroundState ? StreamType.AUDIO : StreamType.AUDIO | StreamType.VIDEO | StreamType.SUBTITLE;
861
+ }
862
+ const waitForResponse = this._remotePlayerApiVersion >= 2;
863
+ const request = { target: "TC", waitForResponse: waitForResponse, message: JSON.stringify(message) };
855
864
  return new Promise((resolve, reject) => {
856
- window.cefQuery({
865
+ let timerId = 0;
866
+ const timeBeforeSendingRequest = Date.now();
867
+ const queryId = window.cefQuery({
857
868
  request: JSON.stringify(request),
858
869
  persistent: false,
859
870
  onSuccess: () => {
860
- logger.log("remotePlayer pause request successfully sent");
871
+ const duration = Date.now() - timeBeforeSendingRequest;
872
+ logger.withFields({ duration }).log(`pause completed successfully after ${duration} ms`);
873
+ timerId = clearTimer(timerId);
861
874
  resolve();
862
875
  },
863
876
  onFailure: (code, msg) => {
864
- logger.error(`remotePlayer pause request failed: ${code} ${msg}`);
877
+ const duration = Date.now() - timeBeforeSendingRequest;
878
+ logger.withFields({ duration }).log(`pause failed after ${duration} ms. Error code: ${code}, error message: ${msg}`);
879
+ timerId = clearTimer(timerId);
865
880
  reject(new RemotePlayerError(code, msg));
866
881
  }
867
882
  });
883
+ logger.log(`window.cefQuery for pause returned query id ${queryId}`);
884
+ if (waitForResponse) {
885
+ const timeout = this._remotePlayerConfirmationTimeout + 1000;
886
+ timerId = setTimeout(() => {
887
+ logger.log(`pause reached timeout of ${timeout} ms, canceling query id ${queryId}`);
888
+ window.cefQueryCancel(queryId);
889
+ reject(new RemotePlayerError(6000, `pause reached timeout of ${timeout} ms`));
890
+ }, timeout, queryId);
891
+ }
868
892
  });
869
893
  }
870
894
  sdkLogger.error("remotePlayer pause: window.cefQuery is undefined");