senza-sdk 4.2.65-d2761c0.0 → 4.3.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 (29) hide show
  1. package/dist/bundle.js +1 -1
  2. package/dist/implementation.bundle.js +2 -0
  3. package/dist/implementation.bundle.js.LICENSE.txt +57 -0
  4. package/package.json +18 -9
  5. package/src/api.js +258 -327
  6. package/src/{alarmManager.js → implementation/alarmManager.js} +15 -52
  7. package/src/implementation/api.js +363 -0
  8. package/src/{deviceManager.js → implementation/deviceManager.js} +6 -78
  9. package/src/{lifecycle.js → implementation/lifecycle.js} +37 -225
  10. package/src/implementation/messageManager.js +55 -0
  11. package/src/{platformManager.js → implementation/platformManager.js} +5 -23
  12. package/src/{remotePlayer.js → implementation/remotePlayer.js} +35 -237
  13. package/src/{senzaShakaPlayer.js → implementation/senzaShakaPlayer.js} +92 -125
  14. package/src/{utils.js → implementation/utils.js} +15 -6
  15. package/src/interface/alarmManager.js +76 -0
  16. package/src/interface/api.js +8 -0
  17. package/src/{devSequence.js → interface/devSequence.js} +35 -0
  18. package/src/interface/deviceManager.js +143 -0
  19. package/src/interface/lifecycle.js +284 -0
  20. package/src/interface/messageManager.js +54 -0
  21. package/src/interface/platformManager.js +42 -0
  22. package/src/interface/remotePlayer.js +469 -0
  23. package/src/interface/senzaShakaPlayer.js +168 -0
  24. package/src/interface/utils.js +45 -0
  25. package/src/messageManager.js +0 -88
  26. /package/src/{SessionInfo.js → implementation/SessionInfo.js} +0 -0
  27. /package/src/{devHelper.js → implementation/devHelper.js} +0 -0
  28. /package/src/{eventListenersManager.js → implementation/eventListenersManager.js} +0 -0
  29. /package/src/{subtitlesUtils.js → implementation/subtitlesUtils.js} +0 -0
