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.
Files changed (27) hide show
  1. package/dist/bundle.js +1 -1
  2. package/package.json +17 -8
  3. package/src/api.js +258 -327
  4. package/src/{alarmManager.js → implementation/alarmManager.js} +15 -52
  5. package/src/implementation/api.js +363 -0
  6. package/src/{deviceManager.js → implementation/deviceManager.js} +6 -78
  7. package/src/{lifecycle.js → implementation/lifecycle.js} +37 -225
  8. package/src/implementation/messageManager.js +55 -0
  9. package/src/{platformManager.js → implementation/platformManager.js} +5 -23
  10. package/src/{remotePlayer.js → implementation/remotePlayer.js} +35 -237
  11. package/src/{senzaShakaPlayer.js → implementation/senzaShakaPlayer.js} +92 -125
  12. package/src/{utils.js → implementation/utils.js} +15 -6
  13. package/src/interface/alarmManager.js +76 -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 +142 -0
  17. package/src/interface/lifecycle.js +283 -0
  18. package/src/interface/messageManager.js +53 -0
  19. package/src/interface/platformManager.js +41 -0
  20. package/src/interface/remotePlayer.js +470 -0
  21. package/src/interface/senzaShakaPlayer.js +168 -0
  22. package/src/interface/utils.js +45 -0
  23. package/src/messageManager.js +0 -88
  24. /package/src/{SessionInfo.js → implementation/SessionInfo.js} +0 -0
  25. /package/src/{devHelper.js → implementation/devHelper.js} +0 -0
  26. /package/src/{eventListenersManager.js → implementation/eventListenersManager.js} +0 -0
  27. /package/src/{subtitlesUtils.js → implementation/subtitlesUtils.js} +0 -0
