senza-sdk 4.2.65-90c49ac.0 → 4.3.1-4a01fcf.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.
Files changed (26) hide show
  1. package/dist/bundle.js +1 -1
  2. package/package.json +17 -8
  3. package/src/api.js +248 -329
  4. package/src/{alarmManager.js → implementation/alarmManager.js} +15 -52
  5. package/src/implementation/api.js +367 -0
  6. package/src/{deviceManager.js → implementation/deviceManager.js} +6 -78
  7. package/src/{lifecycle.js → implementation/lifecycle.js} +28 -215
  8. package/src/{messageManager.js → implementation/messageManager.js} +6 -6
  9. package/src/{platformManager.js → implementation/platformManager.js} +5 -4
  10. package/src/{remotePlayer.js → implementation/remotePlayer.js} +33 -27
  11. package/src/{senzaShakaPlayer.js → implementation/senzaShakaPlayer.js} +91 -16
  12. package/src/{utils.js → implementation/utils.js} +15 -6
  13. package/src/interface/alarmManager.js +69 -0
  14. package/src/interface/api.js +8 -0
  15. package/src/{devSequence.js → interface/devSequence.js} +35 -0
  16. package/src/interface/deviceManager.js +133 -0
  17. package/src/interface/lifecycle.js +278 -0
  18. package/src/interface/messageManager.js +46 -0
  19. package/src/interface/platformManager.js +35 -0
  20. package/src/interface/remotePlayer.js +441 -0
  21. package/src/interface/senzaShakaPlayer.js +171 -0
  22. package/src/interface/utils.js +45 -0
  23. /package/src/{SessionInfo.js → implementation/SessionInfo.js} +0 -0
  24. /package/src/{devHelper.js → implementation/devHelper.js} +0 -0
  25. /package/src/{eventListenersManager.js → implementation/eventListenersManager.js} +0 -0
  26. /package/src/{subtitlesUtils.js → implementation/subtitlesUtils.js} +0 -0
@@ -1,29 +1,9 @@
1
+ import { AlarmManager as AlarmManagerInterface } from "../interface/alarmManager";
1
2
  import { getFCID, sdkLogger } from "./utils";
2
3
  import { EventListenersManager } from "./eventListenersManager";
3
4
  import { lifecycle } from "./lifecycle";
4
5
 