@@ -1,4 +1,6 @@
1
- import { alarmManager, getPlatformInfo } from "./api";
1
+ import { Lifecycle as LifecycleInterface } from "../interface/lifecycle";
2
+ import { getPlatformInfo } from "./api";
3
+ import { alarmManager } from "./alarmManager";
2
4
  import {
3
5
  getFCID,
4
6
  isAudioSyncConfigured,
@@ -18,82 +20,7 @@ const DEFAULT_AUTO_BACKGROUND_VIDEO_DELAY = 30;
18
20
  const DEFAULT_AUTO_BACKGROUND_UI_DELAY = -1;
19
21
  const DEFAULT_AUTO_BACKGROUND_ENABLED = false;
20
22
 
21
- /**
22
- * Lifecycle is a singleton class that manages the application lifecycle states.<br>
23
- * @fires onstatechange
24
- * @fires userinactivity
25
- * @fires userdisconnected
26
- */
27
- class Lifecycle extends EventTarget {
28
-
29
- /**
30
- * @typedef {Object} ConnectReason - The reason the ui app has been loaded
31
- * @property {string} UNKNOWN
32
- * @property {string} INITIAL_CONNECTION - Indicates that ui app has been loaded for the first time
33
- * @property {string} APPLICATION_RELOAD - Indicates that ui app has been reloaded (e.g. after HOME keypress)
34
- * @property {string} UI_RELEASE - Indicates that ui app has been reloaded after ui release
35
- * @property {string} UI_TERMINATION - Indicates that ui app has been reloaded due to ui termination
36
- * @property {string} WEBRTC_ERROR - Indicates that ui app has been reloaded due to webrtc error
37
- * @property {string} UI_WATCHDOG - Indicates that ui app has been reloaded due to ui watchdog not receiving ui frames
38
- */
39
- ConnectReason = Object.freeze({
40
- UNKNOWN: "unknown",
41
- INITIAL_CONNECTION: "initial_connection",
42
- APPLICATION_RELOAD: "reload_app",
43
- UI_RELEASE: "ui_release",
44
- UI_TERMINATION: "ui_termination",
45
- WEBRTC_ERROR: "webrtc_error",
46
- UI_WATCHDOG: "ui_watchdog"
47
- });
48
-
49
- /**
50
- * @typedef {Object} UiState - The ui lifecycle state
51
- * @property {string} UNKNOWN - state is unknown at this time
52
- * @property {string} FOREGROUND - ui is displayed
53
- * @property {string} IN_TRANSITION_TO_FOREGROUND - ui is about to be displayed
54
- * @property {string} BACKGROUND - remote player is playing (full screen playback is displayed)
55
- * @property {string} IN_TRANSITION_TO_BACKGROUND - remote player is about to be playing
56
- */
57
- UiState = Object.freeze({
58
- UNKNOWN: "unknown",
59
- FOREGROUND: "foreground",
60
- IN_TRANSITION_TO_FOREGROUND: "inTransitionToForeground",
61
- BACKGROUND: "background",
62
- IN_TRANSITION_TO_BACKGROUND: "inTransitionToBackground"
63
- });
64
-
65
- /**
66
- * @event Lifecycle#onstatechange
67
- * @description Fired after transition from one state to another.<br>
68
- * The flow is: foreground --> inTransitionToBackground --> background --> inTransitionToForeground --> foreground
69
- * @property {UiState} state - Indicates the new state.
70
- * @example
71
- * lifecycle.addEventListener("onstatechange", (e) => {
72
- * console.log("new state is", e.state);
73
- * });
74
- */
75
-
76
- /**
77
- * @event Lifecycle#userinactivity
78
- * @description Fired after the ui has been inactive (i.e. no key presses) for a configurable number of seconds.<br>
79
- * @property {number} timeout - the number of seconds after which the application will be unloaded.
80
- * @example
81
- * lifecycle.addEventListener("userinactivity", (e) => {
82
- * console.log(`Application will be unloaded in ${e.timeout} seconds`);
83
- * });
84
- * @alpha API has not yet been released
85
- */
86
-
87
- /**
88
- * @event Lifecycle#userdisconnected
89
- * @description Fired when the user session ends .
90
- * 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
91
- * @example
92
- * lifecycle.addEventListener("userdisconnected", () => {
93
- * console.log("User session ended, cleaning up application state");
94
- * // Perform any necessary cleanup here
95
- * });
96
- */
23
+ class Lifecycle extends LifecycleInterface {
97
24
  constructor() {
98
25
  super();
99
26
 
@@ -102,9 +29,7 @@ class Lifecycle extends EventTarget {
102
29
  * @private
103
30
  */
104
31
  this._isInitialized = false;
105
- this._inTransitionToForeground = false;
106
- this._inTransitionToBackground = false;
107
- this._inTransitionToStandby = false;
32
+ this._inTransition = false;
108
33
 
109
34
  /**
110
35
  * Event listeners manager for the userdisconnected event
@@ -181,7 +106,8 @@ class Lifecycle extends EventTarget {
181
106
  });
182
107
  }
183
108
 
184
- /** @private Initialize the lifecycle
109
+ /**
110
+ * @private Initialize the lifecycle
185
111
  * @param {Object} uiStreamerSettings - UI-streamer portion of the settings taken from session info
186
112
  * @param {Object} [uiStreamerSettings.autoBackground] - Auto background mode configuration
187
113
  * @param {boolean} [uiStreamerSettings.autoBackground.enabled=false] - Enable/disable auto background
@@ -278,14 +204,16 @@ class Lifecycle extends EventTarget {
278
204
  }
279
205
  }
280
206
 
281
- /** @private Checks if auto background is enabled including overrides.
207
+ /**
208
+ * @private Checks if auto background is enabled including overrides.
282
209
  * @returns {boolean}
283
210
  */
284
211
  _isAutoBackgroundEnabled() {
285
212
  return this._autoBackgroundOverrides?.enabled ?? this._autoBackground;
286
213
  }
287
214
 
288
- /** @private Gets the auto background video delay including overrides.
215
+ /**
216
+ * @private Gets the auto background video delay including overrides.
289
217
  * @returns {number}
290
218
  */
291
219
  _getAutoBackgroundOnVideoDelay() {
@@ -296,7 +224,8 @@ class Lifecycle extends EventTarget {
296
224
  return this._autoBackgroundOnVideoDelay;
297
225
  }
298
226
 
299
- /** @private Gets the auto background UI delay including overrides.
227
+ /**
228
+ * @private Gets the auto background UI delay including overrides.
300
229
  * @returns {number}
301
230
  */
302
231
  _getAutoBackgroundOnUIDelay() {
@@ -307,15 +236,6 @@ class Lifecycle extends EventTarget {
307
236
  return this._autoBackgroundOnUIDelay;
308
237
  }
309
238
 
310
- /**
311
- * Configure lifecycle settings
312
- * @param {Object} config - Configuration object
313
- * @param {Object} [config.autoBackground] - Auto background settings
314
- * @param {boolean} [config.autoBackground.enabled] - Enable/disable auto background
315
- * @param {Object} [config.autoBackground.timeout] - Timeout settings
316
- * @param {number|false} [config.autoBackground.timeout.playing=30] - Timeout in seconds when video is playing, false to disable
317
- * @param {number|false} [config.autoBackground.timeout.idle=false] - Timeout in seconds when in UI mode, false to disable
318
- */
319
239
  configure(config) {
320
240
  if (config?.autoBackground) {
321
241
  const { enabled, timeout } = config.autoBackground;
@@ -355,15 +275,6 @@ class Lifecycle extends EventTarget {
355
275
  }
356
276
  }
357
277
 
358
- /**
359
- * Get the current configuration settings
360
- * @returns {Object} The current configuration object
361
- * @example
362
- * const config = lifecycle.getConfiguration();
363
- * console.log(config.autoBackground.enabled); // true/false
364
- * console.log(config.autoBackground.timeout.playing); // 30
365
- * console.log(config.autoBackground.timeout.idle); // false
366
- */
367
278
  getConfiguration() {
368
279
  return {
369
280
  autoBackground: {
@@ -377,6 +288,7 @@ class Lifecycle extends EventTarget {
377
288
  }
378
289
 
379
290
  /**
291
+ * @private
380
292
  * This method moves the application into standby mode, i.e. last ui frame is displayed and ui resources are released.
381
293
  * It should be called whenever the application wishes to go into standby mode and release resources.
382
294
  * @example
@@ -386,7 +298,7 @@ class Lifecycle extends EventTarget {
386
298
  // This api is part of epic HSDEV-713
387
299
  _moveToUiStandby() {
388
300
  if (window.cefQuery) {
389
- this._inTransitionToStandby = true;
301
+ this._inTransition = true;
390
302
  return new Promise((resolve, reject) => {
391
303
  const FCID = getFCID();
392
304
  const request = { target: "TC", waitForResponse: false, internalAction: "uiExit", message: JSON.stringify({ type: "uiStandbyRequest", fcid: FCID }) };
@@ -397,12 +309,12 @@ class Lifecycle extends EventTarget {
397
309
  persistent: false,
398
310
  onSuccess: () => {
399
311
  logger.log("[ moveToUiStandby ] moveToUiStandby successfully sent");
400
- this._inTransitionToStandby = false;
312
+ this._inTransition = false;
401
313
  resolve(true);
402
314
  },
403
315
  onFailure: (code, msg) => {
404
316
  logger.error(`[ moveToUiStandby ] moveToUiStandby failed: ${code} ${msg}`);
405
- this._inTransitionToStandby = false;
317
+ this._inTransition = false;
406
318
  reject(`moveToUiStandby failed: ${code} ${msg}`);
407
319
  }
408
320
  });
@@ -412,10 +324,6 @@ class Lifecycle extends EventTarget {
412
324
  return Promise.resolve(true);
413
325
  }
414
326
 
415
- /**
416
- * Getter for returning the ui lifecycle state
417
- * @returns {UiState} the current application lifecycle state
418
- */
419
327
  get state() {
420
328
  if (!this._isInitialized) {
421
329
  this._state = this.UiState.UNKNOWN;
@@ -423,10 +331,6 @@ class Lifecycle extends EventTarget {
423
331
  return this._state;
424
332
  }
425
333
 
426
- /**
427
- * Getter for returning the application connection reason
428
- * @returns {ConnectReason} the application connection reason
429
- */
430
334
  get connectReason() {
431
335
  if (!this._isInitialized) {
432
336
  this._connectReason = this.ConnectReason.UNKNOWN;
@@ -434,11 +338,6 @@ class Lifecycle extends EventTarget {
434
338
  return this._connectReason;
435
339
  }
436
340
 
437
- /**
438
- * Getter for returning the event that triggered the reloading of the ui after ui has been released
439
- * @returns {Object} trigger event
440
- * @property {string} type - the type of the trigger event (e.g. keyPressEvent, videoPlaybackEvent)
441
- * @property {object} data - data of the event, dependent on its type (e.g. keyPressEvent has data of keyValue) */
442
341
  get triggerEvent() {
443
342
  if (!this._isInitialized) {
444
343
  this._triggerEvent = {};
@@ -446,14 +345,6 @@ class Lifecycle extends EventTarget {
446
345
  return this._triggerEvent;
447
346
  }
448
347
 
449
- /**
450
- * @deprecated Use `lifecycle.configure()` instead.
451
- * Controls the autoBackground feature.<br>
452
- * When enabled, the application will automatically move to the background state after a configurable
453
- * period of inactivity. Use the `configure` method to set timeouts for video playback and UI states.
454
- * @type {boolean}
455
- * @see {@link Lifecycle#configure}
456
- */
457
348
  set autoBackground(enabled) {
458
349
  this._autoBackground = enabled;
459
350
  if (this._isAutoBackgroundEnabled()) {
@@ -467,14 +358,6 @@ class Lifecycle extends EventTarget {
467
358
  return this._autoBackground;
468
359
  }
469
360
 
470
- /**
471
- * @deprecated Use `lifecycle.configure()` instead.
472
- * The number of seconds of user inactivity before the application moves to the background state while playing video.
473
- * Use the `configure` method to set this timeout.
474
- * @type {integer}
475
- * @default 30
476
- * @see {@link Lifecycle#configure}
477
- */
478
361
  set autoBackgroundDelay(delay) {
479
362
  this._autoBackgroundOnVideoDelay = delay;
480
363
  if (this._isAutoBackgroundEnabled() && remotePlayer._isPlaying) {
@@ -486,14 +369,6 @@ class Lifecycle extends EventTarget {
486
369
  return this._autoBackgroundOnVideoDelay;
487
370
  }
488
371
 
489
- /**
490
- * @deprecated Use `lifecycle.configure()` instead.
491
- * The number of seconds of user inactivity before the application moves to the background state while in the UI (not playing).
492
- * Use the `configure` method to set this timeout.
493
- * @type {integer}
494
- * @default -1
495
- * @see {@link Lifecycle#configure}
496
- */
497
372
  set autoBackgroundOnUIDelay(delay) {
498
373
  this._autoBackgroundOnUIDelay = delay;
499
374
  if (this._isAutoBackgroundEnabled() && !remotePlayer._isPlaying) {
@@ -536,26 +411,6 @@ class Lifecycle extends EventTarget {
536
411
  this._countdown = null;
537
412
  }
538
413
 
539
- /**
540
- * @private
541
- */
542
- _isInTransition() {
543
- return this._inTransitionToForeground || this._inTransitionToBackground || this._inTransitionToStandby;
544
- }
545
-
546
-
547
- /**
548
- * @deprecated use lifecycle.state instead.
549
- * Async function that returns the ui lifecycle state
550
- * @returns {UiState} the current application lifecycle state
551
- * @example
552
- * try {
553
- * const state = await lifecycle.getState();
554
- * console.log("current state is", state);
555
- * } catch (e) {
556
- * console.error("getState failed", e);
557
- * }
558
- */
559
414
  getState() {
560
415
  if (window.cefQuery) {
561
416
  return new Promise((resolve, reject) => {
@@ -576,29 +431,16 @@ class Lifecycle extends EventTarget {
576
431
  sdkLogger.warn("lifecycle getState is not supported if NOT running e2e");
577
432
  }
578
433
 
579
- /**
580
- * Once playback starts on the remote player,
581
- * the application is moved from foreground to inTransitionToBackground and eventually to background.
582
- * The application will need to call moveToForeground when it receives an event that needs the UI to be displayed again,
583
- * for example a key press, a playback end-of-file or a playback error.
584
- * @return {Promise} Promise which is resolved when the moveToForeground command has been successfully processed.
585
- * Failure to process the moveToForeground command will result in the promise being rejected.
586
- */
587
434
  moveToForeground() {
588
435
  if (window.cefQuery) {
589
- const inTransition = this._isInTransition();
590
- if (inTransition || this._state === this.UiState.FOREGROUND || this._state === this.UiState.IN_TRANSITION_TO_FOREGROUND) {
591
- sdkLogger.warn(`lifecycle moveToForeground: No need to transition to foreground, state: ${this._state} transition: ${inTransition}`);
436
+ if (this._inTransition || this._state === this.UiState.FOREGROUND || this._state === this.UiState.IN_TRANSITION_TO_FOREGROUND) {
437
+ sdkLogger.warn(`lifecycle moveToForeground: No need to transition to foreground, state: ${this._state} transition: ${this._inTransition}`);
592
438
  return Promise.resolve(false);
593
439
  }
594
- this._inTransitionToForeground = true;
440
+ this._inTransition = true;
595
441
  alarmManager._moveToForegroundCalled();
596
442
  const FCID = getFCID();
597
443
  if (this._remotePlayerApiVersion >= 2) {
598
- // Only update to playing UI if we started seeking in ABR. But, if we are seeking while already paused, keep the target seek state as is.
599
- if (remotePlayer._isSeekingByApplication && remotePlayer._targetSeekPlayingState === TargetPlayingState.PLAYING_ABR) {
600
- remotePlayer._targetSeekPlayingState = TargetPlayingState.PLAYING_UI;
601
- }
602
444
  return new Promise((resolve, reject) => {
603
445
  const FCID = getFCID();
604
446
  const logger = sdkLogger.withFields({ FCID });
@@ -618,14 +460,14 @@ class Lifecycle extends EventTarget {
618
460
  onSuccess: () => {
619
461
  const duration = Date.now() - timeBeforeSendingRequest;
620
462
  logger.withFields({ duration }).log(`stop completed successfully after ${duration} ms`);
621
- this._inTransitionToForeground = false;
463
+ this._inTransition = false;
622
464
  timerId = clearTimer(timerId);
623
465
  resolve(true);
624
466
  },
625
467
  onFailure: (code, msg) => {
626
468
  const duration = Date.now() - timeBeforeSendingRequest;
627
469
  logger.withFields({ duration }).log(`stop failed after ${duration} ms. Error code: ${code}, error message: ${msg}`);
628
- this._inTransitionToForeground = false;
470
+ this._inTransition = false;
629
471
  timerId = clearTimer(timerId);
630
472
  reject(new SenzaError(code, msg));
631
473
  }
@@ -634,7 +476,7 @@ class Lifecycle extends EventTarget {
634
476
  const timeout = this._remotePlayerConfirmationTimeout + 1000;
635
477
  timerId = setTimeout(() => {
636
478
  logger.log(`stop reached timeout of ${timeout} ms, canceling query id ${queryId}`);
637
- this._inTransitionToForeground = false;
479
+ this._inTransition = false;
638
480
  window.cefQueryCancel(queryId);
639
481
  reject(new SenzaError(6000, `stop reached timeout of ${timeout} ms`));
640
482
  }, timeout, queryId);
@@ -649,11 +491,11 @@ class Lifecycle extends EventTarget {
649
491
  persistent: false,
650
492
  onSuccess: () => {
651
493
  logger.log("uiActiveRequest successfully sent");
652
- this._inTransitionToForeground = false;
494
+ this._inTransition = false;
653
495
  resolve(true);
654
496
  },
655
497
  onFailure: (code, msg) => {
656
- this._inTransitionToForeground = false;
498
+ this._inTransition = false;
657
499
  logger.error(`uiActiveRequest failed: ${code} ${msg}`);
658
500
  reject(`uiActiveRequest failed: ${code} ${msg}`);
659
501
  }
@@ -666,6 +508,10 @@ class Lifecycle extends EventTarget {
666
508
 
667
509
  _moveToBackground() {
668
510
  if (window.cefQuery) {
511
+ if (this._inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
512
+ sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${this._inTransition}`);
513
+ return Promise.resolve(false);
514
+ }
669
515
  // If audio sync is disabled, we only need to sync before remote player starts playing
670
516
  if (!isAudioSyncConfigured()) {
671
517
  remotePlayer._syncRemotePlayerWithLocalPlayer();
@@ -677,7 +523,7 @@ class Lifecycle extends EventTarget {
677
523
  return this._moveToUiStandby();
678
524
  }
679
525
 
680
- this._inTransitionToBackground = true;
526
+ this._inTransition = true;
681
527
  return new Promise((resolve, reject) => {
682
528
  const FCID = getFCID();
683
529
  const logger = sdkLogger.withFields({ FCID });
@@ -718,14 +564,14 @@ class Lifecycle extends EventTarget {
718
564
  onSuccess: () => {
719
565
  const duration = Date.now() - timeBeforeSendingRequest;
720
566
  logger.withFields({ duration }).log(`play completed successfully after ${duration} ms`);
721
- this._inTransitionToBackground = false;
567
+ this._inTransition = false;
722
568
  timerId = clearTimer(timerId);
723
569
  resolve();
724
570
  },
725
571
  onFailure: (code, msg) => {
726
572
  const duration = Date.now() - timeBeforeSendingRequest;
727
573
  logger.withFields({ duration }).log(`play failed after ${duration} ms. Error code: ${code}, error message: ${msg}`);
728
- this._inTransitionToBackground = false;
574
+ this._inTransition = false;
729
575
  timerId = clearTimer(timerId);
730
576
  reject(new SenzaError(code, msg));
731
577
  }
@@ -735,7 +581,7 @@ class Lifecycle extends EventTarget {
735
581
  const timeout = this._remotePlayerConfirmationTimeout + 1000;
736
582
  timerId = setTimeout(() => {
737
583
  logger.log(`play reached timeout of ${timeout} ms, canceling query id ${queryId}`);
738
- this._inTransitionToBackground = false;
584
+ this._inTransition = false;
739
585
  window.cefQueryCancel(queryId);
740
586
  reject(new SenzaError(6000, `play reached timeout of ${timeout} ms`));
741
587
  }, timeout, queryId);
@@ -746,24 +592,13 @@ class Lifecycle extends EventTarget {
746
592
  return Promise.resolve(false);
747
593
  }
748
594
 
749
- /**
750
- * This method moves the application to the background.
751
- * It should be called after remotePlayer.play().
752
- * As a consequence, remote player playback will be displayed in full screen.
753
- * @example
754
- * remotePlayer.load("https://example.com/video.mp4", 0);
755
- * remotePlayer.play();
756
- * lifecycle.moveToBackground();
757
- * @return {Promise} Promise which is resolved when the moveToBackground command has been successfully processed.
758
- * Failure to process the moveToBackground command will result in the promise being rejected.
759
- */
760
595
  moveToBackground() {
761
596
  if (window.cefQuery) {
762
- const inTransition = this._isInTransition();
763
- if (inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
764
- sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${inTransition}`);
597
+ if (this._inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
598
+ sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${this._inTransition}`);
765
599
  return Promise.resolve(false);
766
600
  }
601
+
767
602
  if (remotePlayer._isSeekingByApplication) {
768
603
  remotePlayer._targetSeekPlayingState = TargetPlayingState.PLAYING_ABR;
769
604
  return Promise.resolve(true);
@@ -780,13 +615,6 @@ class Lifecycle extends EventTarget {
780
615
  return this._moveToBackground();
781
616
  }
782
617
 
783
- /**
784
- * 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
785
- * Senza platform. Switching to the home tenant should use the exitApplication().
786
- * @param {string} tenantId The tenantId to switch
787
- * @return {Promise} Promise which is resolved when the switchTenant command has been successfully processed.
788
- * Failure to process the switchTenant command will result in the promise being rejected.
789
- */
790
618
  switchTenant(tenantId) {
791
619
  if (tenantId && tenantId.length > 0) {
792
620
  if (tenantId === getPlatformInfo().sessionInfo?.tenantId) {
@@ -832,11 +660,6 @@ class Lifecycle extends EventTarget {
832
660
  return Promise.reject("SwitchTenant requires a valid tenantId string parameter");
833
661
  }
834
662
 
835
- /**
836
- * Use this api to exit the application which will redirect the browser to the home tenant application.
837
- * @return {Promise} Promise which is resolved when the exitApplication command has been successfully processed.
838
- * Failure to process the exitApplication command will result in the promise being rejected.
839
- */
840
663
  exitApplication() {
841
664
  if (window.cefQuery) {
842
665
  return new Promise((resolve, reject) => {
@@ -885,12 +708,6 @@ class Lifecycle extends EventTarget {
885
708
  return Promise.reject("exitApplication is not supported if NOT running e2e");
886
709
  }
887
710
 
888
- /**
889
- * Add event listener for lifecycle events
890
- * @param {string} type - The event type to listen for
891
- * @param {Function} listener - The callback function. Listeners for 'userdisconnected' events should return a promise to ensure the event is processed before the application exits.
892
- * @param {Object} options - Event listener options
893
- */
894
711
  addEventListener(type, listener, options) {
895
712
  if (type === "userdisconnected") {
896
713
  // Use the event manager for userdisconnected events
@@ -901,12 +718,7 @@ class Lifecycle extends EventTarget {
901
718
  }
902
719
  }
903
720
 
904
- /**
905
- * Remove event listener
906
- * @param {string} type - The event type
907
- * @param {Function} listener - The callback function to remove
908
- * @param {Object} options - Event listener options
909
- */
721
+
910
722
  removeEventListener(type, listener, options) {
911
723
  if (type === "userdisconnected") {
912
724
  // Use the event manager for userdisconnected events
@@ -0,0 +1,55 @@
1
+ import { MessageManager as MessageManagerInterface } from "../interface/messageManager";
2
+ import { getFCID, sdkLogger } from "./utils";
3
+
4
+ class MessageManager extends MessageManagerInterface {
5
+
6
+ constructor() {
7
+ super();
8
+ typeof document !== "undefined" && document.addEventListener("hs/externalEvent", (e) => {
9
+ sdkLogger.log("Got hs/externalEvent", JSON.stringify(e.detail));
10
+ this.dispatchEvent(new CustomEvent("message", { detail: { eventName: e.detail.eventName, payload: e.detail.payload, fcid: e.detail.fcid } }));
11
+ });
12
+ }
13
+
14
+ async registerGroups(groups) {
15
+ sdkLogger.log(`register called for ${groups}`);
16
+ return new Promise((resolve, reject) => {
17
+ if (window.cefQuery) {
18
+ const FCID = getFCID();
19
+ const logger = sdkLogger.withFields({ FCID });
20
+ const message = {
21
+ type: "registerGroupEvent",
22
+ fcid: FCID,
23
+ groups
24
+ };
25
+ const request = { target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message) };
26
+ window.cefQuery({
27
+ request: JSON.stringify(request),
28
+ persistent: false,
29
+ onSuccess: () => {
30
+ logger.log("registerGroupEvent request successfully sent");
31
+ resolve(true);
32
+ },
33
+ onFailure: (code, msg) => {
34
+ logger.error(`registerGroupEvent failed: ${code} ${msg}`);
35
+ reject(`registerGroupEvent failed: ${code} ${msg}`);
36
+ }
37
+ });
38
+ } else {
39
+ sdkLogger.warn("registerGroupEvent is not supported if NOT running e2e");
40
+ reject("registerGroupEvent is not supported if NOT running e2e");
41
+ }
42
+ });
43
+ }
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @module
49
+ * @example
50
+ * import { MessageManager } from "senza-sdk";
51
+ *
52
+ * @return {MessageManager} pointer to the MessageManager singleton
53
+ */
54
+
55
+ export const messageManager = new MessageManager();
@@ -1,41 +1,23 @@
1
+ import { PlatformManager as PlatformManagerInterface } from "../interface/platformManager";
1
2
  import { sdkLogger } from "./utils";
2
- import {sessionInfo} from "./SessionInfo";
3
+ import { sessionInfo } from "./SessionInfo";
3
4
 
4
-
5
- /**
6
- * PlatformManager is a singleton class that manages the platform
7
- */
8
- class PlatformManager extends EventTarget {
5
+ class PlatformManager extends PlatformManagerInterface {
9
6
 
10
7
  constructor() {
11
8
  super();
12
9
  }
13
10
 
14
- /**
15
- * @returns {Object} appConfig object
16
- * @property {String[]} territories - a list of territories configured for the tenant.
17
- * if the list is undefined or empty - there are no restrictions.
18
- * @example
19
- * import { platformManager } from "senza-sdk";
20
- * const appConfig = platformManager.appConfig
21
- * */
22
11
  get appConfig() {
23
12
  const sessionInfoObj = sessionInfo.sessionInfoObj;
24
13
  const appConfig = sessionInfoObj.homeSessionInfo?.["appConfig"] || {};
25
- sdkLogger.info("PlatformManager get appConfig: \n" + JSON.stringify(appConfig, null,2));
14
+ sdkLogger.info("PlatformManager get appConfig: \n" + JSON.stringify(appConfig, null, 2));
26
15
  return appConfig;
27
16
  }
28
17
 
29
- /**
30
- *
31
- * @param {string} timezone the timezone to set to
32
- * the format of the timezone is according to the standard TZ identifier
33
- * (e.g. America/Los_Angeles, Asia/Tokyo, Europe/Brussels)
34
- * for a full list of TZ identifiers, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
35
- */
36
18
  setTimezone(timezone) {
37
19
  if (window.cefQuery) {
38
- const request = {message: JSON.stringify({type: "setTimeZone", timezone}), waitForResponse: false, target: "UI-Streamer"};
20
+ const request = { message: JSON.stringify({ type: "setTimeZone", timezone }), waitForResponse: false, target: "UI-Streamer" };
39
21
  window.cefQuery({
40
22
  request: JSON.stringify(request),
41
23
  persistent: false,