senza-sdk 4.4.4-86e7d7a.0 → 4.4.4
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 +1 -1
- package/src/api.js +16 -2
- package/src/implementation/api.js +7 -5
- package/src/implementation/deviceManager.js +6 -177
- package/src/implementation/displayManager.js +181 -0
- package/src/implementation/edidParser.js +125 -0
- 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/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
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,13 @@ 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";
|
|
8
9
|
|
|
9
10
|
export { remotePlayer };
|
|
10
|
-
export { lifecycle }
|
|
11
|
+
export { lifecycle };
|
|
11
12
|
export { deviceManager };
|
|
13
|
+
export { displayManager };
|
|
12
14
|
export { platformManager } from "./platformManager.js";
|
|
13
15
|
export { alarmManager };
|
|
14
16
|
export { messageManager };
|
|
@@ -101,9 +103,9 @@ export async function init(interfaceApiVersion, showSequenceFunc, initSequenceFu
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
// Set default device manager event timeout using UI-Streamer settings
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
|
|
106
|
+
const displayManagerEventTimeout = sessionInfoObj?.settings?.["ui-streamer"]?.displayManagerEventTimeout;
|
|
107
|
+
if (displayManagerEventTimeout) {
|
|
108
|
+
displayManager._setDefaultTimeout(displayManagerEventTimeout);
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
// Get trigger event
|
|
@@ -139,7 +141,7 @@ export async function init(interfaceApiVersion, showSequenceFunc, initSequenceFu
|
|
|
139
141
|
await remotePlayer._init(sessionInfoObj, triggerEvent);
|
|
140
142
|
alarmManager._init();
|
|
141
143
|
messageManager._init();
|
|
142
|
-
|
|
144
|
+
await displayManager._init();
|
|
143
145
|
sdkLogger.log("All submodules initialized");
|
|
144
146
|
|
|
145
147
|
|
|
@@ -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
|
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { DisplayManager as DisplayManagerInterface } from "../interface/displayManager";
|
|
2
|
+
import { sdkLogger, getRestResponse } from "./utils";
|
|
3
|
+
import { parseEdid } from "./edidParser";
|
|
4
|
+
import { EventListenersManager } from "./eventListenersManager";
|
|
5
|
+
import { bus, Events } from "./eventBus";
|
|
6
|
+
import { lifecycle } from "./lifecycle";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class DisplayManager extends DisplayManagerInterface {
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
/**
|
|
14
|
+
* Event listeners manager for the displayManager events
|
|
15
|
+
* @type {EventListenersManager}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
this._eventManager = new EventListenersManager({
|
|
19
|
+
timeoutMs: 10000 // Default timeout of 10 seconds, can be overridden by _setDefaultTimeout
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @type {boolean}
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
this._isInitialized = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async _updateDisplayInfo() {
|
|
30
|
+
try {
|
|
31
|
+
const displayInfoResponse = await getRestResponse("display-info");
|
|
32
|
+
const displayInfo = this._parseDisplayInfo(displayInfoResponse);
|
|
33
|
+
this._setDisplayProperties(displayInfo);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
sdkLogger.error(e);
|
|
36
|
+
this._setDisplayProperties({ connection: this.DisplayConnectionStatus.UNKNOWN });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async _init() {
|
|
41
|
+
sdkLogger.log("Initializing DisplayManager");
|
|
42
|
+
await this._updateDisplayInfo();
|
|
43
|
+
if (!this._isInitialized) {
|
|
44
|
+
this._isInitialized = true;
|
|
45
|
+
this._addSenzaEventListeners();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @private Add event listeners for system events
|
|
51
|
+
*/
|
|
52
|
+
_addSenzaEventListeners() {
|
|
53
|
+
bus.addEventListener(Events.LifecycleForeground, () => {
|
|
54
|
+
this._moveToForegroundHasBeenCalled = true;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
typeof document !== "undefined" && document.addEventListener("hs/displayInfoChanged", async (event) => {
|
|
58
|
+
sdkLogger.info("Got hs/displayInfoChanged event with detail", JSON.stringify(event?.detail));
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const displayInfo = this._parseDisplayInfo(event.detail.displayInfo);
|
|
62
|
+
this._setDisplayProperties(displayInfo);
|
|
63
|
+
|
|
64
|
+
const timeBeforeCallbacks = Date.now();
|
|
65
|
+
|
|
66
|
+
// Dispatch event to application and allow a chance to move to foreground.
|
|
67
|
+
// If there are no callbacks or the application doesn't move to foreground, the UI will be disconnected.
|
|
68
|
+
await this._eventManager.dispatch("displayinfochanged", { displayInfo });
|
|
69
|
+
|
|
70
|
+
const callbackDuration = Date.now() - timeBeforeCallbacks;
|
|
71
|
+
sdkLogger.log(`All callbacks for displayInfoChanged are finished within ${callbackDuration}ms`);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
sdkLogger.error("Failed to handle displayInfo update", error);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isTriggering = lifecycle.triggerEvent.type === "displayInfoChanged" && lifecycle._triggerEventFcid && lifecycle._triggerEventFcid === event.detail.fcid;
|
|
77
|
+
if (isTriggering) {
|
|
78
|
+
if (!this._moveToForegroundHasBeenCalled && window.cefQuery) {
|
|
79
|
+
sdkLogger.log("Application is about to be disconnected since didn't move to foreground");
|
|
80
|
+
const message = { type: "disconnect" };
|
|
81
|
+
const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
|
|
82
|
+
window.cefQuery({
|
|
83
|
+
request: JSON.stringify(request),
|
|
84
|
+
persistent: false,
|
|
85
|
+
onSuccess: () => {
|
|
86
|
+
sdkLogger.log("disconnect request successfully sent");
|
|
87
|
+
},
|
|
88
|
+
onFailure: (code, msg) => {
|
|
89
|
+
sdkLogger.error(`disconnect request failed: ${code} ${msg}`);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set the default timeout for display manager event listeners
|
|
99
|
+
* @param {number} timeout - Timeout in milliseconds for display manager event listeners
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
_setDefaultTimeout(timeout) {
|
|
103
|
+
if (typeof timeout === "number" && timeout > 0) {
|
|
104
|
+
this._eventManager.timeoutMs = timeout;
|
|
105
|
+
sdkLogger.log(`displayManager event listener timeout set to ${timeout}ms`);
|
|
106
|
+
} else {
|
|
107
|
+
sdkLogger.warn(`Invalid timeout value: ${timeout}. Must be a positive number.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_setDisplayProperties(displayInfo) {
|
|
112
|
+
|
|
113
|
+
if (displayInfo.connection !== undefined) {
|
|
114
|
+
this.connection = displayInfo.connection;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// If the connection is disconnected/unknown, reset all the display properties
|
|
118
|
+
if (this.connection !== this.DisplayConnectionStatus.CONNECTED) {
|
|
119
|
+
this.selected = undefined;
|
|
120
|
+
this.resolution = undefined;
|
|
121
|
+
this.framerate = undefined;
|
|
122
|
+
this.security = undefined;
|
|
123
|
+
this.make = undefined;
|
|
124
|
+
this.model = undefined;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (const [key, value] of Object.entries(displayInfo)) {
|
|
129
|
+
if (value !== undefined) {
|
|
130
|
+
this[key] = value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_parseDisplayInfo(displayInfoResponseStr) {
|
|
136
|
+
const displayInfoResponse = JSON.parse(displayInfoResponseStr);
|
|
137
|
+
|
|
138
|
+
const displayInfo = {
|
|
139
|
+
connection: displayInfoResponse?.connection,
|
|
140
|
+
selected: displayInfoResponse?.connectedDisplayInfo?.selected,
|
|
141
|
+
resolution: displayInfoResponse?.connectedDisplayInfo?.resolution,
|
|
142
|
+
framerate: displayInfoResponse?.connectedDisplayInfo?.framerate,
|
|
143
|
+
security: displayInfoResponse?.connectedDisplayInfo?.hdcpVersion
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if (displayInfoResponse?.connectedDisplayInfo?.edid) {
|
|
148
|
+
try {
|
|
149
|
+
const { manufacturerName, modelName } = parseEdid(displayInfoResponse.connectedDisplayInfo.edid);
|
|
150
|
+
displayInfo.make = manufacturerName ? manufacturerName : "unknown";
|
|
151
|
+
displayInfo.model = modelName ? modelName : "unknown";
|
|
152
|
+
} catch (error) {
|
|
153
|
+
sdkLogger.error("Failed to parse EDID", error);
|
|
154
|
+
displayInfo.make = "unknown";
|
|
155
|
+
displayInfo.model = "unknown";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return displayInfo;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
addEventListener(type, callback) {
|
|
162
|
+
this._eventManager.addEventListener(type, callback);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
removeEventListener(type, callback) {
|
|
166
|
+
this._eventManager.removeEventListener(type, callback);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @module
|
|
173
|
+
* @type {DisplayManager}
|
|
174
|
+
* @example
|
|
175
|
+
* import { displayManager } from "senza-sdk";
|
|
176
|
+
* const connection = await displayManager.connection;
|
|
177
|
+
* console.info(connection);
|
|
178
|
+
*
|
|
179
|
+
* @return {DisplayManager} pointer to the DisplayManager singleton
|
|
180
|
+
*/
|
|
181
|
+
export const displayManager = new DisplayManager();
|