senza-sdk 4.2.58-a3e6d19.0 → 4.2.59-c9128b1.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.58-a3e6d19.0",
3
+ "version": "4.2.59-c9128b1.0",
4
4
  "main": "./src/api.js",
5
5
  "description": "API for Senza application",
6
6
  "license": "MIT",
@@ -85,7 +85,7 @@ class DeviceManager extends EventTarget {
85
85
  connectionId: sessionInfoObj.connectionId,
86
86
  community: sessionInfoObj.community,
87
87
  tenant: sessionInfoObj.tenant,
88
- clientIp: sessionInfoObj?.settings?.["ui-streamer"]?.clientIpOverride || sessionInfoObj.clientIp,
88
+ clientIp: sessionInfoObj.clientIp,
89
89
  countryCode: sessionInfoObj.general?.location?.["x-country-code"],
90
90
  connectionType: (!sessionInfoObj.connectionType || sessionInfoObj.connectionType === "direct") ? "device" : sessionInfoObj.connectionType
91
91
  };
package/src/lifecycle.js CHANGED
@@ -637,10 +637,10 @@ class Lifecycle extends EventTarget {
637
637
  return new Promise((resolve, reject) => {
638
638
  const FCID = getFCID();
639
639
  const logger = sdkLogger.withFields({ FCID });
640
- logger.log("lifecycle moveToBackground: sending play action");
641
640
  const configuration = remotePlayer.getConfiguration();
642
641
  const audioLanguage = remotePlayer._selectedAudioTrack || configuration.preferredAudioLanguage || "";
643
- const subtitlesLanguage = remotePlayer.textTrackVisibility && (remotePlayer._selectedSubtitlesTrack || configuration.preferredSubtitlesLanguage) || "";
642
+ const subtitlesLanguage = remotePlayer._selectedSubtitlesTrack || configuration.preferredSubtitlesLanguage || "";
643
+
644
644
  let request;
645
645
  const message = {
646
646
  action: "play",
@@ -652,7 +652,7 @@ class Lifecycle extends EventTarget {
652
652
  message.type = "remotePlayer.play";
653
653
  message.class = "remotePlayer";
654
654
  message.switchMode = remotePlayer._isAudioSyncEnabled() ? SwitchMode.SEAMLESS : SwitchMode.NON_SEAMLESS;
655
- message.streamType = StreamType.AUDIO | StreamType.VIDEO | StreamType.SUBTITLE;
655
+ message.streamType = remotePlayer.textTrackVisibility ? (StreamType.AUDIO | StreamType.VIDEO | StreamType.SUBTITLE) : (StreamType.AUDIO | StreamType.VIDEO);
656
656
  request = {
657
657
  target: "TC",
658
658
  waitForResponse: true,
@@ -660,8 +660,12 @@ class Lifecycle extends EventTarget {
660
660
  message: JSON.stringify(message)
661
661
  };
662
662
  } else {
663
+ if (!remotePlayer.textTrackVisibility) {
664
+ message.subtitlesLanguage = "";
665
+ }
663
666
  request = message;
664
667
  }
668
+ logger.log(`lifecycle moveToBackground: sending play action audioLanguage=${message.audioLanguage} subtitlesLanguage=${message.subtitlesLanguage} textTrackVisibility=${remotePlayer.textTrackVisibility}`);
665
669
  let timerId = 0;
666
670
  const timeBeforeSendingRequest = Date.now();
667
671
  const queryId = window.cefQuery({
@@ -495,13 +495,7 @@ class RemotePlayer extends EventTarget {
495
495
  }
496
496
  if (this._availableTextTracks) {
497
497
  const selectedTrack = this._availableTextTracks.find((track) => track.selected === true);
498
- if (selectedTrack) {
499
- this._selectedSubtitlesTrack = selectedTrack.id;
500
- this._textTrackVisibility = true;
501
- } else {
502
- this._selectedSubtitlesTrack = "";
503
- this._textTrackVisibility = false;
504
- }
498
+ this._selectedSubtitlesTrack = selectedTrack?.id || "";
505
499
  }
506
500
  }
507
501
 
@@ -698,12 +692,9 @@ class RemotePlayer extends EventTarget {
698
692
  if (window.cefQuery) {
699
693
  const FCID = getFCID();
700
694
  const logger = sdkLogger.withFields({ FCID });
701
- logger.log("remotePlayer play: sending play action");
702
695
  const audioLanguage = this._selectedAudioTrack || this._config.preferredAudioLanguage || "";
703
- let subtitlesLanguage = "";
704
- if (this._textTrackVisibility) {
705
- subtitlesLanguage = this._selectedSubtitlesTrack || this._config.preferredSubtitlesLanguage || "";
706
- }
696
+ const subtitlesLanguage = this._selectedSubtitlesTrack || this._config.preferredSubtitlesLanguage || "";
697
+
707
698
  const message = {
708
699
  type: "remotePlayer.play",
709
700
  class: "remotePlayer",
@@ -718,7 +709,23 @@ class RemotePlayer extends EventTarget {
718
709
  message.switchMode = this._isAudioSyncEnabled() ? SwitchMode.SEAMLESS : SwitchMode.NON_SEAMLESS;
719
710
  message.streamType = streamType;
720
711
  waitForResponse = true;
712
+
713
+ if (!this._textTrackVisibility) {
714
+ const onlySubtitle = message.streamType === StreamType.SUBTITLE;
715
+ if (onlySubtitle) {
716
+ logger.log("remotePlayer play: text track visibility is disabled and streamType is only SUBTITLE. returning early with no action.");
717
+ return Promise.resolve(undefined); // nothing to do
718
+ }
719
+ if (message.streamType && StreamType.SUBTITLE) {
720
+ // remove SUBTITLE
721
+ message.streamType = message.streamType & ~StreamType.SUBTITLE;
722
+ logger.log("remotePlayer play: text track visibility is disabled. Removed SUBTITLE from streamType.");
723
+ }
724
+ }
725
+ } else if (!this.textTrackVisibility) {
726
+ message.subtitlesLanguage = "";
721
727
  }
728
+ logger.log(`remotePlayer play: sending play action remotePlayer._isPlaying: ${this._isPlaying} audioLanguage=${message.audioLanguage} subtitlesLanguage=${message.subtitlesLanguage} textTrackVisibility=${this.textTrackVisibility}`);
722
729
  const request = { target: "TC", waitForResponse: waitForResponse, message: JSON.stringify(message) };
723
730
  return new Promise((resolve, reject) => {
724
731
  let timerId = 0;
@@ -947,10 +954,7 @@ class RemotePlayer extends EventTarget {
947
954
  const playbackPosition = position ?? 0;
948
955
  const logger = sdkLogger.withFields({ FCID, loadUrl: url, playbackPosition });
949
956
  const audioLanguage = audioTrackId || this._selectedAudioTrack || this._config.preferredAudioLanguage || "";
950
- let subtitlesLanguage = "";
951
- if (this._textTrackVisibility) {
952
- subtitlesLanguage = textTrackId || this._selectedSubtitlesTrack || this._config.preferredSubtitlesLanguage || "";
953
- }
957
+ const subtitlesLanguage = textTrackId || this._selectedSubtitlesTrack || this._config.preferredSubtitlesLanguage || "";
954
958
 
955
959
  const message = {
956
960
  url,
@@ -968,7 +972,7 @@ class RemotePlayer extends EventTarget {
968
972
  } else {
969
973
  message.type = "setPlayableUri";
970
974
  }
971
- logger.log(`remotePlayer load: sending ${message.type} request. remotePlayer._isPlaying: ${this._isPlaying}`);
975
+ logger.log(`remotePlayer load: sending ${message.type} request. remotePlayer._isPlaying: ${this._isPlaying} audioLanguage=${audioLanguage} subtitlesLanguage=${subtitlesLanguage}`);
972
976
  const request = { target: "TC", waitForResponse: true, message: JSON.stringify(message) };
973
977
  let timerId = 0;
974
978
  const timeBeforeSendingRequest = Date.now();
@@ -1519,20 +1523,23 @@ class RemotePlayer extends EventTarget {
1519
1523
  /**
1520
1524
  * Enable or disable the subtitles.
1521
1525
  * If the player is in an unloaded state, the request will be applied next time content is played.
1522
- * @param {boolean} visible whether the subtitles are visible or not
1523
- * @throws {TypeError} if visible is not a boolean variable
1526
+ * @param {boolean|0|1} visible whether the subtitles are visible or not
1527
+ * @throws {TypeError} if visible is not a boolean variable or 0/1
1524
1528
  */
1525
1529
  setTextTrackVisibility(visible) {
1526
1530
  const oldVisibility = this._textTrackVisibility;
1527
- if (typeof visible !== "boolean") {
1528
- throw new TypeError("visible parameter must be a boolean");
1531
+ if (typeof visible !== "boolean" && !(visible === 0 || visible === 1)) {
1532
+ throw new TypeError("visible parameter must be a boolean or 0/1");
1529
1533
  }
1530
- const newVisibility = visible;
1531
- if (newVisibility === oldVisibility) {
1534
+ // Convert to boolean in case apps pass 0/1 instead false/true.
1535
+ const newVisibility = !!visible;
1536
+
1537
+ if (oldVisibility === newVisibility) {
1532
1538
  return;
1533
1539
  }
1540
+
1534
1541
  this._textTrackVisibility = newVisibility;
1535
- if (!newVisibility) {
1542
+ if (!this._textTrackVisibility) {
1536
1543
  // Setting the visibility to false clears any previous selections user has done
1537
1544
  this._selectedSubtitlesTrack = "";
1538
1545
  }
@@ -1,6 +1,7 @@
1
1
  import * as shaka from "shaka-player";
2
2
  import { remotePlayer, lifecycle, getPlatformInfo } from "./api";
3
3
  import { sdkLogger, iso6393to1 } from "./utils";
4
+
4
5
  // Define custom error category
5
6
  shaka.util.Error.Category.SENZA_PLAYER_ERROR = 50;
6
7
  shaka.util.Error.Code.SENZA_PLAYER_ERROR = 10500;
@@ -75,6 +76,13 @@ export class SenzaShakaPlayer extends shaka.Player {
75
76
  * @description Object containing event listeners for the video element.
76
77
  */
77
78
  _videoEventListeners = {
79
+ "play": () => {
80
+ this.remotePlayer.play()
81
+ .catch(error => {
82
+ sdkLogger.error("Failed to play remote player:", error);
83
+ this.handleSenzaError(error.code, error.message || "Unknown play error");
84
+ });
85
+ },
78
86
  "pause": () => {
79
87
  this.remotePlayer.pause()
80
88
  .catch(error => {
@@ -211,7 +219,6 @@ export class SenzaShakaPlayer extends shaka.Player {
211
219
  * @param {boolean} [initializeMediaSource=true] - Whether to initialize the media source.
212
220
  */
213
221
  async attach(videoElement, initializeMediaSource = true) {
214
-
215
222
  await super.attach(videoElement, initializeMediaSource);
216
223
  this.videoElement = videoElement;
217
224
  this._attachVideoElementToRemotePlayer();
@@ -256,8 +263,8 @@ export class SenzaShakaPlayer extends shaka.Player {
256
263
  */
257
264
  async unload(initializeMediaSource = true, keepAdManager = false) {
258
265
  // Call the remote player's unload method
259
-
260
266
  try {
267
+ await lifecycle.moveToForeground();
261
268
  await remotePlayer.unload();
262
269
  } catch (error) {
263
270
  sdkLogger.error("Failed to unload remote player:", error);
@@ -399,7 +406,7 @@ export class SenzaShakaPlayer extends shaka.Player {
399
406
  // Create a promise that will resolve when _remotePlayerLoad is called
400
407
  let remoteLoadResolver;
401
408
  let remoteLoadRejecter;
402
- const remoteLoadPromise = new Promise((resolve,reject) => {
409
+ const remoteLoadPromise = new Promise((resolve, reject) => {
403
410
  remoteLoadResolver = resolve;
404
411
  remoteLoadRejecter = reject;
405
412
  });
@@ -473,7 +480,8 @@ export class SenzaShakaPlayer extends shaka.Player {
473
480
  * @returns {Boolean}
474
481
  */
475
482
 
476
- destroy() {
483
+ async destroy() {
484
+ await lifecycle.moveToForeground();
477
485
  SenzaShakaPlayer._prevInstance = null;
478
486
  this._removeRemotePlayerEventListeners();
479
487
  return super.destroy();
@@ -494,6 +502,8 @@ export class SenzaShakaPlayer extends shaka.Player {
494
502
  * });
495
503
  */
496
504
  configure(config) {
505
+ sdkLogger.log("configure player with: ", JSON.stringify(config));
506
+
497
507
  // Handle custom configuration
498
508
  if (config.shouldStopRemotePlayerOnError !== undefined) {
499
509
  this._shouldStopRemotePlayerOnError = !!config.shouldStopRemotePlayerOnError;
@@ -514,6 +524,7 @@ export class SenzaShakaPlayer extends shaka.Player {
514
524
  remoteConfiguration["preferredSubtitlesLanguage"] = config["preferredTextLanguage"];
515
525
  }
516
526
 
527
+ sdkLogger.log("configure remote player with: ", JSON.stringify(remoteConfiguration));
517
528
  remotePlayer.configure(remoteConfiguration);
518
529
  }
519
530
 
@@ -532,7 +543,7 @@ export class SenzaShakaPlayer extends shaka.Player {
532
543
 
533
544
  }
534
545
 
535
- async _remotePlayerLoad(url,startTime) {
546
+ async _remotePlayerLoad(url, startTime) {
536
547
  const waitForLoadModeChange = () => {
537
548
  const timeout = this.remotePlayer._remotePlayerConfirmationTimeout + 2000;
538
549
  return Promise.race([
@@ -575,26 +586,6 @@ export class SenzaShakaPlayer extends shaka.Player {
575
586
  for (const [event, listener] of Object.entries(this._videoEventListeners)) {
576
587
  this.videoElement.addEventListener(event, listener);
577
588
  }
578
-
579
- this.videoElement.origPlay=this.videoElement.play;
580
- this.videoElement.play = async () => {
581
- sdkLogger.info("video tag play was called - first calling remotePlayer Play");
582
-
583
- try {
584
- await this.remotePlayer.play();
585
- } catch (error) {
586
- sdkLogger.error("Failed to play remote player:", error);
587
- this.handleSenzaError(error.code, error.message || "Unknown play error");
588
- }
589
-
590
- sdkLogger.info("Waiting for 30 seconds");
591
- setTimeout(() => {
592
- sdkLogger.info("Now calling origPlay");
593
- return this.videoElement.origPlay();
594
- }, 30 * 1000);
595
-
596
- };
597
-
598
589
  }
599
590
 
600
591
  }