senza-sdk 4.2.54-01d7afc.0 → 4.2.54-b92e464.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "senza-sdk",
3
- "version": "4.2.54-01d7afc.0",
3
+ "version": "4.2.54-b92e464.0",
4
4
  "main": "./src/api.js",
5
5
  "description": "API for Senza application",
6
6
  "license": "MIT",
package/src/lifecycle.js CHANGED
@@ -102,9 +102,7 @@ class Lifecycle extends EventTarget {
102
102
  * @private
103
103
  */
104
104
  this._isInitialized = false;
105
- this._inTransitionToForeground = false;
106
- this._inTransitionToBackground = false;
107
- this._inTransitionToStandby = false;
105
+ this._inTransition = false;
108
106
 
109
107
  /**
110
108
  * Event listeners manager for the userdisconnected event
@@ -351,7 +349,7 @@ class Lifecycle extends EventTarget {
351
349
  // This api is part of epic HSDEV-713
352
350
  _moveToUiStandby() {
353
351
  if (window.cefQuery) {
354
- this._inTransitionToStandby = true;
352
+ this._inTransition = true;
355
353
  return new Promise((resolve, reject) => {
356
354
  const FCID = getFCID();
357
355
  const request = { target: "TC", waitForResponse: false, internalAction: "uiExit", message: JSON.stringify({ type: "uiStandbyRequest", fcid: FCID }) };
@@ -362,12 +360,12 @@ class Lifecycle extends EventTarget {
362
360
  persistent: false,
363
361
  onSuccess: () => {
364
362
  logger.log("[ moveToUiStandby ] moveToUiStandby successfully sent");
365
- this._inTransitionToStandby = false;
363
+ this._inTransition = false;
366
364
  resolve(true);
367
365
  },
368
366
  onFailure: (code, msg) => {
369
367
  logger.error(`[ moveToUiStandby ] moveToUiStandby failed: ${code} ${msg}`);
370
- this._inTransitionToStandby = false;
368
+ this._inTransition = false;
371
369
  reject(`moveToUiStandby failed: ${code} ${msg}`);
372
370
  }
373
371
  });
@@ -503,14 +501,6 @@ class Lifecycle extends EventTarget {
503
501
  this._countdown = null;
504
502
  }
505
503
 
506
- /**
507
- * @private
508
- */
509
- _isInTransition() {
510
- return this._inTransitionToForeground || this._inTransitionToBackground || this._inTransitionToStandby;
511
- }
512
-
513
-
514
504
  /**
515
505
  * @deprecated use lifecycle.state instead.
516
506
  * Async function that returns the ui lifecycle state
@@ -553,19 +543,14 @@ class Lifecycle extends EventTarget {
553
543
  */
554
544
  moveToForeground() {
555
545
  if (window.cefQuery) {
556
- const inTransition = this._isInTransition();
557
- if (inTransition || this._state === this.UiState.FOREGROUND || this._state === this.UiState.IN_TRANSITION_TO_FOREGROUND) {
558
- sdkLogger.warn(`lifecycle moveToForeground: No need to transition to foreground, state: ${this._state} transition: ${inTransition}`);
546
+ if (this._inTransition || this._state === this.UiState.FOREGROUND || this._state === this.UiState.IN_TRANSITION_TO_FOREGROUND) {
547
+ sdkLogger.warn(`lifecycle moveToForeground: No need to transition to foreground, state: ${this._state} transition: ${this._inTransition}`);
559
548
  return Promise.resolve(false);
560
549
  }
561
- this._inTransitionToForeground = true;
550
+ this._inTransition = true;
562
551
  alarmManager._moveToForegroundCalled();
563
552
  const FCID = getFCID();
564
553
  if (this._remotePlayerApiVersion >= 2) {
565
- // 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.
566
- if (remotePlayer._isSeekingByApplication && remotePlayer._targetSeekPlayingState === TargetPlayingState.PLAYING_ABR) {
567
- remotePlayer._targetSeekPlayingState = TargetPlayingState.PLAYING_UI;
568
- }
569
554
  return new Promise((resolve, reject) => {
570
555
  const FCID = getFCID();
571
556
  const logger = sdkLogger.withFields({ FCID });
@@ -585,14 +570,14 @@ class Lifecycle extends EventTarget {
585
570
  onSuccess: () => {
586
571
  const duration = Date.now() - timeBeforeSendingRequest;
587
572
  logger.withFields({ duration }).log(`stop completed successfully after ${duration} ms`);
588
- this._inTransitionToForeground = false;
573
+ this._inTransition = false;
589
574
  timerId = clearTimer(timerId);
590
575
  resolve(true);
591
576
  },
592
577
  onFailure: (code, msg) => {
593
578
  const duration = Date.now() - timeBeforeSendingRequest;
594
579
  logger.withFields({ duration }).log(`stop failed after ${duration} ms. Error code: ${code}, error message: ${msg}`);
595
- this._inTransitionToForeground = false;
580
+ this._inTransition = false;
596
581
  timerId = clearTimer(timerId);
597
582
  reject(new SenzaError(code, msg));
598
583
  }
@@ -601,7 +586,7 @@ class Lifecycle extends EventTarget {
601
586
  const timeout = this._remotePlayerConfirmationTimeout + 1000;
602
587
  timerId = setTimeout(() => {
603
588
  logger.log(`stop reached timeout of ${timeout} ms, canceling query id ${queryId}`);
604
- this._inTransitionToForeground = false;
589
+ this._inTransition = false;
605
590
  window.cefQueryCancel(queryId);
606
591
  reject(new SenzaError(6000, `stop reached timeout of ${timeout} ms`));
607
592
  }, timeout, queryId);
@@ -616,11 +601,11 @@ class Lifecycle extends EventTarget {
616
601
  persistent: false,
617
602
  onSuccess: () => {
618
603
  logger.log("uiActiveRequest successfully sent");
619
- this._inTransitionToForeground = false;
604
+ this._inTransition = false;
620
605
  resolve(true);
621
606
  },
622
607
  onFailure: (code, msg) => {
623
- this._inTransitionToForeground = false;
608
+ this._inTransition = false;
624
609
  logger.error(`uiActiveRequest failed: ${code} ${msg}`);
625
610
  reject(`uiActiveRequest failed: ${code} ${msg}`);
626
611
  }
@@ -633,6 +618,10 @@ class Lifecycle extends EventTarget {
633
618
 
634
619
  _moveToBackground() {
635
620
  if (window.cefQuery) {
621
+ if (this._inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
622
+ sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${this._inTransition}`);
623
+ return Promise.resolve(false);
624
+ }
636
625
  // If audio sync is disabled, we only need to sync before remote player starts playing
637
626
  if (!isAudioSyncConfigured()) {
638
627
  remotePlayer._syncRemotePlayerWithLocalPlayer();
@@ -644,7 +633,7 @@ class Lifecycle extends EventTarget {
644
633
  return this._moveToUiStandby();
645
634
  }
646
635
 
647
- this._inTransitionToBackground = true;
636
+ this._inTransition = true;
648
637
  return new Promise((resolve, reject) => {
649
638
  const FCID = getFCID();
650
639
  const logger = sdkLogger.withFields({ FCID });
@@ -681,14 +670,14 @@ class Lifecycle extends EventTarget {
681
670
  onSuccess: () => {
682
671
  const duration = Date.now() - timeBeforeSendingRequest;
683
672
  logger.withFields({ duration }).log(`play completed successfully after ${duration} ms`);
684
- this._inTransitionToBackground = false;
673
+ this._inTransition = false;
685
674
  timerId = clearTimer(timerId);
686
675
  resolve();
687
676
  },
688
677
  onFailure: (code, msg) => {
689
678
  const duration = Date.now() - timeBeforeSendingRequest;
690
679
  logger.withFields({ duration }).log(`play failed after ${duration} ms. Error code: ${code}, error message: ${msg}`);
691
- this._inTransitionToBackground = false;
680
+ this._inTransition = false;
692
681
  timerId = clearTimer(timerId);
693
682
  reject(new SenzaError(code, msg));
694
683
  }
@@ -698,7 +687,7 @@ class Lifecycle extends EventTarget {
698
687
  const timeout = this._remotePlayerConfirmationTimeout + 1000;
699
688
  timerId = setTimeout(() => {
700
689
  logger.log(`play reached timeout of ${timeout} ms, canceling query id ${queryId}`);
701
- this._inTransitionToBackground = false;
690
+ this._inTransition = false;
702
691
  window.cefQueryCancel(queryId);
703
692
  reject(new SenzaError(6000, `play reached timeout of ${timeout} ms`));
704
693
  }, timeout, queryId);
@@ -721,13 +710,12 @@ class Lifecycle extends EventTarget {
721
710
  * Failure to process the moveToBackground command will result in the promise being rejected.
722
711
  */
723
712
  moveToBackground() {
724
- if (window.cefQuery) {
725
- const inTransition = this._isInTransition();
726
- if (inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
727
- sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${inTransition}`);
728
- return Promise.resolve(false);
729
- }
730
- if (remotePlayer._isSeekingByApplication) {
713
+ if (remotePlayer._isSeekingByApplication) {
714
+ if (window.cefQuery) {
715
+ if (this._inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
716
+ sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${this._inTransition}`);
717
+ return Promise.resolve(false);
718
+ }
731
719
  remotePlayer._targetSeekPlayingState = TargetPlayingState.PLAYING_ABR;
732
720
  return Promise.resolve(true);
733
721
  }
@@ -1428,16 +1428,18 @@ class RemotePlayer extends EventTarget {
1428
1428
 
1429
1429
  // If the local player is just initializing after loading the manifest, ignore the seeking event.
1430
1430
  if (this._localPlayerLoadCurrentTime === 0 && this._videoElement.currentTime - this._localPlayerLoadCurrentTime > ONE_DAY_SECONDS) {
1431
- sdkLogger.info(`Seeking ignored for video currentTime init: currentTime=${this._videoElement.currentTime} loadCurrentTime=${this._localPlayerLoadCurrentTime}`);
1431
+ sdkLogger.info(`Seeking ignored for video currentTime init: currentTime: ${this._videoElement.currentTime}, loadCurrentTime: ${this._localPlayerLoadCurrentTime}`);
1432
1432
  this._localPlayerLoadCurrentTime = this._videoElement.currentTime;
1433
1433
  return;
1434
1434
  }
1435
1435
  }
1436
1436
 
1437
- if (this._remotePlayerApiVersion >= 2 && !this._isSeekingByPlatform && !this._isSeekingByApplication) {
1437
+ // Only allow seeking in foreground. Still ignore the initialized local player seeking event above
1438
+ if (this._remotePlayerApiVersion >= 2 && !this._isSeekingByPlatform && !this._isSeekingByApplication &&
1439
+ (lifecycle.state === lifecycle.UiState.FOREGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_FOREGROUND)) {
1438
1440
  this._atomicSeek();
1439
1441
  } else {
1440
- sdkLogger.info(`Seeking: skipping seeking event to currentTime=${this._videoElement.currentTime} internalSeek=${this._isSeekingByPlatform} localPlayerSeek=${this._isSeekingByApplication}`);
1442
+ sdkLogger.info(`Seeking: skipping seeking event to currentTime: ${playbackPosition}, internalSeek: ${this._isSeekingByPlatform}, localPlayerSeek: ${this._isSeekingByApplication}, state: ${lifecycle.state}`);
1441
1443
  }
1442
1444
  }
1443
1445
 
@@ -1452,17 +1454,17 @@ class RemotePlayer extends EventTarget {
1452
1454
  * @private
1453
1455
  * */
1454
1456
  async _atomicSeek() {
1455
- sdkLogger.info("Seeking: local video element seeking start while isPLaying=", this._isPlaying);
1456
-
1457
- if (this._isPlaying) {
1458
- if (!lifecycle._inTransitionToForeground && (lifecycle._inTransitionToBackground || lifecycle.state === lifecycle.UiState.BACKGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_BACKGROUND)) {
1459
- this._targetSeekPlayingState = TargetPlayingState.PLAYING_ABR;
1460
- } else {
1461
- this._targetSeekPlayingState = TargetPlayingState.PLAYING_UI;
1462
- }
1463
- } else {
1464
- this._targetSeekPlayingState = TargetPlayingState.PAUSED;
1465
- }
1457
+ sdkLogger.info("Seeking: local video element seeking start while isPLaying: ", this._isPlaying);
1458
+
1459
+ // Initialize the target playing state unless changed during the seek process
1460
+ // In the future, we should allow for seeking in background. Currently, there's no
1461
+ // way to know when the web application will call moveToForeground (i.e Before/After seek)
1462
+ // Therefore, for now, we will assume the target is either paused or playing in ui unless
1463
+ // specifically receiving a moveToBackground during the process.
1464
+ // if (this._isPlaying && (lifecycle.state === lifecycle.UiState.BACKGROUND || lifecycle.state === lifecycle.UiState.IN_TRANSITION_TO_BACKGROUND)) {
1465
+ // this._targetSeekPlayingState = TargetPlayingState.PLAYING_ABR;
1466
+ // }
1467
+ this._targetSeekPlayingState = this._isPlaying ? TargetPlayingState.PLAYING_UI : TargetPlayingState.PAUSED;
1466
1468
 
1467
1469
  // The platform could be currently syncing audio/video using playback rate. Reset when performing seek.
1468
1470
  if (this._videoElement) {
@@ -1529,13 +1531,11 @@ class RemotePlayer extends EventTarget {
1529
1531
 
1530
1532
  // If in TargetPlayingState.PAUSE, no need to resume.
1531
1533
  // Resume without awaiting to avoid blocking the seek process anymore
1532
- // In case where we aborted (new load or unload called), we don't want to resume playback.
1534
+ // In case where we aborted, we don't want to resume playback.
1533
1535
  if (!this._abortSeeking) {
1534
1536
  if (this._targetSeekPlayingState === TargetPlayingState.PLAYING_UI) {
1535
1537
  this._play();
1536
1538
  } else if (this._targetSeekPlayingState === TargetPlayingState.PLAYING_ABR) {
1537
- // When moving back to background, we need to put the remote player back into play mode
1538
- this._changePlayMode(true);
1539
1539
  lifecycle._moveToBackground();
1540
1540
  }
1541
1541
  }