@@ -0,0 +1,142 @@
1
+ import { sdkLogger, noop } from "./utils.js";
2
+
3
+ const wifiInfo = {
4
+ level: 0,
5
+ quality: 0,
6
+ ssid: "unknown",
7
+ bssid: "unknown"
8
+ };
9
+ /**
10
+ * @deprecated Instead, call deviceManager.getWifiInfo() periodically
11
+ * @event DeviceManager#wifiInfoUpdated
12
+ * @example
13
+ * deviceManager.addEventListener("wifiInfoUpdated", () => {
14
+ * console.info("Wifi info has been updated to", deviceManager.wifiInfo);
15
+ * });
16
+ *
17
+ */
18
+ /**
19
+ * DeviceManager is a singleton class that manages the device
20
+ */
21
+ export class DeviceManager extends EventTarget {
22
+ /**
23
+ * @property {object} DeviceInfo
24
+ * @property {string} DeviceInfo.deviceId
25
+ * @property {string} DeviceInfo.modelNumber
26
+ * @property {string} DeviceInfo.connectionId
27
+ * @property {string} DeviceInfo.community
28
+ * @property {string} DeviceInfo.tenant
29
+ * @property {string} DeviceInfo.clientIp
30
+ * @property {string} DeviceInfo.countryCode A 2-letter code as defined in ISO_3166-1
31
+ * @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.
32
+ */
33
+ get deviceInfo() {
34
+ sdkLogger.log("getDeviceInfo running locally, returning dummy info");
35
+ return {
36
+ deviceId: "123456789",
37
+ modelNumber: "ABC",
38
+ connectionId: "dummy",
39
+ community: "LocalDev",
40
+ tenant: "XXXXXX",
41
+ clientIp: "0.0.0.0",
42
+ countryCode: "XX",
43
+ connectionType: "simulator"
44
+ };
45
+
46
+ }
47
+
48
+ /**
49
+ * @deprecated use deviceManager.getWifiInfo() instead
50
+ * @property {object} WifiInfo
51
+ * @property {number} WifiInfo.level
52
+ * @property {number} WifiInfo.quality
53
+ * @property {string} WifiInfo.ssid
54
+ * @property {string} WifiInfo.bssid
55
+ */
56
+ get wifiInfo() {
57
+ return wifiInfo;
58
+ }
59
+
60
+ /**
61
+ * Reboot the device
62
+ * @return {Promise} Promise which is resolved when the reboot command has been successfully processed.
63
+ * Failure to process the reboot command will result in the promise being rejected.
64
+ */
65
+ reboot() {
66
+ return noop("DeviceManager.reboot");
67
+ }
68
+
69
+ /**
70
+ * Delete current wifi configuration and forget network
71
+ * @return {Promise} Promise which is resolved when the clearWifi command has been successfully processed.
72
+ * Failure to process the clearWifi command will result in the promise being rejected.
73
+ */
74
+ clearWifi() {
75
+ return noop("DeviceManager.clearWifi");
76
+ }
77
+
78
+ /**
79
+ * Send raw data directly to a customer's device via the USB serial connection of a Senza device.
80
+ * This function is specifically designed for customers who have their devices connected to a Senza device.
81
+ * Using this API, these customers can transmit messages or data directly to their connected devices.
82
+ * The transmission occurs through the Senza device's USB serial interface, facilitating direct communication
83
+ * between the customer's web application and their device.
84
+ * @param {String} data raw data to be passed to the device
85
+ * @return {Promise} Promise which is resolved when the command has been successfully processed.
86
+ * Failure to process the command will result in the promise being rejected.
87
+ */
88
+ sendDataToDevice(data) {
89
+ return noop("DeviceManager.sendDataToDevice", data);
90
+ }
91
+
92
+ /**
93
+ * Perform device factory reset.
94
+ * @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.
95
+ * @return {Promise} Promise which is resolved when factoryReset has been successfully performed
96
+ * Failure to factoryReset for any reason, result in the promise being rejected.
97
+ */
98
+ async factoryReset(reboot = true) {
99
+ return noop("DeviceManager.factoryReset", reboot);
100
+ }
101
+
102
+ /**
103
+ * @typedef {Object} WiFiInfo
104
+ * @property {string} ssid the name of the Wi-Fi network that the device is connected to
105
+ * @property {string} bssid the unique identifier of the Wi-Fi access point
106
+ * @property {string} standard the Wi-Fi standard in use, such as 802.11a/b/g/n/ac/ax
107
+ * @property {string} security the type of security protocol used by the Wi-Fi network, such as WEP, WPA, WPA2, or WPA3
108
+ * @property {string} device-mac the MAC address of the device
109
+ * @property {string} device-ip4 the IPv4 address assigned to the device on the Wi-Fi network
110
+ * @property {string} dhcp-server the IP address of the DHCP server that assigned the device's network configuration
111
+ * @property {string[]} dns-server array of IP addresses of the DNS servers the device uses to resolve domain names
112
+ * @property {number} channel the number of the Wi-Fi channel currently being used
113
+ * @property {number} width width of the Wi-Fi channel in megahertz, e.g. 20MHz or 40 MHz channel
114
+ * @property {number} level a measure of the received signal strength, in the range 0 to 100 (the higher, the better). The level value is 100+RSSI (RSSI is the signal strength, measured in decibels)
115
+ * @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.
116
+ * */
117
+
118
+ /**
119
+ * Get Wi-Fi info - access point data and status (the status is cached for 5 seconds)
120
+ * @returns {WiFiInfo} An object containing the Wi-Fi info
121
+ * @alpha API has not yet been released
122
+ * */
123
+ // This api is part of epic HSDEV-4185
124
+ async getWifiInfo() {
125
+ return Promise.resolve({});
126
+ }
127
+ }
128
+
129
+
130
+ /**
131
+ * @module
132
+ * @type {DeviceManager}
133
+ * @example
134
+ * import { deviceManager } from "senza-sdk";
135
+ * const wifiInfo = await deviceManager.getWifiInfo();
136
+ * console.info(wifiInfo.ssid);
137
+ * await deviceManager.clearWifi();
138
+ * deviceManager.reboot();
139
+ *
140
+ * @return {DeviceManager} pointer to the DeviceManager singleton
141
+ */
142
+ "needed for the module doc comment to be recognized";
@@ -0,0 +1,283 @@
1
+ import {
2
+ sdkLogger,
3
+ noop
4
+ } from "./utils.js";
5
+ /**
6
+ * @event Lifecycle#onstatechange
7
+ * @description Fired after transition from one state to another.<br>
8
+ * The flow is: foreground --> inTransitionToBackground --> background --> inTransitionToForeground --> foreground
9
+ * @property {UiState} state - Indicates the new state.
10
+ * @example
11
+ * lifecycle.addEventListener("onstatechange", (e) => {
12
+ * console.log("new state is", e.state);
13
+ * });
14
+ */
15
+
16
+ /**
17
+ * @event Lifecycle#userinactivity
18
+ * @description Fired after the ui has been inactive (i.e. no key presses) for a configurable number of seconds.<br>
19
+ * @property {number} timeout - the number of seconds after which the application will be unloaded.
20
+ * @example
21
+ * lifecycle.addEventListener("userinactivity", (e) => {
22
+ * console.log(`Application will be unloaded in ${e.timeout} seconds`);
23
+ * });
24
+ * @alpha API has not yet been released
25
+ */
26
+
27
+ /**
28
+ * @event Lifecycle#userdisconnected
29
+ * @description Fired when the user session ends .
30
+ * This event is useful for cleaning up application state or saving data before the application closes. Event callback should return promise to ensure that the event is handled before the application is terminated
31
+ * @example
32
+ * lifecycle.addEventListener("userdisconnected", () => {
33
+ * console.log("User session ended, cleaning up application state");
34
+ * // Perform any necessary cleanup here
35
+ * });
36
+ */
37
+
38
+ /**
39
+ * Lifecycle is a singleton class that manages the application lifecycle states.<br>
40
+ * @fires onstatechange
41
+ * @fires userinactivity
42
+ * @fires userdisconnected
43
+ */
44
+ export class Lifecycle extends EventTarget {
45
+
46
+ /**
47
+ * @typedef {Object} ConnectReason - The reason the ui app has been loaded
48
+ * @property {string} UNKNOWN
49
+ * @property {string} INITIAL_CONNECTION - Indicates that ui app has been loaded for the first time
50
+ * @property {string} APPLICATION_RELOAD - Indicates that ui app has been reloaded (e.g. after HOME keypress)
51
+ * @property {string} UI_RELEASE - Indicates that ui app has been reloaded after ui release
52
+ * @property {string} UI_TERMINATION - Indicates that ui app has been reloaded due to ui termination
53
+ * @property {string} WEBRTC_ERROR - Indicates that ui app has been reloaded due to webrtc error
54
+ * @property {string} UI_WATCHDOG - Indicates that ui app has been reloaded due to ui watchdog not receiving ui frames
55
+ */
56
+ ConnectReason = Object.freeze({
57
+ UNKNOWN: "unknown",
58
+ INITIAL_CONNECTION: "initial_connection",
59
+ APPLICATION_RELOAD: "reload_app",
60
+ UI_RELEASE: "ui_release",
61
+ UI_TERMINATION: "ui_termination",
62
+ WEBRTC_ERROR: "webrtc_error",
63
+ UI_WATCHDOG: "ui_watchdog"
64
+ });
65
+
66
+ /**
67
+ * @typedef {Object} UiState - The ui lifecycle state
68
+ * @property {string} UNKNOWN - state is unknown at this time
69
+ * @property {string} FOREGROUND - ui is displayed
70
+ * @property {string} IN_TRANSITION_TO_FOREGROUND - ui is about to be displayed
71
+ * @property {string} BACKGROUND - remote player is playing (full screen playback is displayed)
72
+ * @property {string} IN_TRANSITION_TO_BACKGROUND - remote player is about to be playing
73
+ */
74
+ UiState = Object.freeze({
75
+ UNKNOWN: "unknown",
76
+ FOREGROUND: "foreground",
77
+ IN_TRANSITION_TO_FOREGROUND: "inTransitionToForeground",
78
+ BACKGROUND: "background",
79
+ IN_TRANSITION_TO_BACKGROUND: "inTransitionToBackground"
80
+ });
81
+
82
+ /**
83
+ * Configure lifecycle settings
84
+ * @param {Object} config - Configuration object
85
+ * @param {Object} [config.autoBackground] - Auto background settings
86
+ * @param {boolean} [config.autoBackground.enabled] - Enable/disable auto background
87
+ * @param {Object} [config.autoBackground.timeout] - Timeout settings
88
+ * @param {number|false} [config.autoBackground.timeout.playing=30] - Timeout in seconds when video is playing, false to disable
89
+ * @param {number|false} [config.autoBackground.timeout.idle=false] - Timeout in seconds when in UI mode, false to disable
90
+ */
91
+ configure(config) {
92
+ noop("lifecycle.configure", config);
93
+ }
94
+
95
+ /**
96
+ * Get the current configuration settings
97
+ * @returns {Object} The current configuration object
98
+ * @example
99
+ * const config = lifecycle.getConfiguration();
100
+ * console.log(config.autoBackground.enabled); // true/false
101
+ * console.log(config.autoBackground.timeout.playing); // 30
102
+ * console.log(config.autoBackground.timeout.idle); // false
103
+ */
104
+ getConfiguration() {
105
+ return {
106
+ autoBackground: {
107
+ enabled: false,
108
+ timeout: {
109
+ playing: 0,
110
+ idle: 0
111
+ }
112
+ }
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Getter for returning the ui lifecycle state
118
+ * @returns {UiState} the current application lifecycle state
119
+ */
120
+ get state() {
121
+ this._state = this.UiState.UNKNOWN;
122
+ return this._state;
123
+ }
124
+
125
+ /**
126
+ * Getter for returning the application connection reason
127
+ * @returns {ConnectReason} the application connection reason
128
+ */
129
+ get connectReason() {
130
+ return this.ConnectReason.UNKNOWN;
131
+ }
132
+
133
+ /**
134
+ * Getter for returning the event that triggered the reloading of the ui after ui has been released
135
+ * @returns {Object} trigger event
136
+ * @property {string} type - the type of the trigger event (e.g. keyPressEvent, videoPlaybackEvent)
137
+ * @property {object} data - data of the event, dependent on its type (e.g. keyPressEvent has data of keyValue) */
138
+ get triggerEvent() {
139
+ return {};
140
+ }
141
+
142
+ /**
143
+ * @deprecated Use `lifecycle.configure()` instead.
144
+ * Controls the autoBackground feature.<br>
145
+ * When enabled, the application will automatically move to the background state after a configurable
146
+ * period of inactivity. Use the `configure` method to set timeouts for video playback and UI states.
147
+ * @type {boolean}
148
+ * @see {@link Lifecycle#configure}
149
+ */
150
+ set autoBackground(enabled) {
151
+ noop("lifecycle.autoBackground", enabled);
152
+ }
153
+
154
+ get autoBackground() {
155
+ return false;
156
+ }
157
+
158
+ /**
159
+ * @deprecated Use `lifecycle.configure()` instead.
160
+ * The number of seconds of user inactivity before the application moves to the background state while playing video.
161
+ * Use the `configure` method to set this timeout.
162
+ * @type {integer}
163
+ * @default 30
164
+ * @see {@link Lifecycle#configure}
165
+ */
166
+ set autoBackgroundDelay(delay) {
167
+ noop("lifecycle.autoBackgroundDelay", delay);
168
+ }
169
+
170
+ get autoBackgroundDelay() {
171
+ return 0;
172
+ }
173
+
174
+ /**
175
+ * @deprecated Use `lifecycle.configure()` instead.
176
+ * The number of seconds of user inactivity before the application moves to the background state while in the UI (not playing).
177
+ * Use the `configure` method to set this timeout.
178
+ * @type {integer}
179
+ * @default -1
180
+ * @see {@link Lifecycle#configure}
181
+ */
182
+ set autoBackgroundOnUIDelay(delay) {
183
+ noop("lifecycle.autoBackgroundOnUIDelay", delay);
184
+ }
185
+
186
+ get autoBackgroundOnUIDelay() {
187
+ return 0;
188
+ }
189
+
190
+ /**
191
+ * @deprecated use lifecycle.state instead.
192
+ * Async function that returns the ui lifecycle state
193
+ * @returns {UiState} the current application lifecycle state
194
+ * @example
195
+ * try {
196
+ * const state = await lifecycle.getState();
197
+ * console.log("current state is", state);
198
+ * } catch (e) {
199
+ * console.error("getState failed", e);
200
+ * }
201
+ */
202
+ getState() {
203
+ sdkLogger.warn("lifecycle getState is not supported if NOT running e2e");
204
+ }
205
+
206
+ /**
207
+ * Once playback starts on the remote player,
208
+ * the application is moved from foreground to inTransitionToBackground and eventually to background.
209
+ * The application will need to call moveToForeground when it receives an event that needs the UI to be displayed again,
210
+ * for example a key press, a playback end-of-file or a playback error.
211
+ * @return {Promise} Promise which is resolved when the moveToForeground command has been successfully processed.
212
+ * Failure to process the moveToForeground command will result in the promise being rejected.
213
+ */
214
+ moveToForeground() {
215
+ return noop("lifecycle.moveToForeground");
216
+ }
217
+
218
+ /**
219
+ * This method moves the application to the background.
220
+ * It should be called after remotePlayer.play().
221
+ * As a consequence, remote player playback will be displayed in full screen.
222
+ * @example
223
+ * remotePlayer.load("https://example.com/video.mp4", 0);
224
+ * remotePlayer.play();
225
+ * lifecycle.moveToBackground();
226
+ * @return {Promise} Promise which is resolved when the moveToBackground command has been successfully processed.
227
+ * Failure to process the moveToBackground command will result in the promise being rejected.
228
+ */
229
+ moveToBackground() {
230
+ return noop("lifecycle.moveToBackground");
231
+ }
232
+
233
+ /**
234
+ * Use this api to switch to another tenant (other than the home tenant) which will launch the application associated with the tenantId. The tenantId must be configured in the
235
+ * Senza platform. Switching to the home tenant should use the exitApplication().
236
+ * @param {string} tenantId The tenantId to switch
237
+ * @return {Promise} Promise which is resolved when the switchTenant command has been successfully processed.
238
+ * Failure to process the switchTenant command will result in the promise being rejected.
239
+ */
240
+ switchTenant(tenantId) {
241
+ return noop("lifecycle.switchTenant", tenantId);
242
+ }
243
+
244
+ /**
245
+ * Use this api to exit the application which will redirect the browser to the home tenant application.
246
+ * @return {Promise} Promise which is resolved when the exitApplication command has been successfully processed.
247
+ * Failure to process the exitApplication command will result in the promise being rejected.
248
+ */
249
+ exitApplication() {
250
+ return noop("lifecycle.exitApplication");
251
+ }
252
+
253
+ /**
254
+ * Add event listener for lifecycle events
255
+ * @param {string} type - The event type to listen for
256
+ * @param {Function} listener - The callback function. Listeners for 'userdisconnected' events should return a promise to ensure the event is processed before the application exits.
257
+ * @param {Object} options - Event listener options
258
+ */
259
+ addEventListener(type, listener, options) {
260
+ super.addEventListener(type, listener, options);
261
+ }
262
+
263
+ /**
264
+ * Remove event listener
265
+ * @param {string} type - The event type
266
+ * @param {Function} listener - The callback function to remove
267
+ * @param {Object} options - Event listener options
268
+ */
269
+ removeEventListener(type, listener, options) {
270
+ super.removeEventListener(type, listener, options);
271
+ }
272
+ }
273
+
274
+
275
+ /**
276
+ * @module
277
+ * @type {Lifecycle}
278
+ * @example
279
+ * import { lifecycle } from "senza-sdk";
280
+ *
281
+ * @return {Lifecycle} pointer to the Lifecycle singleton
282
+ */
283
+ "needed for the module doc comment to be recognized";
@@ -0,0 +1,53 @@
1
+
2
+ import { noop } from "./utils";
3
+
4
+ /**
5
+ * @typedef {object} MessageDetails - object which contains the content of the message
6
+ * @property {string} eventName - The name of the event message, a property of MessageDetails
7
+ * @property {object} payload - The payload for this event, a property of MessageDetails
8
+ * @property {string} fcid - The flow context for this message, a property of MessageDetails
9
+ */
10
+
11
+ /**
12
+ * message event
13
+ *
14
+ * @event MessageManager#message
15
+ * @type {CustomEvent}
16
+ * @property {MessageDetails} detail - object containing data related to the event:
17
+
18
+ *
19
+ * @description Fired when an external event arrives. This is a generic handler for all messages received for any registered group <br>
20
+ * @example
21
+ * messageManager.addEventListener("message", (e) => {
22
+ * console.log("message arrived with data", e.detail);
23
+ * });
24
+ *
25
+ */
26
+
27
+ /**
28
+ * MessageManager is a singleton class that manages the external messages received by the application. It fires custom events as "message" with the payload as the content
29
+ * @class MessageManager
30
+ * @fires MessageManager#message
31
+ */
32
+ export class MessageManager extends EventTarget {
33
+
34
+ /** Register to specific group(s). This function replaces the previously registered groups
35
+ * @param {Array<String>} groups group events to receive messages.
36
+ * @return {Promise} Promise which is resolved when the registerGroups command has been successfully processed.
37
+ * Failure to process the registerGroups command will result in the promise being rejected.
38
+ * messageManager.registerGroups(["A","B"]);
39
+ * */
40
+ async registerGroups(groups) {
41
+ return noop("MessageManager.registerGroups", groups);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * @module
47
+ * @type {MessageManager}
48
+ * @example
49
+ * import { MessageManager } from "senza-sdk";
50
+ *
51
+ * @return {MessageManager} pointer to the MessageManager singleton
52
+ */
53
+ "needed for the module doc comment to be recognized";
@@ -0,0 +1,41 @@
1
+ import { noop } from "./utils";
2
+ /**
3
+ * PlatformManager is a singleton class that manages the platform
4
+ */
5
+ export class PlatformManager extends EventTarget {
6
+
7
+ /**
8
+ * @returns {Object} appConfig object
9
+ * @property {String[]} territories - a list of territories configured for the tenant.
10
+ * if the list is undefined or empty - there are no restrictions.
11
+ * @example
12
+ * import { platformManager } from "senza-sdk";
13
+ * const appConfig = platformManager.appConfig
14
+ * */
15
+ get appConfig() {
16
+ return {};
17
+ }
18
+
19
+ /**
20
+ *
21
+ * @param {string} timezone the timezone to set to
22
+ * the format of the timezone is according to the standard TZ identifier
23
+ * (e.g. America/Los_Angeles, Asia/Tokyo, Europe/Brussels)
24
+ * for a full list of TZ identifiers, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
25
+ */
26
+ setTimezone(timezone) {
27
+ noop("PlatformManager.setTimezone", timezone);
28
+ }
29
+ }
30
+
31
+ /**
32
+ * @module
33
+ * @type {PlatformManager}
34
+ * @example
35
+ * import { platformManager } from "senza-sdk";
36
+ * console.info(platformManager.appConfig);
37
+ * platformManager.setTimezone("Europe/Brussels");
38
+ *
39
+ * @return {PlatformManager} pointer to the PlatformManager singleton
40
+ */
41
+ "needed for the module doc comment to be recognized";