eyevinn-channel-engine 3.2.4 → 3.2.7

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 (2) hide show
  1. package/engine/session.js +31 -14
  2. package/package.json +1 -1
package/engine/session.js CHANGED
@@ -57,7 +57,7 @@ class Session {
57
57
  transitionSegments: null,
58
58
  reloadBehind: null,
59
59
  }
60
- this.alreadyClearedVodCache = null;
60
+ this.isAllowedToClearVodCache = null;
61
61
 
62
62
  if (config) {
63
63
  if (config.sessionId) {
@@ -361,9 +361,13 @@ class Session {
361
361
  state = await this.getSessionState();
362
362
  }
363
363
 
364
- const playheadState = await this._playheadState.getValues(["vodMediaSeqVideo"]);
365
- if (opts && opts.targetMseq) {
364
+ const playheadState = {
365
+ vodMediaSeqVideo: null
366
+ }
367
+ if (opts && opts.targetMseq !== undefined) {
366
368
  playheadState.vodMediaSeqVideo = opts.targetMseq;
369
+ } else {
370
+ playheadState.vodMediaSeqVideo = await this._playheadState.get("vodMediaSeqVideo");
367
371
  }
368
372
 
369
373
  // NOTE: Assume that VOD cache was already cleared in 'getCurrentMediaAndDiscSequenceCount()'
@@ -476,14 +480,13 @@ class Session {
476
480
  if (playheadState.vodMediaSeqVideo < 2 || playheadState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
477
481
  debug(`[${this._sessionId}]: current[${playheadState.vodMediaSeqVideo}]_prev[${this.prevVodMediaSeq.video}]`);
478
482
  const isLeader = await this._sessionStateStore.isLeader(this._instanceId);
479
- if (!isLeader && !this.alreadyClearedVodCache) {
483
+ if (!isLeader && this.isAllowedToClearVodCache) {
480
484
  debug(`[${this._sessionId}]: Not a leader and first|second media sequence in a VOD is requested. Invalidate cache to ensure having the correct VOD.`);
481
485
  await this._sessionState.clearCurrentVodCache();
482
- this.alreadyClearedVodCache = true;
486
+ this.isAllowedToClearVodCache = false;
483
487
  }
484
488
  } else {
485
- // Reset the value
486
- this.alreadyClearedVodCache = false;
489
+ this.isAllowedToClearVodCache = true;
487
490
  }
488
491
 
489
492
  const currentVod = await this._sessionState.getCurrentVod();
@@ -567,6 +570,7 @@ class Session {
567
570
  } else {
568
571
  debug(`[${this._sessionId}]: We don't have any previously generated m3u8`);
569
572
  }
573
+ this.isAllowedToClearVodCache = true;
570
574
  }
571
575
  } else {
572
576
  sessionState.vodMediaSeqVideo = await this._sessionState.increment("vodMediaSeqVideo");
@@ -597,14 +601,13 @@ class Session {
597
601
  if (playheadState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
598
602
  this.alreadyCleredVodCache = false;
599
603
  }
600
- if (!isLeader && !this.alreadyClearedVodCache) {
604
+ if (!isLeader && this.isAllowedToClearVodCache) {
601
605
  debug(`[${this._sessionId}]: Not a leader and have just set 'playheadState.vodMediaSeqVideo' to 0|1. Invalidate cache to ensure having the correct VOD.`);
602
606
  await this._sessionState.clearCurrentVodCache();
603
- this.alreadyClearedVodCache = true;
607
+ this.isAllowedToClearVodCache = false;
604
608
  }
605
609
  } else {
606
- // Reset the value
607
- this.alreadyClearedVodCache = false;
610
+ this.isAllowedToClearVodCache = true;
608
611
  }
609
612
  // Update Value for Previous Sequence
610
613
  this.prevVodMediaSeq.video = playheadState.vodMediaSeqVideo;
@@ -959,12 +962,19 @@ class Session {
959
962
  this.prevVodMediaSeq.video = sessionState.vodMediaSeqVideo;
960
963
  }
961
964
  // Clear Cache if prev count is HIGHER than current...
962
- if (sessionState.vodMediaSeqVideo < this.prevVodMediaSeq.video ) {
963
- debug(`[${this._sessionId}]: current[${sessionState.vodMediaSeqVideo}], prev[${this.prevVodMediaSeq.video}], total[${currentVod.getLiveMediaSequencesCount()}]`);
965
+ if (sessionState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
966
+ debug(`[${this._sessionId}]: state=VOD_PLAYING, current[${sessionState.vodMediaSeqVideo}], prev[${this.prevVodMediaSeq.video}], total[${currentVod.getLiveMediaSequencesCount()}]`);
964
967
  await this._sessionState.clearCurrentVodCache();
965
968
  currentVod = await this._sessionState.getCurrentVod();
966
969
  this.prevVodMediaSeq.video = sessionState.vodMediaSeqVideo;
967
970
  }
971
+ } else {
972
+ // Handle edge case where Leader loaded next vod but Follower remained in state=VOD_PLAYING
973
+ if (this.prevVodMediaSeq.video !== null & sessionState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
974
+ debug(`[${this._sessionId}]: state=VOD_PLAYING, current[${sessionState.vodMediaSeqVideo}], prev[${this.prevVodMediaSeq.video}], total[${currentVod.getLiveMediaSequencesCount()}]`);
975
+ // Allow Follower to clear VodCache...
976
+ this.isAllowedToClearVodCache = true;
977
+ }
968
978
  }
969
979
  debug(`[${this._sessionId}]: state=VOD_PLAYING (${sessionState.vodMediaSeqVideo}_${sessionState.vodMediaSeqAudio}, ${currentVod.getLiveMediaSequencesCount()})`);
970
980
  return;
@@ -973,7 +983,8 @@ class Session {
973
983
  if (!isLeader) {
974
984
  debug(`[${this._sessionId}]: not the leader so just waiting for the VOD to be initiated`);
975
985
  }
976
- this.alreadyClearedVodCache = false;
986
+ // Allow Leader|Follower to clear vodCache...
987
+ this.isAllowedToClearVodCache = true;
977
988
  return;
978
989
  case SessionState.VOD_NEXT_INIT:
979
990
  try {
@@ -1059,6 +1070,8 @@ class Session {
1059
1070
  debug(`[${this._sessionId}]: not a leader so will go directly to state VOD_NEXT_INITIATING`);
1060
1071
  this.waitingForNextVod = true;
1061
1072
  sessionState.state = await this._sessionState.set("state", SessionState.VOD_NEXT_INITIATING);
1073
+ // Allow Leader|Follower to clear vodCache...
1074
+ this.isAllowedToClearVodCache = true;
1062
1075
  sessionState.currentVod = await this._sessionState.getCurrentVod();
1063
1076
  }
1064
1077
  } catch (err) {
@@ -1075,6 +1088,8 @@ class Session {
1075
1088
  debug("No slate to load");
1076
1089
  throw err;
1077
1090
  }
1091
+ // Allow Leader|Follower to clear vodCache...
1092
+ this.isAllowedToClearVodCache = true;
1078
1093
  }
1079
1094
  break;
1080
1095
  case SessionState.VOD_RELOAD_INIT:
@@ -1147,6 +1162,8 @@ class Session {
1147
1162
  }
1148
1163
  this.waitingForNextVod = true;
1149
1164
  }
1165
+ // Allow Leader|Follower to clear vodCache...
1166
+ this.isAllowedToClearVodCache = true;
1150
1167
  return;
1151
1168
  default:
1152
1169
  throw new Error("Invalid state: " + sessionState.state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyevinn-channel-engine",
3
- "version": "3.2.4",
3
+ "version": "3.2.7",
4
4
  "description": "OTT TV Channel Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {