senza-sdk 4.4.4-86e7d7a.0 → 4.4.5
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/dist/implementation.bundle.js +2 -0
- package/dist/implementation.bundle.js.LICENSE.txt +82 -0
- package/package.json +8 -7
- package/src/api.js +16 -2
- package/src/implementation/api.js +9 -5
- package/src/implementation/backgroundRenderControl.js +113 -0
- package/src/implementation/deviceManager.js +6 -177
- package/src/implementation/displayManager.js +181 -0
- package/src/implementation/edidParser.js +125 -0
- package/src/implementation/lifecycle.js +42 -17
- package/src/implementation/remotePlayer.js +5 -2
- package/src/interface/api.js +1 -0
- package/src/interface/deviceManager.js +0 -33
- package/src/interface/displayManager.js +126 -0
- package/src/interface/lifecycle.js +18 -1
- package/src/interface/version.js +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
@license
|
|
3
|
+
Copyright 2006 The Closure Library Authors
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
@license
|
|
9
|
+
Copyright 2008 The Closure Library Authors
|
|
10
|
+
SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
@license
|
|
15
|
+
Copyright 2013 Ali Al Dallal
|
|
16
|
+
|
|
17
|
+
Licensed under the MIT license.
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
in the Software without restriction, including without limitation the rights
|
|
22
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
furnished to do so, subject to the following conditions:
|
|
25
|
+
|
|
26
|
+
The above copyright notice and this permission notice shall be included in
|
|
27
|
+
all copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
SOFTWARE.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
@license
|
|
40
|
+
MSS Transmuxer
|
|
41
|
+
Copyright 2015 Dash Industry Forum
|
|
42
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
@license
|
|
47
|
+
Shaka Player
|
|
48
|
+
Copyright 2016 Google LLC
|
|
49
|
+
SPDX-License-Identifier: Apache-2.0
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
@license
|
|
54
|
+
Shaka Player
|
|
55
|
+
Copyright 2022 Google LLC
|
|
56
|
+
SPDX-License-Identifier: Apache-2.0
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
@license
|
|
61
|
+
Shaka Player
|
|
62
|
+
Copyright 2023 Google LLC
|
|
63
|
+
SPDX-License-Identifier: Apache-2.0
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
@license
|
|
68
|
+
Shaka Player
|
|
69
|
+
Copyright 2025 Google LLC
|
|
70
|
+
SPDX-License-Identifier: Apache-2.0
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
@license
|
|
75
|
+
tXml
|
|
76
|
+
Copyright 2015 Tobias Nickel
|
|
77
|
+
SPDX-License-Identifier: MIT
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
//! moment.js
|
|
81
|
+
|
|
82
|
+
//! moment.js locale configuration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "senza-sdk",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.5",
|
|
4
4
|
"main": "./src/api.js",
|
|
5
5
|
"description": "API for Senza application",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,17 +23,18 @@
|
|
|
23
23
|
"version:output": "echo 'export const version = \"'$npm_package_version'\";' > src/interface/version.js"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@babel/cli": "^7.
|
|
27
|
-
"@babel/core": "7.
|
|
28
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
29
|
-
"@babel/preset-env": "^7.
|
|
26
|
+
"@babel/cli": "^7.22.0",
|
|
27
|
+
"@babel/core": "^7.22.0",
|
|
28
|
+
"@babel/plugin-transform-modules-commonjs": "^7.22.0",
|
|
29
|
+
"@babel/preset-env": "^7.22.0",
|
|
30
30
|
"@eslint/eslintrc": "^3.3.0",
|
|
31
31
|
"@eslint/js": "^9.22.0",
|
|
32
|
-
"babel-jest": "^
|
|
32
|
+
"babel-jest": "^30.2.0",
|
|
33
33
|
"eslint": "^9.22.0",
|
|
34
34
|
"eslint-plugin-jest": "^28.11.0",
|
|
35
35
|
"globals": "^16.0.0",
|
|
36
|
-
"jest": "^
|
|
36
|
+
"jest": "^30.2.0",
|
|
37
|
+
"jest-environment-jsdom" : "^30.2.0",
|
|
37
38
|
"jsdoc-to-markdown": "^7.1.1",
|
|
38
39
|
"webpack": "^5.72.1",
|
|
39
40
|
"webpack-cli": "^5.1.4"
|
package/src/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sdkLogger, noop } from "./interface/utils.js";
|
|
2
2
|
|
|
3
|
-
import { Lifecycle, RemotePlayer, DeviceManager, PlatformManager, AlarmManager, MessageManager, ShakaPlayer, shaka, showSequence, initSequence } from "./interface/api.js";
|
|
3
|
+
import { Lifecycle, RemotePlayer, DeviceManager, PlatformManager, AlarmManager, MessageManager, ShakaPlayer, shaka, showSequence, initSequence, DisplayManager } from "./interface/api.js";
|
|
4
4
|
|
|
5
5
|
import { version } from "./interface/version.js";
|
|
6
6
|
|
|
@@ -252,6 +252,18 @@ let alarmManager;
|
|
|
252
252
|
*/
|
|
253
253
|
let deviceManager;
|
|
254
254
|
|
|
255
|
+
/**
|
|
256
|
+
* @module
|
|
257
|
+
* @private
|
|
258
|
+
* @type {DisplayManager}
|
|
259
|
+
* @example
|
|
260
|
+
* import { displayManager } from "senza-sdk";
|
|
261
|
+
* const connection = await displayManager.connection;
|
|
262
|
+
* console.info(connection);
|
|
263
|
+
*
|
|
264
|
+
* @return {DisplayManager} pointer to the DisplayManager singleton
|
|
265
|
+
*/
|
|
266
|
+
let displayManager;
|
|
255
267
|
|
|
256
268
|
/**
|
|
257
269
|
* @module
|
|
@@ -317,6 +329,7 @@ if (!isRunningE2E()) {
|
|
|
317
329
|
remotePlayer = new RemotePlayer();
|
|
318
330
|
alarmManager = new AlarmManager();
|
|
319
331
|
deviceManager = new DeviceManager();
|
|
332
|
+
displayManager = new DisplayManager();
|
|
320
333
|
platformManager = new PlatformManager();
|
|
321
334
|
messageManager = new MessageManager();
|
|
322
335
|
ShakaPlayerImplementation = ShakaPlayer;
|
|
@@ -327,6 +340,7 @@ if (!isRunningE2E()) {
|
|
|
327
340
|
remotePlayer = window.senzaSDKImplementation.remotePlayer;
|
|
328
341
|
alarmManager = window.senzaSDKImplementation.alarmManager;
|
|
329
342
|
deviceManager = window.senzaSDKImplementation.deviceManager;
|
|
343
|
+
displayManager = window.senzaSDKImplementation.displayManager;
|
|
330
344
|
platformManager = window.senzaSDKImplementation.platformManager;
|
|
331
345
|
messageManager = window.senzaSDKImplementation.messageManager;
|
|
332
346
|
ShakaPlayerImplementation = window.senzaSDKImplementation.ShakaPlayer;
|
|
@@ -373,7 +387,7 @@ export function setTimezone(timezone) {
|
|
|
373
387
|
}
|
|
374
388
|
}
|
|
375
389
|
|
|
376
|
-
export { lifecycle, remotePlayer, alarmManager, deviceManager, platformManager, messageManager, ShakaPlayerImplementation as ShakaPlayer, shakaImplementation as shaka, showSequence, initSequence };
|
|
390
|
+
export { lifecycle, remotePlayer, alarmManager, deviceManager, displayManager, platformManager, messageManager, ShakaPlayerImplementation as ShakaPlayer, shakaImplementation as shaka, showSequence, initSequence };
|
|
377
391
|
|
|
378
392
|
// Assign the senza library to the old name (hs) for backward compatibility
|
|
379
393
|
import * as senzaSDK from "./api.js";
|
|
@@ -4,11 +4,14 @@ import { lifecycle } from "./lifecycle.js";
|
|
|
4
4
|
import { alarmManager } from "./alarmManager.js";
|
|
5
5
|
import { remotePlayer } from "./remotePlayer.js";
|
|
6
6
|
import { deviceManager } from "./deviceManager.js";
|
|
7
|
+
import { displayManager } from "./displayManager.js";
|
|
7
8
|
import { messageManager } from "./messageManager.js";
|
|
9
|
+
import { backgroundRenderControl } from "./backgroundRenderControl.js";
|
|
8
10
|
|
|
9
11
|
export { remotePlayer };
|
|
10
|
-
export { lifecycle }
|
|
12
|
+
export { lifecycle };
|
|
11
13
|
export { deviceManager };
|
|
14
|
+
export { displayManager };
|
|
12
15
|
export { platformManager } from "./platformManager.js";
|
|
13
16
|
export { alarmManager };
|
|
14
17
|
export { messageManager };
|
|
@@ -101,9 +104,9 @@ export async function init(interfaceApiVersion, showSequenceFunc, initSequenceFu
|
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
// Set default device manager event timeout using UI-Streamer settings
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
+
const displayManagerEventTimeout = sessionInfoObj?.settings?.["ui-streamer"]?.displayManagerEventTimeout;
|
|
108
|
+
if (displayManagerEventTimeout) {
|
|
109
|
+
displayManager._setDefaultTimeout(displayManagerEventTimeout);
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
// Get trigger event
|
|
@@ -139,7 +142,8 @@ export async function init(interfaceApiVersion, showSequenceFunc, initSequenceFu
|
|
|
139
142
|
await remotePlayer._init(sessionInfoObj, triggerEvent);
|
|
140
143
|
alarmManager._init();
|
|
141
144
|
messageManager._init();
|
|
142
|
-
|
|
145
|
+
backgroundRenderControl._init();
|
|
146
|
+
await displayManager._init();
|
|
143
147
|
sdkLogger.log("All submodules initialized");
|
|
144
148
|
|
|
145
149
|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { lifecycle } from "./lifecycle.js";
|
|
2
|
+
import { sdkLogger } from "./utils.js";
|
|
3
|
+
import { sessionInfo } from "./SessionInfo";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal background render control.
|
|
7
|
+
* Listens to lifecycle state changes and disables animation / video rendering when in background mode.
|
|
8
|
+
* Specifically it pauses CSS animations and hides video elements to reduce CPU/GPU load
|
|
9
|
+
*
|
|
10
|
+
* For remote-gpu deployments this reduces the CPU use in background mode from 6 cores to 0.4 cores.
|
|
11
|
+
*
|
|
12
|
+
* Extra CPU can be saved by also overriding requestAnimationFrame and slowing down time.
|
|
13
|
+
* This has the effect of ensuring the segments are downloaded at a slower pace
|
|
14
|
+
* - or not at all if you actually pause video, but these may have more complicated state and audio sync issues.
|
|
15
|
+
* Either way if you slow the decoding speed then we save more CPU by not doing as much SW video decoding,
|
|
16
|
+
* but the bulk is saved by the hidden video elements.
|
|
17
|
+
* See comments on https://jira01.engit.synamedia.com/browse/HSDEV-16827 for more about a PoC / spike that did this.
|
|
18
|
+
*
|
|
19
|
+
* As it stands, the current implementation that gets us 0.4 cores in background mode for remote-gpu is a good compromise of complexity vs benefit.
|
|
20
|
+
* It also roughly matches GPU mode background CPU use (maybe slightly better).
|
|
21
|
+
* GPU mode with this feature enabled (from my testing) saves about 0.15 cores ~0.45 -> ~0.30 cores
|
|
22
|
+
*
|
|
23
|
+
* This module uses the following settings:
|
|
24
|
+
* {
|
|
25
|
+
* "ui-streamer": {
|
|
26
|
+
* "throttleRenderingInBackground": {
|
|
27
|
+
* "enabled": true, // enable or disable the feature
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
class BackgroundRenderControl {
|
|
33
|
+
|
|
34
|
+
/** initialised
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
* @private
|
|
37
|
+
* Whether the instance has been initialized.
|
|
38
|
+
*/
|
|
39
|
+
_initialized = false;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
* @private
|
|
44
|
+
* Whether render control is enabled.
|
|
45
|
+
*/
|
|
46
|
+
_enabled = false;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @type {boolean}
|
|
50
|
+
* @private
|
|
51
|
+
* Whether rendering is currently active.
|
|
52
|
+
*/
|
|
53
|
+
_active = true;
|
|
54
|
+
|
|
55
|
+
/** @type {string|null}
|
|
56
|
+
* @private
|
|
57
|
+
* Stores the last known lifecycle state.
|
|
58
|
+
*/
|
|
59
|
+
_lastState = null;
|
|
60
|
+
|
|
61
|
+
/** @type {Function}
|
|
62
|
+
* @private
|
|
63
|
+
* Event listener for lifecycle state changes.
|
|
64
|
+
*/
|
|
65
|
+
_listener = (e) => this._handleStateChange(e.state);
|
|
66
|
+
|
|
67
|
+
_init() {
|
|
68
|
+
if (this._initialized) return;
|
|
69
|
+
this._enabled = sessionInfo?.sessionInfoObj.settings?.["ui-streamer"]?.throttleRenderingInBackground?.enabled ?? false;
|
|
70
|
+
sdkLogger.log(`Initializing BackgroundRenderControl: enabled=${this._enabled}`);
|
|
71
|
+
if (!this._enabled) return;
|
|
72
|
+
this._lastState = lifecycle.state;
|
|
73
|
+
lifecycle.addEventListener("onstatechange", this._listener);
|
|
74
|
+
this._initialized = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_handleStateChange(state) {
|
|
78
|
+
if (!this._enabled) return;
|
|
79
|
+
if (state === this._lastState) return;
|
|
80
|
+
this._lastState = state;
|
|
81
|
+
try {
|
|
82
|
+
if (state === lifecycle.UiState.FOREGROUND) this._onForeground();
|
|
83
|
+
else if (state === lifecycle.UiState.BACKGROUND) this._onBackground();
|
|
84
|
+
} catch (err) {
|
|
85
|
+
sdkLogger.error("BackgroundRenderControl state handling error", err);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_onForeground() {
|
|
90
|
+
if (this._active) return;
|
|
91
|
+
sdkLogger.log("BackgroundRenderControl resume rendering");
|
|
92
|
+
this._active = true;
|
|
93
|
+
const style = document.getElementById("hs-sdk-bg-render-styles");
|
|
94
|
+
if (style) style.remove();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_onBackground() {
|
|
98
|
+
if (!this._active) return;
|
|
99
|
+
sdkLogger.log("BackgroundRenderControl throttle rendering");
|
|
100
|
+
this._active = false;
|
|
101
|
+
if (!document.getElementById("hs-sdk-bg-render-styles")) {
|
|
102
|
+
const style = document.createElement("style");
|
|
103
|
+
style.id = "hs-sdk-bg-render-styles";
|
|
104
|
+
style.textContent = `
|
|
105
|
+
* { animation-play-state: paused !important; transition: none !important; scroll-behavior: auto !important; }
|
|
106
|
+
canvas, video, img { visibility: hidden !important; }
|
|
107
|
+
`;
|
|
108
|
+
document.head.appendChild(style);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const backgroundRenderControl = new BackgroundRenderControl();
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { DeviceManager as DeviceManagerInterface } from "../interface/deviceManager";
|
|
2
|
-
import { getFCID, sdkLogger, getRestResponse
|
|
2
|
+
import { getFCID, sdkLogger, getRestResponse } from "./utils";
|
|
3
3
|
import { sessionInfo } from "./SessionInfo";
|
|
4
|
-
import { EventListenersManager } from "./eventListenersManager";
|
|
5
|
-
import { bus, Events } from "./eventBus";
|
|
6
|
-
import { lifecycle } from "./lifecycle";
|
|
7
4
|
|
|
8
5
|
let wifi_ap_data;
|
|
9
6
|
let wifi_status;
|
|
10
7
|
let wifi_status_last_update = 0;
|
|
11
8
|
|
|
12
9
|
const WIFI_STATUS_CACHE_SECONDS = 5;
|
|
13
|
-
const
|
|
10
|
+
const FACTORY_RESET_TIMEOUT_SECONDS = 5;
|
|
14
11
|
|
|
15
12
|
async function getWifiApData() {
|
|
16
13
|
// Wi-Fi access point data is static, so it needs to be retrieved only once
|
|
@@ -41,134 +38,6 @@ class DeviceManager extends DeviceManagerInterface {
|
|
|
41
38
|
|
|
42
39
|
constructor() {
|
|
43
40
|
super();
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Mapping of CEC active source status to HdmiStatus.
|
|
47
|
-
* @type {Object}
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
this._cecActiveSourceStatusMap = Object.freeze({
|
|
51
|
-
active: this.HdmiStatus.ACTIVE,
|
|
52
|
-
inactive: this.HdmiStatus.INACTIVE,
|
|
53
|
-
unknown: this.HdmiStatus.UNKNOWN
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Event listeners manager for the deviceManager events
|
|
58
|
-
* @type {EventListenersManager}
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
this._eventManager = new EventListenersManager({
|
|
62
|
-
timeoutMs: 10000 // Default timeout of 10 seconds, can be overridden by _setDefaultTimeout
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @type {boolean}
|
|
67
|
-
* @private
|
|
68
|
-
*/
|
|
69
|
-
this._isInitialized = false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
_init() {
|
|
76
|
-
sdkLogger.log("Initializing DeviceManager");
|
|
77
|
-
if (!this._isInitialized) {
|
|
78
|
-
this._isInitialized = true;
|
|
79
|
-
this._addSenzaEventListeners();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Translate the HdmiStatus information to a single HdmiStatus for the application
|
|
85
|
-
* 1) cecStatus is a configuration setting from the client. If false, we always return UNKNOWN to the application
|
|
86
|
-
* 2) If cecStatus is true, we check the hdmiStatus. If not "connected", the HDMI status is definitely INACTIVE.
|
|
87
|
-
* 3) If hdmiStatus is "connected" and cecStatus is true, we rely on the cecActiveSourceStatus to determine the HdmiStatus
|
|
88
|
-
* @private
|
|
89
|
-
*/
|
|
90
|
-
_translateHdmiStatus(hdmiStatusStr) {
|
|
91
|
-
const hdmiStatusObj = JSON.parse(hdmiStatusStr ?? "{}"); // Object containing the 3 statuses
|
|
92
|
-
let hdmiStatus = this.HdmiStatus.UNKNOWN;
|
|
93
|
-
if (hdmiStatusObj?.cecStatus) {
|
|
94
|
-
if (hdmiStatusObj.hdmiStatus !== "connected") {
|
|
95
|
-
hdmiStatus = this.HdmiStatus.INACTIVE;
|
|
96
|
-
} else {
|
|
97
|
-
const cecActive = this._cecActiveSourceStatusMap[hdmiStatusObj.cecActiveSourceStatus];
|
|
98
|
-
hdmiStatus = cecActive ?? this.HdmiStatus.UNKNOWN;
|
|
99
|
-
if (!cecActive) {
|
|
100
|
-
sdkLogger.warn(`Unknown CEC active source status: ${hdmiStatusObj.cecActiveSourceStatus}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
sdkLogger.warn("cec is disabled or no hdmiStatus");
|
|
105
|
-
}
|
|
106
|
-
sdkLogger.log("HDMI status is:", hdmiStatus);
|
|
107
|
-
return hdmiStatus;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @private Add event listeners for system events
|
|
112
|
-
*/
|
|
113
|
-
_addSenzaEventListeners() {
|
|
114
|
-
bus.addEventListener(Events.LifecycleForeground, () => {
|
|
115
|
-
this._moveToForegroundHasBeenCalled = true;
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
typeof document !== "undefined" && document.addEventListener("hs/hdmiStatusChanged", async (event) => {
|
|
119
|
-
sdkLogger.info("Got hs/hdmiStatusChanged event with detail", JSON.stringify(event?.detail));
|
|
120
|
-
|
|
121
|
-
const hdmiStatus = this._translateHdmiStatus(event?.detail?.hdmiStatus);
|
|
122
|
-
|
|
123
|
-
const timeBeforeCallbacks = Date.now();
|
|
124
|
-
|
|
125
|
-
// Dispatch event to application and allow a chance to move to foreground.
|
|
126
|
-
// If there are no callbacks or the application doesn't move to foreground, the UI will be disconnected.
|
|
127
|
-
await this._eventManager.dispatch("hdmistatuschanged", {hdmiStatus});
|
|
128
|
-
|
|
129
|
-
const callbackDuration = Date.now() - timeBeforeCallbacks;
|
|
130
|
-
sdkLogger.log(`All callbacks for hdmiStatusChanged are finished within ${callbackDuration}ms`);
|
|
131
|
-
const isTriggering = lifecycle.triggerEvent.type === "hdmiStatusChanged" && lifecycle._triggerEventFcid && lifecycle._triggerEventFcid === event.detail.fcid;
|
|
132
|
-
if (isTriggering) {
|
|
133
|
-
if (!this._moveToForegroundHasBeenCalled && window.cefQuery) {
|
|
134
|
-
sdkLogger.log("Application is about to be disconnected since didn't move to foreground");
|
|
135
|
-
const message = { type: "disconnect" };
|
|
136
|
-
const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
|
|
137
|
-
window.cefQuery({
|
|
138
|
-
request: JSON.stringify(request),
|
|
139
|
-
persistent: false,
|
|
140
|
-
onSuccess: () => {
|
|
141
|
-
sdkLogger.log("disconnect request successfully sent");
|
|
142
|
-
},
|
|
143
|
-
onFailure: (code, msg) => {
|
|
144
|
-
sdkLogger.error(`disconnect request failed: ${code} ${msg}`);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Set the default timeout for device manager event listeners
|
|
154
|
-
* @param {number} timeout - Timeout in milliseconds for device manager event listeners
|
|
155
|
-
* @private
|
|
156
|
-
*/
|
|
157
|
-
_setDefaultTimeout(timeout) {
|
|
158
|
-
if (typeof timeout === "number" && timeout > 0) {
|
|
159
|
-
this._eventManager.timeoutMs = timeout;
|
|
160
|
-
sdkLogger.log(`DeviceManager event listener timeout set to ${timeout}ms`);
|
|
161
|
-
} else {
|
|
162
|
-
sdkLogger.warn(`Invalid timeout value: ${timeout}. Must be a positive number.`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
addEventListener(type, callback) {
|
|
167
|
-
this._eventManager.addEventListener(type, callback);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
removeEventListener(type, callback) {
|
|
171
|
-
this._eventManager.removeEventListener(type, callback);
|
|
172
41
|
}
|
|
173
42
|
|
|
174
43
|
get deviceInfo() {
|
|
@@ -188,46 +57,6 @@ class DeviceManager extends DeviceManagerInterface {
|
|
|
188
57
|
return super.deviceInfo;
|
|
189
58
|
}
|
|
190
59
|
|
|
191
|
-
getHdmiStatus() {
|
|
192
|
-
if (window.cefQuery) {
|
|
193
|
-
const FCID = getFCID();
|
|
194
|
-
const message = {
|
|
195
|
-
type: "getHdmiStatus",
|
|
196
|
-
fcid: FCID
|
|
197
|
-
};
|
|
198
|
-
const request = { target: "TC", waitForResponse: true, message: JSON.stringify(message) };
|
|
199
|
-
sdkLogger.log("Sending getHdmiStatus request");
|
|
200
|
-
return new Promise((resolve, reject) => {
|
|
201
|
-
let timerId = 0;
|
|
202
|
-
const timeBeforeSendingRequest = Date.now();
|
|
203
|
-
const queryId = window.cefQuery({
|
|
204
|
-
request: JSON.stringify(request),
|
|
205
|
-
persistent: false,
|
|
206
|
-
onSuccess: (data) => {
|
|
207
|
-
timerId = clearTimer(timerId);
|
|
208
|
-
const duration = Date.now() - timeBeforeSendingRequest;
|
|
209
|
-
sdkLogger.withFields({ duration }).log(`getHdmiStatus completed successfully after ${duration} ms with data: ${data}`);
|
|
210
|
-
const hdmiStatus = this._translateHdmiStatus(data ? data : "{}");
|
|
211
|
-
resolve(hdmiStatus);
|
|
212
|
-
},
|
|
213
|
-
onFailure: (code, msg) => {
|
|
214
|
-
const duration = Date.now() - timeBeforeSendingRequest;
|
|
215
|
-
sdkLogger.withFields({ duration }).log(`getHdmiStatus failed after ${duration} ms. Error code: ${code}, error message: ${msg}`);
|
|
216
|
-
timerId = clearTimer(timerId);
|
|
217
|
-
reject(new SenzaError(code, msg));
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
sdkLogger.log(`window.cefQuery for getHdmiStatus returned query id ${queryId}`);
|
|
221
|
-
const timeout = API_CONFIRMATION_TIMEOUT_MS + 1000;
|
|
222
|
-
timerId = setTimeout(() => {
|
|
223
|
-
sdkLogger.log(`getHdmiStatus reached timeout of ${timeout} ms, canceling query id ${queryId}`);
|
|
224
|
-
window.cefQueryCancel(queryId);
|
|
225
|
-
reject(new SenzaError(6000, `getHdmiStatus reached timeout of ${timeout} ms`));
|
|
226
|
-
}, timeout, queryId);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
60
|
reboot() {
|
|
232
61
|
return new Promise((resolve, reject) => {
|
|
233
62
|
if (window.cefQuery) {
|
|
@@ -344,12 +173,12 @@ class DeviceManager extends DeviceManagerInterface {
|
|
|
344
173
|
reject(`factoryReset failed: ${code} ${msg}`);
|
|
345
174
|
}
|
|
346
175
|
});
|
|
347
|
-
|
|
176
|
+
|
|
348
177
|
timeoutHandler = setTimeout(() => {
|
|
349
|
-
logger.error(`factoryReset failed: reached timeout of ${
|
|
178
|
+
logger.error(`factoryReset failed: reached timeout of ${FACTORY_RESET_TIMEOUT_SECONDS * 1000} ms`);
|
|
350
179
|
window.cefQueryCancel(queryId);
|
|
351
|
-
reject(`factoryReset failed: reached timeout of ${
|
|
352
|
-
},
|
|
180
|
+
reject(`factoryReset failed: reached timeout of ${FACTORY_RESET_TIMEOUT_SECONDS * 1000} ms`);
|
|
181
|
+
}, FACTORY_RESET_TIMEOUT_SECONDS * 1000);
|
|
353
182
|
});
|
|
354
183
|
}
|
|
355
184
|
|