senza-sdk 4.2.43 → 4.2.45
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/lifecycle.js +21 -4
- package/src/remotePlayer.js +17 -10
- package/src/utils.js +1 -1
package/package.json
CHANGED
package/src/lifecycle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { alarmManager, getPlatformInfo } from "./api";
|
|
2
2
|
import {
|
|
3
3
|
getFCID,
|
|
4
|
-
|
|
4
|
+
isAudioSyncConfigured,
|
|
5
5
|
clearTimer,
|
|
6
6
|
sdkLogger,
|
|
7
7
|
StreamType,
|
|
@@ -21,6 +21,7 @@ const DEFAULT_AUTO_BACKGROUND_ENABLED = false;
|
|
|
21
21
|
* Lifecycle is a singleton class that manages the application lifecycle states.<br>
|
|
22
22
|
* @fires onstatechange
|
|
23
23
|
* @fires userinactivity
|
|
24
|
+
* @fires userdisconnected
|
|
24
25
|
*/
|
|
25
26
|
class Lifecycle extends EventTarget {
|
|
26
27
|
/**
|
|
@@ -60,6 +61,17 @@ class Lifecycle extends EventTarget {
|
|
|
60
61
|
* });
|
|
61
62
|
* @alpha API has not yet been released
|
|
62
63
|
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @event Lifecycle#userdisconnected
|
|
67
|
+
* @description Fired when the user session ends .
|
|
68
|
+
* This event is useful for cleaning up application state or saving data before the application closes.
|
|
69
|
+
* @example
|
|
70
|
+
* lifecycle.addEventListener("userdisconnected", () => {
|
|
71
|
+
* console.log("User session ended, cleaning up application state");
|
|
72
|
+
* // Perform any necessary cleanup here
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
63
75
|
constructor() {
|
|
64
76
|
super();
|
|
65
77
|
|
|
@@ -106,6 +118,11 @@ class Lifecycle extends EventTarget {
|
|
|
106
118
|
this.dispatchEvent(event);
|
|
107
119
|
});
|
|
108
120
|
|
|
121
|
+
typeof document !== "undefined" && document.addEventListener("hs/endOfSession", () => {
|
|
122
|
+
const event = new Event("userdisconnected");
|
|
123
|
+
this.dispatchEvent(event);
|
|
124
|
+
});
|
|
125
|
+
|
|
109
126
|
typeof document !== "undefined" && document.addEventListener("keydown", () => {
|
|
110
127
|
if (this._autoBackground) {
|
|
111
128
|
if (this.state === this.UiState.BACKGROUND ||
|
|
@@ -364,7 +381,7 @@ class Lifecycle extends EventTarget {
|
|
|
364
381
|
type: "remotePlayer.stop",
|
|
365
382
|
class: "remotePlayer",
|
|
366
383
|
action: "stop",
|
|
367
|
-
streamType:
|
|
384
|
+
streamType: remotePlayer._isAudioSyncEnabled() ? StreamType.VIDEO | StreamType.SUBTITLE : StreamType.AUDIO | StreamType.VIDEO | StreamType.SUBTITLE,
|
|
368
385
|
fcid: FCID
|
|
369
386
|
};
|
|
370
387
|
let timerId = 0;
|
|
@@ -428,7 +445,7 @@ class Lifecycle extends EventTarget {
|
|
|
428
445
|
return Promise.resolve(false);
|
|
429
446
|
}
|
|
430
447
|
// If audio sync is disabled, we only need to sync before remote player starts playing
|
|
431
|
-
if (!
|
|
448
|
+
if (!isAudioSyncConfigured()) {
|
|
432
449
|
remotePlayer._syncRemotePlayerWithLocalPlayer();
|
|
433
450
|
}
|
|
434
451
|
|
|
@@ -454,7 +471,7 @@ class Lifecycle extends EventTarget {
|
|
|
454
471
|
if (this._remotePlayerApiVersion >= 2) {
|
|
455
472
|
message.type = "remotePlayer.play";
|
|
456
473
|
message.class = "remotePlayer";
|
|
457
|
-
message.switchMode =
|
|
474
|
+
message.switchMode = remotePlayer._isAudioSyncEnabled() ? SwitchMode.SEAMLESS : SwitchMode.NON_SEAMLESS;
|
|
458
475
|
message.streamType = StreamType.AUDIO | StreamType.VIDEO | StreamType.SUBTITLE;
|
|
459
476
|
request = {
|
|
460
477
|
target: "TC",
|
package/src/remotePlayer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getFCID,
|
|
3
|
-
|
|
3
|
+
isAudioSyncConfigured,
|
|
4
4
|
clearTimer,
|
|
5
5
|
sdkLogger,
|
|
6
6
|
StreamType,
|
|
@@ -199,8 +199,8 @@ class RemotePlayer extends EventTarget {
|
|
|
199
199
|
sdkLogger.info("Got hs/playbackInfoEvent");
|
|
200
200
|
// When attached, the sdk controls the synchronization between the local and remote player.
|
|
201
201
|
if (this._videoElement) {
|
|
202
|
-
// When audio sync
|
|
203
|
-
if (!
|
|
202
|
+
// When audio sync is configured, the local player is already in sync with the remote player.
|
|
203
|
+
if (!isAudioSyncConfigured() && (lifecycle.state === lifecycle.UiState.BACKGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_BACKGROUND)) {
|
|
204
204
|
this._syncLocalPlayerWithRemotePlayer();
|
|
205
205
|
}
|
|
206
206
|
} else {
|
|
@@ -250,8 +250,8 @@ class RemotePlayer extends EventTarget {
|
|
|
250
250
|
this._videoElement.playbackRate = event.detail.rate;
|
|
251
251
|
});
|
|
252
252
|
typeof document !== "undefined" && document.addEventListener("hs/senzaPlayerSetTime", (event) => {
|
|
253
|
-
// For simplicity, make sure we only accept syncing the current time if audio sync enabled
|
|
254
|
-
if (!this.
|
|
253
|
+
// For simplicity, make sure we only accept syncing the current time if audio sync is enabled
|
|
254
|
+
if (!this._isAudioSyncEnabled()) return;
|
|
255
255
|
if (this._isSeekingByApplication) {
|
|
256
256
|
sdkLogger.info("Skip senzaPlayerSetTime while seek performed");
|
|
257
257
|
return;
|
|
@@ -504,6 +504,13 @@ class RemotePlayer extends EventTarget {
|
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
+
/** @private Audio sync is enabled only when the video element is attached and the audio sync is configured
|
|
508
|
+
* @returns {boolean}
|
|
509
|
+
*/
|
|
510
|
+
_isAudioSyncEnabled() {
|
|
511
|
+
return isAudioSyncConfigured() && this._videoElement;
|
|
512
|
+
}
|
|
513
|
+
|
|
507
514
|
/** get the player configuration.
|
|
508
515
|
* @returns {Config}
|
|
509
516
|
* */
|
|
@@ -708,7 +715,7 @@ class RemotePlayer extends EventTarget {
|
|
|
708
715
|
let waitForResponse = false;
|
|
709
716
|
this._changePlayMode(true);
|
|
710
717
|
if (this._remotePlayerApiVersion >= 2) {
|
|
711
|
-
if (
|
|
718
|
+
if (this._isAudioSyncEnabled()) {
|
|
712
719
|
message.switchMode = SwitchMode.SEAMLESS;
|
|
713
720
|
message.streamType = StreamType.AUDIO;
|
|
714
721
|
waitForResponse = true;
|
|
@@ -756,7 +763,7 @@ class RemotePlayer extends EventTarget {
|
|
|
756
763
|
if (window.cefQuery) {
|
|
757
764
|
this._changePlayMode(false);
|
|
758
765
|
const isForegroundState = lifecycle.state === lifecycle.UiState.FOREGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_FOREGROUND;
|
|
759
|
-
if (this._remotePlayerApiVersion >= 2 && !
|
|
766
|
+
if (this._remotePlayerApiVersion >= 2 && !this._isAudioSyncEnabled() && isForegroundState) {
|
|
760
767
|
sdkLogger.info("remotePlayer pause: application in foreground, remote player is not playing.");
|
|
761
768
|
return Promise.resolve();
|
|
762
769
|
}
|
|
@@ -770,7 +777,7 @@ class RemotePlayer extends EventTarget {
|
|
|
770
777
|
fcid: FCID
|
|
771
778
|
};
|
|
772
779
|
if (this._remotePlayerApiVersion >= 2) {
|
|
773
|
-
message.streamType =
|
|
780
|
+
message.streamType = this._isAudioSyncEnabled() && isForegroundState ? StreamType.AUDIO : StreamType.AUDIO | StreamType.VIDEO | StreamType.SUBTITLE;
|
|
774
781
|
}
|
|
775
782
|
const waitForResponse = this._remotePlayerApiVersion >= 2;
|
|
776
783
|
const request = { target: "TC", waitForResponse: waitForResponse, message: JSON.stringify(message) };
|
|
@@ -831,7 +838,7 @@ class RemotePlayer extends EventTarget {
|
|
|
831
838
|
if (this._videoElement) {
|
|
832
839
|
this.detach();
|
|
833
840
|
}
|
|
834
|
-
if (
|
|
841
|
+
if (isAudioSyncConfigured()) {
|
|
835
842
|
this._handleVideoFrameInfo(video);
|
|
836
843
|
this._updateSeekListeners(video);
|
|
837
844
|
}
|
|
@@ -1063,7 +1070,7 @@ class RemotePlayer extends EventTarget {
|
|
|
1063
1070
|
return Promise.resolve(true);
|
|
1064
1071
|
}
|
|
1065
1072
|
/*
|
|
1066
|
-
else if (this._remotePlayerApiVersion >= 2 &&
|
|
1073
|
+
else if (this._remotePlayerApiVersion >= 2 && this._isAudioSyncEnabled()) {
|
|
1067
1074
|
// If we have the position of the video element, we can sync the remote player with the local player
|
|
1068
1075
|
// before playing audio.
|
|
1069
1076
|
if (this._videoElement.currentTime !== 0) {
|
package/src/utils.js
CHANGED
|
@@ -110,7 +110,7 @@ export function clearTimer(timerId) {
|
|
|
110
110
|
return timerId;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
export function
|
|
113
|
+
export function isAudioSyncConfigured() {
|
|
114
114
|
const clientUiAudioSettings = sessionInfo.sessionInfoObj?.settings?.client?.["ui_audio"];
|
|
115
115
|
return clientUiAudioSettings?.enabled && clientUiAudioSettings?.from_cdn && clientUiAudioSettings?.ui_sync_enabled;
|
|
116
116
|
}
|