senza-sdk 4.2.65-d2761c0.0 → 4.3.1-ca3d96f.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/dist/bundle.js +1 -1
- package/package.json +17 -8
- package/src/api.js +258 -327
- package/src/{alarmManager.js → implementation/alarmManager.js} +15 -52
- package/src/implementation/api.js +363 -0
- package/src/{deviceManager.js → implementation/deviceManager.js} +6 -78
- package/src/{lifecycle.js → implementation/lifecycle.js} +37 -225
- package/src/implementation/messageManager.js +55 -0
- package/src/{platformManager.js → implementation/platformManager.js} +5 -23
- package/src/{remotePlayer.js → implementation/remotePlayer.js} +35 -237
- package/src/{senzaShakaPlayer.js → implementation/senzaShakaPlayer.js} +92 -125
- package/src/{utils.js → implementation/utils.js} +15 -6
- package/src/interface/alarmManager.js +76 -0
- package/src/interface/api.js +8 -0
- package/src/{devSequence.js → interface/devSequence.js} +35 -0
- package/src/interface/deviceManager.js +142 -0
- package/src/interface/lifecycle.js +283 -0
- package/src/interface/messageManager.js +53 -0
- package/src/interface/platformManager.js +41 -0
- package/src/interface/remotePlayer.js +470 -0
- package/src/interface/senzaShakaPlayer.js +168 -0
- package/src/interface/utils.js +45 -0
- package/src/messageManager.js +0 -88
- /package/src/{SessionInfo.js → implementation/SessionInfo.js} +0 -0
- /package/src/{devHelper.js → implementation/devHelper.js} +0 -0
- /package/src/{eventListenersManager.js → implementation/eventListenersManager.js} +0 -0
- /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,363 @@
|
|
|
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
|
+
/** @namespace auth
|
|
12
|
+
*@example
|
|
13
|
+
* import { auth } from "senza-sdk";
|
|
14
|
+
**/
|
|
15
|
+
export const auth = {
|
|
16
|
+
|
|
17
|
+
/** Should be called upon startup and be embedded in future requests */
|
|
18
|
+
getToken,
|
|
19
|
+
|
|
20
|
+
/** Should be called upon '401' event (unauthorized) */
|
|
21
|
+
forceTokenUpdate,
|
|
22
|
+
|
|
23
|
+
getClientAssertion
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
import { remotePlayer } from "./remotePlayer.js";
|
|
28
|
+
export { remotePlayer };
|
|
29
|
+
|
|
30
|
+
/** Should be called once to init the library
|
|
31
|
+
*@example
|
|
32
|
+
* import { init } from "senza-sdk";
|
|
33
|
+
* await init();
|
|
34
|
+
**/
|
|
35
|
+
export async function init(interfaceApiVersion, showSequenceFunc, initSequenceFunc) {
|
|
36
|
+
interfaceVersion = interfaceApiVersion;
|
|
37
|
+
sdkLogger.addfields({ interfaceVersion });
|
|
38
|
+
sdkLogger.log(`init. Interface version: ${interfaceVersion}. Implementation version: ${getVersion()}`);
|
|
39
|
+
|
|
40
|
+
if (!window.diagnostics) {
|
|
41
|
+
// ------------------------------------------------------------------------------------------------
|
|
42
|
+
// -- Do NOT change this log, as ui-streamer is checking this string to detect abnormal behavior --
|
|
43
|
+
// ------------------------------------------------------------------------------------------------
|
|
44
|
+
sdkLogger.error("[ init ] window.diagnostics is undefined");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (window.cefQuery) {
|
|
48
|
+
|
|
49
|
+
// First, check compatability with ui-streamer api version
|
|
50
|
+
await new Promise((resolve, reject) => {
|
|
51
|
+
window.cefQuery({
|
|
52
|
+
request: "apiVersion " + API_VERSION,
|
|
53
|
+
persistent: false,
|
|
54
|
+
onSuccess: () => {
|
|
55
|
+
sdkLogger.log("api version compatability check succeeded");
|
|
56
|
+
resolve();
|
|
57
|
+
},
|
|
58
|
+
onFailure: (code, msg) => {
|
|
59
|
+
sdkLogger.error("api version compatability check failed: " + msg);
|
|
60
|
+
reject(msg);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const sessionInfoStr = await new Promise((resolve) => {
|
|
66
|
+
window.cefQuery({
|
|
67
|
+
request: "sessionInfo",
|
|
68
|
+
persistent: false,
|
|
69
|
+
onSuccess: (response) => {
|
|
70
|
+
sdkLogger.log("sessionInfo request successfully returned " + response);
|
|
71
|
+
resolve(response);
|
|
72
|
+
},
|
|
73
|
+
onFailure: (code, msg) => {
|
|
74
|
+
sdkLogger.error(`sessionInfo request failed: ${code} ${msg}`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
sessionInfo.setSessionInfoStr(sessionInfoStr);
|
|
80
|
+
const sessionInfoObj = JSON.parse(sessionInfoStr);
|
|
81
|
+
authToken = sessionInfoObj?.settings?.webUI?.backendHeaders?.Authorization;
|
|
82
|
+
sdkLogger.log(`authToken: token = ${authToken}`);
|
|
83
|
+
// Listen to updateSession event to set the new token
|
|
84
|
+
document.addEventListener("updateSession", (e) => {
|
|
85
|
+
authToken = e.detail?.updateObj;
|
|
86
|
+
sdkLogger.log(`onUpdateSessionEvent: token = ${authToken}`);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Set default alarm timeout using UI-Streamer settings
|
|
90
|
+
const alarmTimeout = sessionInfoObj?.settings?.["ui-streamer"]?.alarmTimeout;
|
|
91
|
+
if (alarmTimeout) {
|
|
92
|
+
alarmManager._setDefaultTimeout(alarmTimeout);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Get trigger event
|
|
96
|
+
const triggerEventStr = await new Promise((resolve) => {
|
|
97
|
+
const FCID = getFCID();
|
|
98
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
99
|
+
const message = { type: "triggerEvent", fcid: FCID };
|
|
100
|
+
const request = { target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message) };
|
|
101
|
+
window.cefQuery({
|
|
102
|
+
request: JSON.stringify(request),
|
|
103
|
+
persistent: false,
|
|
104
|
+
onSuccess: (response) => {
|
|
105
|
+
logger.log(`triggerEvent request successfully returned '${response}'`);
|
|
106
|
+
resolve(response);
|
|
107
|
+
},
|
|
108
|
+
onFailure: (code, msg) => {
|
|
109
|
+
logger.error(`triggerEvent request failed: ${code} ${msg}`);
|
|
110
|
+
resolve("");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
let triggerEvent = {};
|
|
115
|
+
if (triggerEventStr) {
|
|
116
|
+
try {
|
|
117
|
+
triggerEvent = JSON.parse(triggerEventStr);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
sdkLogger.error(`failed to parse trigger event string ${triggerEventStr}: ${e.message}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Initialize lifecycle first to make sure the state is updated.
|
|
124
|
+
await lifecycle._init(sessionInfoObj?.settings?.["ui-streamer"], triggerEvent);
|
|
125
|
+
await remotePlayer._init(sessionInfoObj?.settings?.["ui-streamer"], triggerEvent);
|
|
126
|
+
|
|
127
|
+
const devSequence = sessionInfoObj?.settings?.["ui-streamer"]?.devSequence;
|
|
128
|
+
if (devSequence) {
|
|
129
|
+
initSequenceFunc({ lifecycle, remotePlayer });
|
|
130
|
+
showSequenceFunc(true);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
} else {
|
|
134
|
+
authToken = getPlatformInfo().sessionInfo?.settings?.webUI?.backendHeaders?.Authorization;
|
|
135
|
+
sdkLogger.log(`authToken dummy: token = ${authToken}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// override window.close() since it's not allowed to close the application this way
|
|
139
|
+
window.close = () => {
|
|
140
|
+
sdkLogger.warn("window.close is disabled on Senza platform. Use lifecycle.exitApplication() instead.");
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Returns the platform information, including version, pod, pod ip and session info.
|
|
147
|
+
export function getPlatformInfo() {
|
|
148
|
+
if (typeof window !== "undefined" && window.diagnostics) {
|
|
149
|
+
try {
|
|
150
|
+
const platformInfo = window.diagnostics() || {};
|
|
151
|
+
platformInfo.sessionInfo = sessionInfo.sessionInfoObj;
|
|
152
|
+
return platformInfo;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
sdkLogger.error("Could not get platform info", e.stack);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} else {
|
|
158
|
+
if (typeof window !== "undefined" && !window.diagnostics) {
|
|
159
|
+
sdkLogger.error("[ getPlatformInfo ] window.diagnostics is undefined");
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
version: "X.X.XX-X",
|
|
163
|
+
pod: "ui-streamer-X.X.XX-X-QWERT-ASDFG-XXX-XXXXXX-XXXXX",
|
|
164
|
+
podIP: "0.0.0.0",
|
|
165
|
+
sessionInfo: {
|
|
166
|
+
userAgent: "SynamediaSenza/XX.YY.ZZ",
|
|
167
|
+
connectionId: "dummy",
|
|
168
|
+
deviceId: "123456789",
|
|
169
|
+
community: "LocalDev",
|
|
170
|
+
tenant: "XXXXXX",
|
|
171
|
+
tenantId: "XXXXXX",
|
|
172
|
+
manifest: {
|
|
173
|
+
transcontainer: "X.X.XX-X"
|
|
174
|
+
},
|
|
175
|
+
settings: {
|
|
176
|
+
webUI: {
|
|
177
|
+
backendHeaders: {
|
|
178
|
+
Authorization: "Bearer dummytoken"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
homeSessionInfo: {
|
|
183
|
+
tenantId: "XXXXXX",
|
|
184
|
+
community: "LocalDev"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function getToken() {
|
|
192
|
+
if (!authToken) {
|
|
193
|
+
sdkLogger.log("getToken wait for promise updateSession event");
|
|
194
|
+
return new Promise((resolve) => {
|
|
195
|
+
// Listen to updateSession event to set the new token
|
|
196
|
+
document.addEventListener("updateSession", (e) => {
|
|
197
|
+
authToken = e.detail?.updateObj;
|
|
198
|
+
sdkLogger.log(`onUpdateSessionEvent: token= ${authToken}`);
|
|
199
|
+
resolve(authToken);
|
|
200
|
+
}, { once: true });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return Promise.resolve(authToken);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function forceTokenUpdate() {
|
|
207
|
+
authToken = null;
|
|
208
|
+
|
|
209
|
+
if (window.cefQuery) {
|
|
210
|
+
const FCID = getFCID();
|
|
211
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
212
|
+
logger.log("forceTokenUpdate: sending updateSessionRequest");
|
|
213
|
+
const message = {
|
|
214
|
+
type: "updateSessionRequest",
|
|
215
|
+
updateKey: "authorization",
|
|
216
|
+
parentPath: "settings.webUI.backendHeaders.Authorization",
|
|
217
|
+
fcid: FCID
|
|
218
|
+
};
|
|
219
|
+
const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
|
|
220
|
+
window.cefQuery({
|
|
221
|
+
request: JSON.stringify(request),
|
|
222
|
+
persistent: false,
|
|
223
|
+
onSuccess: () => {
|
|
224
|
+
logger.log("updateSessionRequest successfully sent");
|
|
225
|
+
},
|
|
226
|
+
onFailure: (code, msg) => {
|
|
227
|
+
logger.error(`updateSessionRequest failed: ${code} ${msg}`);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
sdkLogger.error("forceTokenUpdate: window.cefQuery is undefined");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Returns a boolean that indicates whether we are running in an e2e environment, or on local browser */
|
|
236
|
+
export function isRunningE2E() {
|
|
237
|
+
return !!(typeof window !== "undefined" && window.cefQuery);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Call this API once after application startup, when the ui is ready to accept keys/events */
|
|
241
|
+
export function uiReady() {
|
|
242
|
+
if (window.cefQuery) {
|
|
243
|
+
window.cefQuery({
|
|
244
|
+
request: "uiReady",
|
|
245
|
+
persistent: false,
|
|
246
|
+
onSuccess: () => {
|
|
247
|
+
sdkLogger.log("uiReady request successfully sent");
|
|
248
|
+
},
|
|
249
|
+
onFailure: (code, msg) => {
|
|
250
|
+
sdkLogger.error(`uiReady request failed: ${code} ${msg}`);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
} else {
|
|
254
|
+
sdkLogger.error("uiReady: window.cefQuery is undefined");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { lifecycle } from "./lifecycle.js";
|
|
259
|
+
export { deviceManager } from "./deviceManager.js";
|
|
260
|
+
export { platformManager } from "./platformManager.js";
|
|
261
|
+
export { alarmManager };
|
|
262
|
+
export { messageManager } from "./messageManager.js";
|
|
263
|
+
export { SenzaShakaPlayer as ShakaPlayer, shaka } from "./senzaShakaPlayer.js";
|
|
264
|
+
|
|
265
|
+
import "./devHelper.js";
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The function receives a license response and passes it to platform.
|
|
269
|
+
* @param {number} statusCode status code that was received from the license server
|
|
270
|
+
* @param {ArrayBuffer|string} licenseResponse a license response that was received from the license server to be passed to platform.
|
|
271
|
+
* @param {string} fcid a fcid received with the license request
|
|
272
|
+
* @param {string} sessionId a sessionId received with the license request
|
|
273
|
+
* In case of success licenceResponse is of type @type {ArrayBuffer}
|
|
274
|
+
* In case of error licenseResponse is of type @type {string}
|
|
275
|
+
*/
|
|
276
|
+
export function writeLicenseResponse(statusCode, licenseResponse, fcid, sessionId) {
|
|
277
|
+
|
|
278
|
+
if (statusCode >= 200 && statusCode < 300) {
|
|
279
|
+
licenseResponse = window.btoa(String.fromCharCode.apply(null, new Uint8Array(licenseResponse))); // to base64
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (window.cefQuery) {
|
|
283
|
+
const message = {
|
|
284
|
+
type: "updateLicense",
|
|
285
|
+
sessionId,
|
|
286
|
+
fcid
|
|
287
|
+
};
|
|
288
|
+
message[statusCode >= 200 && statusCode < 300 ? "response" : "error"] = licenseResponse;
|
|
289
|
+
const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
|
|
290
|
+
window.cefQuery({
|
|
291
|
+
request: JSON.stringify(request),
|
|
292
|
+
persistent: false,
|
|
293
|
+
onSuccess: () => {
|
|
294
|
+
sdkLogger.log("updateLicense request successfully sent");
|
|
295
|
+
},
|
|
296
|
+
onFailure: (code, msg) => {
|
|
297
|
+
sdkLogger.error(`updateLicense request failed: ${code} ${msg}`);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export class ClientAssertionError extends Error {
|
|
305
|
+
constructor(code, message) {
|
|
306
|
+
super(message);
|
|
307
|
+
this.code = code;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @typedef Token
|
|
313
|
+
* @property {string} hostplatform_assertion The client assertion token.
|
|
314
|
+
*/
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Async function that returns the client assertion
|
|
318
|
+
* @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.
|
|
319
|
+
* Failure to getClientAssertion for any reason, result in the promise being rejected.
|
|
320
|
+
* Error status codes:
|
|
321
|
+
* Status code 400 - Tenant configuration is missing
|
|
322
|
+
* Status code 0 - General error
|
|
323
|
+
* @example
|
|
324
|
+
* try {
|
|
325
|
+
* const client_assertion = await auth.getClientAssertion();
|
|
326
|
+
* console.log("Client assertion token is", client_assertion.hostplatform_assertion);
|
|
327
|
+
* } catch (e) {
|
|
328
|
+
* console.error("getClientAssertion failed", e);
|
|
329
|
+
* }
|
|
330
|
+
*/
|
|
331
|
+
export function getClientAssertion() {
|
|
332
|
+
if (window.cefQuery) {
|
|
333
|
+
sdkLogger.log("getClientAssertion is called");
|
|
334
|
+
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
window.cefQuery({
|
|
337
|
+
request: "client_assertion",
|
|
338
|
+
persistent: false,
|
|
339
|
+
onSuccess: (response) => {
|
|
340
|
+
try {
|
|
341
|
+
const json_response = JSON.parse(response);
|
|
342
|
+
sdkLogger.log(`client_assertion request successfully returned ${response}`);
|
|
343
|
+
resolve(json_response);
|
|
344
|
+
} catch (e) {
|
|
345
|
+
sdkLogger.error(`Failed to parse client assertion ${response}: ${e.message}`);
|
|
346
|
+
reject(new ClientAssertionError(0, "Failed to parse client assertion"));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
},
|
|
350
|
+
onFailure: (code, msg) => {
|
|
351
|
+
sdkLogger.log(`client_assertion request failed: ${code} ${msg}`);
|
|
352
|
+
reject(new ClientAssertionError(code, msg));
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
sdkLogger.warn("getClientAssertion is not supported if NOT running e2e");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
import * as senzaSDK from "./api.js";
|
|
361
|
+
if (typeof window !== "undefined") {
|
|
362
|
+
window.senzaSDKImplementation = window.senzaSDKImplementation || senzaSDK; // this is only for testing purposes which allows us to use and test senza APIs in pipeline tests
|
|
363
|
+
}
|
|
@@ -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 (
|
|
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
|
-
|
|
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";
|