senza-sdk 4.4.2 → 4.4.4-86e7d7a.0

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.4.2",
3
+ "version": "4.4.4-86e7d7a.0",
4
4
  "main": "./src/api.js",
5
5
  "description": "API for Senza application",
6
6
  "license": "MIT",
@@ -1,16 +1,16 @@
1
1
  import { DeviceManager as DeviceManagerInterface } from "../interface/deviceManager";
2
- import { getFCID, sdkLogger, getRestResponse } from "./utils";
2
+ import { getFCID, sdkLogger, getRestResponse, clearTimer, SenzaError } from "./utils";
3
3
  import { sessionInfo } from "./SessionInfo";
4
- import {EventListenersManager} from "./eventListenersManager";
5
- import {bus, Events} from "./eventBus";
6
- import {lifecycle} from "./lifecycle";
4
+ import { EventListenersManager } from "./eventListenersManager";
5
+ import { bus, Events } from "./eventBus";
6
+ import { lifecycle } from "./lifecycle";
7
7
 
8
8
  let wifi_ap_data;
9
9
  let wifi_status;
10
10
  let wifi_status_last_update = 0;
11
11
 
12
12
  const WIFI_STATUS_CACHE_SECONDS = 5;
13
- const FACTORY_RESET_TIMEOUT_SECONDS = 5;
13
+ const API_CONFIRMATION_TIMEOUT_MS = 5000;
14
14
 
15
15
  async function getWifiApData() {
16
16
  // Wi-Fi access point data is static, so it needs to be retrieved only once
@@ -80,6 +80,33 @@ class DeviceManager extends DeviceManagerInterface {
80
80
  }
81
81
  }
82
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
+
83
110
  /**
84
111
  * @private Add event listeners for system events
85
112
  */
@@ -91,25 +118,7 @@ class DeviceManager extends DeviceManagerInterface {
91
118
  typeof document !== "undefined" && document.addEventListener("hs/hdmiStatusChanged", async (event) => {
92
119
  sdkLogger.info("Got hs/hdmiStatusChanged event with detail", JSON.stringify(event?.detail));
93
120
 
94
- // Translate the HdmiStatus information to a single HdmiStatus for the application
95
- // 1) cecStatus is a configuration setting from the client. If false, we always return UNKNOWN to the application
96
- // 2) If cecStatus is true, we check the hdmiStatus. If not "connected", the HDMI status is definitely INACTIVE.
97
- // 3) If hdmiStatus is "connected" and cecStatus is true, we rely on the cecActiveSourceStatus to determine the HdmiStatus
98
- let hdmiStatus = this.HdmiStatus.UNKNOWN;
99
- const status = JSON.parse(event?.detail?.hdmiStatus ?? "{}"); // Object containing the 3 statuses
100
- if (status?.cecStatus) {
101
- if (status.hdmiStatus !== "connected") {
102
- hdmiStatus = this.HdmiStatus.INACTIVE;
103
- } else {
104
- const cecActive = this._cecActiveSourceStatusMap[status.cecActiveSourceStatus];
105
- hdmiStatus = cecActive ?? this.HdmiStatus.UNKNOWN;
106
- if (!cecActive) {
107
- sdkLogger.warn(`Unknown CEC active source status: ${status.cecActiveSourceStatus}`);
108
- }
109
- }
110
- } else {
111
- sdkLogger.warn("cec is disabled or no hdmiStatus");
112
- }
121
+ const hdmiStatus = this._translateHdmiStatus(event?.detail?.hdmiStatus);
113
122
 
114
123
  const timeBeforeCallbacks = Date.now();
115
124
 
@@ -179,6 +188,46 @@ class DeviceManager extends DeviceManagerInterface {
179
188
  return super.deviceInfo;
180
189
  }
181
190
 
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
+
182
231
  reboot() {
183
232
  return new Promise((resolve, reject) => {
184
233
  if (window.cefQuery) {
@@ -295,12 +344,12 @@ class DeviceManager extends DeviceManagerInterface {
295
344
  reject(`factoryReset failed: ${code} ${msg}`);
296
345
  }
297
346
  });
298
-
347
+ const timeout = API_CONFIRMATION_TIMEOUT_MS + 1000;
299
348
  timeoutHandler = setTimeout(() => {
300
- logger.error(`factoryReset failed: reached timeout of ${FACTORY_RESET_TIMEOUT_SECONDS * 1000} ms`);
349
+ logger.error(`factoryReset failed: reached timeout of ${timeout} ms`);
301
350
  window.cefQueryCancel(queryId);
302
- reject(`factoryReset failed: reached timeout of ${FACTORY_RESET_TIMEOUT_SECONDS * 1000} ms`);
303
- }, FACTORY_RESET_TIMEOUT_SECONDS * 1000);
351
+ reject(`factoryReset failed: reached timeout of ${timeout} ms`);
352
+ }, timeout);
304
353
  });
305
354
  }
306
355
 
@@ -54,6 +54,16 @@ export class DeviceManager extends EventTarget {
54
54
 
55
55
  }
56
56
 
57
+ /**
58
+ * Get the current HDMI status from the connector
59
+ * @return {Promise<HdmiStatus>} Promise which is resolved when getHdmiStatus has been successfully performed
60
+ * Failure to getHdmiStatus for any reason, results in the promise being rejected.
61
+ * @private
62
+ */
63
+ getHdmiStatus() {
64
+ return noop("DeviceManager.getHdmiStatus");
65
+ }
66
+
57
67
  /**
58
68
  * Reboot the device
59
69
  * @return {Promise} Promise which is resolved when the reboot command has been successfully processed.
@@ -1 +1 @@
1
- export const version = "4.4.2";
1
+ export const version = "4.4.4-86e7d7a.0";