5
- /**
6
- * AlarmManager is a singleton class that manages the alarms in the application. It fires events whose types are the names of the alarms.
7
- * @fires MyAlarm
8
- */
9
- class AlarmManager extends EventTarget {
10
-
11
- /**
12
- * alarm event
13
- *
14
- * @event AlarmManager#MyAlarm
15
- * @description Fired when time of 'MyAlarm' arrives. If this alarm triggers the application load and the application doesn't call
16
- * lifecycle.moveToForeground() in the alarm callback (i.e. the application remains in the background after the callback is completed),
17
- * the application will be unloaded.
18
- * NOTE: If you perform async operations in the callback (without moving to foreground), you must wait for the async
19
- * operation to finish before returning from the callback, otherwise the application will be unloaded before the async operation is finished.<br>
20
- * @example
21
- * alarmManager.addEventListener("MyAlarm", async (e) => {
22
- * console.log("alarm MyAlarm arrived with data", e.detail);
23
- * await fetch("http://www.example.com");
24
- * });
25
- * alarmManager.addAlarm("MyAlarm", Date.now() + 60*60*1000, "MyData");
26
- */
6
+ class AlarmManager extends AlarmManagerInterface {
27
7
  constructor() {
28
8
  super();
29
9
 
@@ -36,10 +16,10 @@ class AlarmManager extends EventTarget {
36
16
  timeoutMs: 15000 // Default timeout of 15 seconds, can be overridden by _setDefaultTimeout
37
17
  });
38
18
 
39
- typeof document !== "undefined" && document.addEventListener("hs/alarmFiredEvent",async (e) => {
19
+ typeof document !== "undefined" && document.addEventListener("hs/alarmFiredEvent", async (e) => {
40
20
 
41
21
  if (e.detail?.alarmName) {
42
- const logger = sdkLogger.withFields({alarmName: e.detail?.alarmName});
22
+ const logger = sdkLogger.withFields({ alarmName: e.detail?.alarmName });
43
23
  logger.log("Got hs/alarmFiredEvent", JSON.stringify(e.detail));
44
24
 
45
25
  const timeBeforeAlarmHandling = Date.now();
@@ -53,7 +33,7 @@ class AlarmManager extends EventTarget {
53
33
  this._targetState = sourceState;
54
34
 
55
35
  // Create the custom event with payload
56
- const event = new CustomEvent(e.detail.alarmName, {detail: e.detail.payload});
36
+ const event = new CustomEvent(e.detail.alarmName, { detail: e.detail.payload });
57
37
 
58
38
  // Dispatch the event and wait for all listeners
59
39
  await this._eventManager.dispatch(e.detail.alarmName, event);
@@ -67,7 +47,7 @@ class AlarmManager extends EventTarget {
67
47
  if (!this._moveToForegroundHasBeenCalled && window.cefQuery) {
68
48
  logger.log("Application is about to be terminated since didn't move to foreground");
69
49
  const message = { type: "terminating" };
70
- const request = { target:"TC", waitForResponse: false, message: JSON.stringify(message) };
50
+ const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
71
51
  window.cefQuery({
72
52
  request: JSON.stringify(request),
73
53
  persistent: false,
@@ -113,7 +93,7 @@ class AlarmManager extends EventTarget {
113
93
  this._eventManager.addEventListener(type, callback);
114
94
  }
115
95
 
116
- removeEventListener(type, callback){
96
+ removeEventListener(type, callback) {
117
97
  this._eventManager.removeEventListener(type, callback);
118
98
  }
119
99
 
@@ -126,17 +106,12 @@ class AlarmManager extends EventTarget {
126
106
  this._targetState = "background";
127
107
  }
128
108
 
129
- /** Set alarm to be fired at the specified time, event when ui is released
130
- * @param {string} alarmName unique name for the alarm
131
- * @param {number} alarmTime target time for the alarm to be fired, represented by the number of milliseconds elapsed since the epoch
132
- * @param {string} [data] data to be passed back when the alarm is fired
133
- * */
134
109
  addAlarm(alarmName, alarmTime, data = "", toleranceBefore = 0, toleranceAfter = 0) {
135
110
  if (typeof data !== "string") {
136
111
  throw Error("data must be a string");
137
112
  }
138
113
  const FCID = getFCID();
139
- const logger = sdkLogger.withFields({alarmName, FCID});
114
+ const logger = sdkLogger.withFields({ alarmName, FCID });
140
115
  logger.log(`addAlarm called for ${alarmName} to be fired at ${alarmTime} with tolerance of ${toleranceBefore} minutes before and ${toleranceAfter} minutes after`);
141
116
  if (window.cefQuery) {
142
117
  const message = {
@@ -144,11 +119,11 @@ class AlarmManager extends EventTarget {
144
119
  fcid: FCID,
145
120
  alarmName,
146
121
  alarmTime,
147
- toleranceBefore: Math.trunc(toleranceBefore*60*1000),
148
- toleranceAfter: Math.trunc(toleranceAfter*60*1000),
122
+ toleranceBefore: Math.trunc(toleranceBefore * 60 * 1000),
123
+ toleranceAfter: Math.trunc(toleranceAfter * 60 * 1000),
149
124
  payload: data
150
125
  };
151
- const request = { target:"TC", waitForResponse: false, message: JSON.stringify(message) };
126
+ const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
152
127
  window.cefQuery({
153
128
  request: JSON.stringify(request),
154
129
  persistent: false,
@@ -164,13 +139,9 @@ class AlarmManager extends EventTarget {
164
139
  }
165
140
  }
166
141
 
167
- /** Delete the specified alarm
168
- * @param {string} alarmName name of alarm to be deleted
169
- *
170
- * */
171
142
  deleteAlarm(alarmName) {
172
143
  const FCID = getFCID();
173
- const logger = sdkLogger.withFields({alarmName, FCID});
144
+ const logger = sdkLogger.withFields({ alarmName, FCID });
174
145
  logger.log(`deleteAlarm called for ${alarmName}`);
175
146
  if (window.cefQuery) {
176
147
  const message = {
@@ -178,7 +149,7 @@ class AlarmManager extends EventTarget {
178
149
  fcid: FCID,
179
150
  alarmName
180
151
  };
181
- const request = { target:"TC", waitForResponse: false, message: JSON.stringify(message) };
152
+ const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
182
153
  window.cefQuery({
183
154
  request: JSON.stringify(request),
184
155
  persistent: false,
@@ -194,18 +165,15 @@ class AlarmManager extends EventTarget {
194
165
  }
195
166
  }
196
167
 
197
- /** Delete all alarms
198
- *
199
- * */
200
168
  deleteAllAlarms() {
201
169
  if (window.cefQuery) {
202
170
  const FCID = getFCID();
203
- const logger = sdkLogger.withFields({FCID});
171
+ const logger = sdkLogger.withFields({ FCID });
204
172
  const message = {
205
173
  type: "deleteAllAlarms",
206
174
  fcid: FCID
207
175
  };
208
- const request = { target:"TC", waitForResponse: false, message: JSON.stringify(message) };
176
+ const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
209
177
  window.cefQuery({
210
178
  request: JSON.stringify(request),
211
179
  persistent: false,
@@ -221,11 +189,6 @@ class AlarmManager extends EventTarget {
221
189
  }
222
190
  }
223
191
 
224
- /** Async function that asks for all active alarms
225
- * @returns {Promise} when resolved, returns an array of objects containing alarmName and alarmTime fields
226
- * @throws {string} error string in case of an error
227
- *
228
- * */
229
192
  getActiveAlarms() {
230
193
  throw Error("NOT IMPLEMENTED");
231
194
  // if (window.cefQuery) {
@@ -0,0 +1,367 @@
1
+ import { getFCID, sdkLogger, getVersion } from "./utils.js";
2
+ import { sessionInfo } from "./SessionInfo.js";
3
+ import { lifecycle } from "./lifecycle.js";
4
+ import { alarmManager } from "./alarmManager.js";
5
+
6
+ let authToken;
7
+
8
+ const API_VERSION = "1.0";
9
+ let interfaceVersion;
10
+
11
+ typeof document !== "undefined" && document.addEventListener("keydown", (event) => {
12
+ sdkLogger.log(`Got ${event.key} key`);
13
+ });
14
+
15
+ /** @namespace auth
16
+ *@example
17
+ * import { auth } from "senza-sdk";
18
+ **/
19
+ export const auth = {
20
+
21
+ /** Should be called upon startup and be embedded in future requests */
22
+ getToken,
23
+
24
+ /** Should be called upon '401' event (unauthorized) */
25
+ forceTokenUpdate,
26
+
27
+ getClientAssertion
28
+
29
+ };
30
+
31
+ import { remotePlayer } from "./remotePlayer.js";
32
+ export { remotePlayer };
33
+
34
+ /** Should be called once to init the library
35
+ *@example
36
+ * import { init } from "senza-sdk";
37
+ * await init();
38
+ **/
39
+ export async function init(interfaceApiVersion, showSequenceFunc, initSequenceFunc) {
40
+ interfaceVersion = interfaceApiVersion;
41
+ sdkLogger.addfields({ interfaceVersion });
42
+ sdkLogger.log(`init. Interface version: ${interfaceVersion}. Implementation version: ${getVersion()}`);
43
+
44
+ if (!window.diagnostics) {
45
+ // ------------------------------------------------------------------------------------------------
46
+ // -- Do NOT change this log, as ui-streamer is checking this string to detect abnormal behavior --
47
+ // ------------------------------------------------------------------------------------------------
48
+ sdkLogger.error("[ init ] window.diagnostics is undefined");
49
+ }
50
+
51
+ if (window.cefQuery) {
52
+
53
+ // First, check compatability with ui-streamer api version
54
+ await new Promise((resolve, reject) => {
55
+ window.cefQuery({
56
+ request: "apiVersion " + API_VERSION,
57
+ persistent: false,
58
+ onSuccess: () => {
59
+ sdkLogger.log("api version compatability check succeeded");
60
+ resolve();
61
+ },
62
+ onFailure: (code, msg) => {
63
+ sdkLogger.error("api version compatability check failed: " + msg);
64
+ reject(msg);
65
+ }
66
+ });
67
+ });
68
+
69
+ const sessionInfoStr = await new Promise((resolve) => {
70
+ window.cefQuery({
71
+ request: "sessionInfo",
72
+ persistent: false,
73
+ onSuccess: (response) => {
74
+ sdkLogger.log("sessionInfo request successfully returned " + response);
75
+ resolve(response);
76
+ },
77
+ onFailure: (code, msg) => {
78
+ sdkLogger.error(`sessionInfo request failed: ${code} ${msg}`);
79
+ }
80
+ });
81
+ });
82
+
83
+ sessionInfo.setSessionInfoStr(sessionInfoStr);
84
+ const sessionInfoObj = JSON.parse(sessionInfoStr);
85
+ authToken = sessionInfoObj?.settings?.webUI?.backendHeaders?.Authorization;
86
+ sdkLogger.log(`authToken: token = ${authToken}`);
87
+ // Listen to updateSession event to set the new token
88
+ document.addEventListener("updateSession", (e) => {
89
+ authToken = e.detail?.updateObj;
90
+ sdkLogger.log(`onUpdateSessionEvent: token = ${authToken}`);
91
+ });
92
+
93
+ // Set default alarm timeout using UI-Streamer settings
94
+ const alarmTimeout = sessionInfoObj?.settings?.["ui-streamer"]?.alarmTimeout;
95
+ if (alarmTimeout) {
96
+ alarmManager._setDefaultTimeout(alarmTimeout);
97
+ }
98
+
99
+ // Get trigger event
100
+ const triggerEventStr = await new Promise((resolve) => {
101
+ const FCID = getFCID();
102
+ const logger = sdkLogger.withFields({ FCID });
103
+ const message = { type: "triggerEvent", fcid: FCID };
104
+ const request = { target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message) };
105
+ window.cefQuery({
106
+ request: JSON.stringify(request),
107
+ persistent: false,
108
+ onSuccess: (response) => {
109
+ logger.log(`triggerEvent request successfully returned '${response}'`);
110
+ resolve(response);
111
+ },
112
+ onFailure: (code, msg) => {
113
+ logger.error(`triggerEvent request failed: ${code} ${msg}`);
114
+ resolve("");
115
+ }
116
+ });
117
+ });
118
+ let triggerEvent = {};
119
+ if (triggerEventStr) {
120
+ try {
121
+ triggerEvent = JSON.parse(triggerEventStr);
122
+ } catch (e) {
123
+ sdkLogger.error(`failed to parse trigger event string ${triggerEventStr}: ${e.message}`);
124
+ }
125
+ }
126
+
127
+ // Initialize lifecycle first to make sure the state is updated.
128
+ await lifecycle._init(sessionInfoObj?.settings?.["ui-streamer"], triggerEvent);
129
+ await remotePlayer._init(sessionInfoObj?.settings?.["ui-streamer"], triggerEvent);
130
+
131
+ const devSequence = sessionInfoObj?.settings?.["ui-streamer"]?.devSequence;
132
+ if (devSequence) {
133
+ initSequenceFunc({ lifecycle, remotePlayer });
134
+ showSequenceFunc(true);
135
+ }
136
+
137
+ } else {
138
+ authToken = getPlatformInfo().sessionInfo?.settings?.webUI?.backendHeaders?.Authorization;
139
+ sdkLogger.log(`authToken dummy: token = ${authToken}`);
140
+ }
141
+
142
+ // override window.close() since it's not allowed to close the application this way
143
+ window.close = () => {
144
+ sdkLogger.warn("window.close is disabled on Senza platform. Use lifecycle.exitApplication() instead.");
145
+ };
146
+
147
+
148
+ }
149
+
150
+ // Returns the platform information, including version, pod, pod ip and session info.
151
+ export function getPlatformInfo() {
152
+ if (typeof window !== "undefined" && window.diagnostics) {
153
+ try {
154
+ const platformInfo = window.diagnostics() || {};
155
+ platformInfo.sessionInfo = sessionInfo.sessionInfoObj;
156
+ return platformInfo;
157
+ } catch (e) {
158
+ sdkLogger.error("Could not get platform info", e.stack);
159
+ }
160
+
161
+ } else {
162
+ if (typeof window !== "undefined" && !window.diagnostics) {
163
+ sdkLogger.error("[ getPlatformInfo ] window.diagnostics is undefined");
164
+ }
165
+ return {
166
+ version: "X.X.XX-X",
167
+ pod: "ui-streamer-X.X.XX-X-QWERT-ASDFG-XXX-XXXXXX-XXXXX",
168
+ podIP: "0.0.0.0",
169
+ sessionInfo: {
170
+ userAgent: "SynamediaSenza/XX.YY.ZZ",
171
+ connectionId: "dummy",
172
+ deviceId: "123456789",
173
+ community: "LocalDev",
174
+ tenant: "XXXXXX",
175
+ tenantId: "XXXXXX",
176
+ manifest: {
177
+ transcontainer: "X.X.XX-X"
178
+ },
179
+ settings: {
180
+ webUI: {
181
+ backendHeaders: {
182
+ Authorization: "Bearer dummytoken"
183
+ }
184
+ }
185
+ },
186
+ homeSessionInfo: {
187
+ tenantId: "XXXXXX",
188
+ community: "LocalDev"
189
+ }
190
+ }
191
+ };
192
+ }
193
+ }
194
+
195
+ async function getToken() {
196
+ if (!authToken) {
197
+ sdkLogger.log("getToken wait for promise updateSession event");
198
+ return new Promise((resolve) => {
199
+ // Listen to updateSession event to set the new token
200
+ document.addEventListener("updateSession", (e) => {
201
+ authToken = e.detail?.updateObj;
202
+ sdkLogger.log(`onUpdateSessionEvent: token= ${authToken}`);
203
+ resolve(authToken);
204
+ }, { once: true });
205
+ });
206
+ }
207
+ return Promise.resolve(authToken);
208
+ }
209
+
210
+ function forceTokenUpdate() {
211
+ authToken = null;
212
+
213
+ if (window.cefQuery) {
214
+ const FCID = getFCID();
215
+ const logger = sdkLogger.withFields({ FCID });
216
+ logger.log("forceTokenUpdate: sending updateSessionRequest");
217
+ const message = {
218
+ type: "updateSessionRequest",
219
+ updateKey: "authorization",
220
+ parentPath: "settings.webUI.backendHeaders.Authorization",
221
+ fcid: FCID
222
+ };
223
+ const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
224
+ window.cefQuery({
225
+ request: JSON.stringify(request),
226
+ persistent: false,
227
+ onSuccess: () => {
228
+ logger.log("updateSessionRequest successfully sent");
229
+ },
230
+ onFailure: (code, msg) => {
231
+ logger.error(`updateSessionRequest failed: ${code} ${msg}`);
232
+ }
233
+ });
234
+ } else {
235
+ sdkLogger.error("forceTokenUpdate: window.cefQuery is undefined");
236
+ }
237
+ }
238
+
239
+ /** Returns a boolean that indicates whether we are running in an e2e environment, or on local browser */
240
+ export function isRunningE2E() {
241
+ return !!(typeof window !== "undefined" && window.cefQuery);
242
+ }
243
+
244
+ /** Call this API once after application startup, when the ui is ready to accept keys/events */
245
+ export function uiReady() {
246
+ if (window.cefQuery) {
247
+ window.cefQuery({
248
+ request: "uiReady",
249
+ persistent: false,
250
+ onSuccess: () => {
251
+ sdkLogger.log("uiReady request successfully sent");
252
+ },
253
+ onFailure: (code, msg) => {
254
+ sdkLogger.error(`uiReady request failed: ${code} ${msg}`);
255
+ }
256
+ });
257
+ } else {
258
+ sdkLogger.error("uiReady: window.cefQuery is undefined");
259
+ }
260
+ }
261
+
262
+ export { lifecycle } from "./lifecycle.js";
263
+ export { deviceManager } from "./deviceManager.js";
264
+ export { platformManager } from "./platformManager.js";
265
+ export { alarmManager };
266
+ export { messageManager } from "./messageManager.js";
267
+ export { SenzaShakaPlayer as ShakaPlayer, shaka } from "./senzaShakaPlayer.js";
268
+
269
+ import "./devHelper.js";
270
+
271
+ /**
272
+ * The function receives a license response and passes it to platform.
273
+ * @param {number} statusCode status code that was received from the license server
274
+ * @param {ArrayBuffer|string} licenseResponse a license response that was received from the license server to be passed to platform.
275
+ * @param {string} fcid a fcid received with the license request
276
+ * @param {string} sessionId a sessionId received with the license request
277
+ * In case of success licenceResponse is of type @type {ArrayBuffer}
278
+ * In case of error licenseResponse is of type @type {string}
279
+ */
280
+ export function writeLicenseResponse(statusCode, licenseResponse, fcid, sessionId) {
281
+
282
+ if (statusCode >= 200 && statusCode < 300) {
283
+ licenseResponse = window.btoa(String.fromCharCode.apply(null, new Uint8Array(licenseResponse))); // to base64
284
+ }
285
+
286
+ if (window.cefQuery) {
287
+ const message = {
288
+ type: "updateLicense",
289
+ sessionId,
290
+ fcid
291
+ };
292
+ message[statusCode >= 200 && statusCode < 300 ? "response" : "error"] = licenseResponse;
293
+ const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
294
+ window.cefQuery({
295
+ request: JSON.stringify(request),
296
+ persistent: false,
297
+ onSuccess: () => {
298
+ sdkLogger.log("updateLicense request successfully sent");
299
+ },
300
+ onFailure: (code, msg) => {
301
+ sdkLogger.error(`updateLicense request failed: ${code} ${msg}`);
302
+ }
303
+ });
304
+ }
305
+
306
+ }
307
+
308
+ export class ClientAssertionError extends Error {
309
+ constructor(code, message) {
310
+ super(message);
311
+ this.code = code;
312
+ }
313
+ }
314
+
315
+ /**
316
+ * @typedef Token
317
+ * @property {string} hostplatform_assertion The client assertion token.
318
+ */
319
+
320
+ /**
321
+ * Async function that returns the client assertion
322
+ * @return {Promise<Token>} Promise which is resolved to a client assertion object when getClientAssertion has been successfully performed. * client assertion object contains hostplatform_assertion property which holds the client assertion token.
323
+ * Failure to getClientAssertion for any reason, result in the promise being rejected.
324
+ * Error status codes:
325
+ * Status code 400 - Tenant configuration is missing
326
+ * Status code 0 - General error
327
+ * @example
328
+ * try {
329
+ * const client_assertion = await auth.getClientAssertion();
330
+ * console.log("Client assertion token is", client_assertion.hostplatform_assertion);
331
+ * } catch (e) {
332
+ * console.error("getClientAssertion failed", e);
333
+ * }
334
+ */
335
+ export function getClientAssertion() {
336
+ if (window.cefQuery) {
337
+ sdkLogger.log("getClientAssertion is called");
338
+
339
+ return new Promise((resolve, reject) => {
340
+ window.cefQuery({
341
+ request: "client_assertion",
342
+ persistent: false,
343
+ onSuccess: (response) => {
344
+ try {
345
+ const json_response = JSON.parse(response);
346
+ sdkLogger.log(`client_assertion request successfully returned ${response}`);
347
+ resolve(json_response);
348
+ } catch (e) {
349
+ sdkLogger.error(`Failed to parse client assertion ${response}: ${e.message}`);
350
+ reject(new ClientAssertionError(0, "Failed to parse client assertion"));
351
+ }
352
+
353
+ },
354
+ onFailure: (code, msg) => {
355
+ sdkLogger.log(`client_assertion request failed: ${code} ${msg}`);
356
+ reject(new ClientAssertionError(code, msg));
357
+ }
358
+ });
359
+ });
360
+ }
361
+ sdkLogger.warn("getClientAssertion is not supported if NOT running e2e");
362
+ }
363
+
364
+ import * as senzaSDK from "./api.js";
365
+ if (typeof window !== "undefined") {
366
+ window.senzaSDKImplementation = window.senzaSDKImplementation || senzaSDK; // this is only for testing purposes which allows us to use and test senza APIs in pipeline tests
367
+ }
@@ -1,5 +1,5 @@
1
+ import { DeviceManager as DeviceManagerInterface } from "../interface/deviceManager";
1
2
  import { getFCID, sdkLogger, getRestResponse } from "./utils";
2
- import { isRunningE2E } from "./api";
3
3
  import { sessionInfo } from "./SessionInfo";
4
4
 
5
5
  const wifiInfo = {};
@@ -35,10 +35,7 @@ async function getWifiStatus() {
35
35
  }
36
36
  }
37
37
 
38
- /**
39
- * DeviceManager is a singleton class that manages the device
40
- */
41
- class DeviceManager extends EventTarget {
38
+ class DeviceManager extends DeviceManagerInterface {
42
39
 
43
40
  constructor() {
44
41
  super();
@@ -46,15 +43,7 @@ class DeviceManager extends EventTarget {
46
43
  wifiInfo.quality = 0;
47
44
  wifiInfo.ssid = "unknown";
48
45
  wifiInfo.bssid = "unknown";
49
- /**
50
- * @deprecated Instead, call deviceManager.getWifiInfo() periodically
51
- * @event DeviceManager#wifiInfoUpdated
52
- * @example
53
- * deviceManager.addEventListener("wifiInfoUpdated", () => {
54
- * console.info("Wifi info has been updated to", deviceManager.wifiInfo);
55
- * });
56
- *
57
- */
46
+
58
47
  typeof document !== "undefined" && document.addEventListener("wifiSignalReport", (e) => {
59
48
  wifiInfo.level = e.detail.level;
60
49
  wifiInfo.quality = e.detail.quality;
@@ -65,20 +54,9 @@ class DeviceManager extends EventTarget {
65
54
 
66
55
  }
67
56
 
68
- /**
69
- * @property {object} DeviceInfo
70
- * @property {string} DeviceInfo.deviceId
71
- * @property {string} DeviceInfo.modelNumber
72
- * @property {string} DeviceInfo.connectionId
73
- * @property {string} DeviceInfo.community
74
- * @property {string} DeviceInfo.tenant
75
- * @property {string} DeviceInfo.clientIp
76
- * @property {string} DeviceInfo.countryCode A 2-letter code as defined in ISO_3166-1
77
- * @property {string} DeviceInfo.connectionType The type of device used during the current connection. Possible values are "device" which mean real device, "simulator" - simulated device - that used during development.
78
- */
79
57
  get deviceInfo() {
80
58
  const sessionInfoObj = sessionInfo.sessionInfoObj;
81
- if (isRunningE2E() && sessionInfoObj) {
59
+ if (sessionInfoObj) {
82
60
  return {
83
61
  deviceId: sessionInfoObj.deviceId,
84
62
  modelNumber: sessionInfoObj.modelNumber,
@@ -90,36 +68,13 @@ class DeviceManager extends EventTarget {
90
68
  connectionType: (!sessionInfoObj.connectionType || sessionInfoObj.connectionType === "direct") ? "device" : sessionInfoObj.connectionType
91
69
  };
92
70
  }
93
- sdkLogger.log("getDeviceInfo running locally, returning dummy info");
94
- return {
95
- deviceId: "123456789",
96
- modelNumber: "ABC",
97
- connectionId: "dummy",
98
- community: "LocalDev",
99
- tenant: "XXXXXX",
100
- clientIp: "0.0.0.0",
101
- countryCode: "XX",
102
- connectionType: "simulator"
103
- };
71
+ return super.deviceInfo;
104
72
  }
105
73
 
106
- /**
107
- * @deprecated use deviceManager.getWifiInfo() instead
108
- * @property {object} WifiInfo
109
- * @property {number} WifiInfo.level
110
- * @property {number} WifiInfo.quality
111
- * @property {string} WifiInfo.ssid
112
- * @property {string} WifiInfo.bssid
113
- */
114
74
  get wifiInfo() {
115
75
  return wifiInfo;
116
76
  }
117
77
 
118
- /**
119
- * Reboot the device
120
- * @return {Promise} Promise which is resolved when the reboot command has been successfully processed.
121
- * Failure to process the reboot command will result in the promise being rejected.
122
- */
123
78
  reboot() {
124
79
  return new Promise((resolve, reject) => {
125
80
  if (window.cefQuery) {
@@ -149,11 +104,6 @@ class DeviceManager extends EventTarget {
149
104
  });
150
105
  }
151
106
 
152
- /**
153
- * Delete current wifi configuration and forget network
154
- * @return {Promise} Promise which is resolved when the clearWifi command has been successfully processed.
155
- * Failure to process the clearWifi command will result in the promise being rejected.
156
- */
157
107
  clearWifi() {
158
108
  return new Promise((resolve, reject) => {
159
109
  const FCID = getFCID();
@@ -178,16 +128,6 @@ class DeviceManager extends EventTarget {
178
128
  });
179
129
  }
180
130
 
181
- /**
182
- * Send raw data directly to a customer's device via the USB serial connection of a Senza device.
183
- * This function is specifically designed for customers who have their devices connected to a Senza device.
184
- * Using this API, these customers can transmit messages or data directly to their connected devices.
185
- * The transmission occurs through the Senza device's USB serial interface, facilitating direct communication
186
- * between the customer's web application and their device.
187
- * @param {String} data raw data to be passed to the device
188
- * @return {Promise} Promise which is resolved when the command has been successfully processed.
189
- * Failure to process the command will result in the promise being rejected.
190
- */
191
131
  sendDataToDevice(data) {
192
132
  if (typeof data !== "string") {
193
133
  throw new Error("data must be of type 'string'");
@@ -219,12 +159,6 @@ class DeviceManager extends EventTarget {
219
159
  });
220
160
  }
221
161
 
222
- /**
223
- * Perform device factory reset.
224
- * @param {Boolean} [reboot=true] a flag that is passed to the device to indicate whether it should reboot after the factory reset. defaults to true.
225
- * @return {Promise} Promise which is resolved when factoryReset has been successfully performed
226
- * Failure to factoryReset for any reason, result in the promise being rejected.
227
- */
228
162
  async factoryReset(reboot = true) {
229
163
  if (typeof reboot !== "boolean") {
230
164
  throw new Error("reboot param must be of type 'boolean'");
@@ -282,12 +216,6 @@ class DeviceManager extends EventTarget {
282
216
  * @property {number} quality a measure of the signal quality, in the range 0 to 100 (the higher, the better). The quality value is derived from the signal EVM.
283
217
  * */
284
218
 
285
- /**
286
- * Get Wi-Fi info - access point data and status (the status is cached for 5 seconds)
287
- * @returns {WiFiInfo} An object containing the Wi-Fi info
288
- * @alpha API has not yet been released
289
- * */
290
- // This api is part of epic HSDEV-4185
291
219
  async getWifiInfo() {
292
220
  await Promise.all([getWifiApData(), getWifiStatus()]);
293
221
  return { ...wifi_ap_data, ...wifi_status };
@@ -295,7 +223,7 @@ class DeviceManager extends EventTarget {
295
223
  }
296
224
 
297
225
  /**
298
- *
226
+
299
227
  * @module
300
228
  * @example
301
229
  * import { deviceManager } from "senza-sdk";