eyevinn-channel-engine 3.1.5 → 3.1.6
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/engine/session.js +34 -4
- package/package.json +1 -1
package/engine/session.js
CHANGED
|
@@ -44,6 +44,8 @@ class Session {
|
|
|
44
44
|
this.maxTickInterval = DEFAULT_MAX_TICK_INTERVAL;
|
|
45
45
|
this.diffCompensation = null;
|
|
46
46
|
this.waitingForNextVod = false;
|
|
47
|
+
this.leaderIsSettingNextVod = false;
|
|
48
|
+
this.isSwitchingBackFromLive = false;
|
|
47
49
|
|
|
48
50
|
if (config) {
|
|
49
51
|
if (config.sessionId) {
|
|
@@ -258,6 +260,8 @@ class Session {
|
|
|
258
260
|
throw new Error('Session not ready');
|
|
259
261
|
}
|
|
260
262
|
|
|
263
|
+
this.isSwitchingBackFromLive = true;
|
|
264
|
+
|
|
261
265
|
let isLeader = await this._sessionStateStore.isLeader(this._instanceId);
|
|
262
266
|
if (!isLeader) {
|
|
263
267
|
debug(`[${this._sessionId}]: FOLLOWER: Invalidate cache to ensure having the correct VOD!`);
|
|
@@ -278,6 +282,7 @@ class Session {
|
|
|
278
282
|
if (!isLeader || vodReloaded) {
|
|
279
283
|
debug(`[${this._sessionId}]: FOLLOWER: leader is alive, and has presumably updated currentVod. Clearing the cache now`);
|
|
280
284
|
await this._sessionState.clearCurrentVodCache();
|
|
285
|
+
this.isSwitchingBackFromLive = false;
|
|
281
286
|
return;
|
|
282
287
|
}
|
|
283
288
|
}
|
|
@@ -313,6 +318,7 @@ class Session {
|
|
|
313
318
|
await this._playheadState.set("vodMediaSeqAudio", 0);
|
|
314
319
|
await this._playheadState.set("playheadRef", Date.now());
|
|
315
320
|
}
|
|
321
|
+
this.isSwitchingBackFromLive = false;
|
|
316
322
|
}
|
|
317
323
|
|
|
318
324
|
async getCurrentMediaSequenceSegments() {
|
|
@@ -350,6 +356,9 @@ class Session {
|
|
|
350
356
|
if (!this._sessionState) {
|
|
351
357
|
throw new Error('Session not ready');
|
|
352
358
|
}
|
|
359
|
+
|
|
360
|
+
this.isSwitchingBackFromLive = true;
|
|
361
|
+
|
|
353
362
|
const isLeader = await this._sessionStateStore.isLeader(this._instanceId);
|
|
354
363
|
if (isLeader) {
|
|
355
364
|
await this._sessionState.set("mediaSeq", _mediaSeq);
|
|
@@ -357,6 +366,7 @@ class Session {
|
|
|
357
366
|
await this._sessionState.set("discSeq", _discSeq);
|
|
358
367
|
debug(`[${this._sessionId}]: Setting current media and discontinuity count -> [${_mediaSeq}]:[${_discSeq}]`);
|
|
359
368
|
}
|
|
369
|
+
this.isSwitchingBackFromLive = false;
|
|
360
370
|
}
|
|
361
371
|
|
|
362
372
|
async getCurrentMediaAndDiscSequenceCount() {
|
|
@@ -395,6 +405,15 @@ class Session {
|
|
|
395
405
|
if (!this._sessionState) {
|
|
396
406
|
throw new Error('Session not ready');
|
|
397
407
|
}
|
|
408
|
+
// Be sure that the leader is not in the middle of setting new vod data in store.
|
|
409
|
+
// Followers will never run this part...
|
|
410
|
+
let tries = 4;
|
|
411
|
+
while(tries > 0 && this.leaderIsSettingNextVod) {
|
|
412
|
+
debug(`[${this._sessionId}]: Leader is setting the next vod. Waiting 500ms_${tries}`);
|
|
413
|
+
await timer(500);
|
|
414
|
+
tries--;
|
|
415
|
+
}
|
|
416
|
+
|
|
398
417
|
const sessionState = await this._sessionState.getValues(["vodMediaSeqVideo", "discSeq"]);
|
|
399
418
|
const playheadState = await this._playheadState.getValues(["mediaSeq", "vodMediaSeqVideo"]);
|
|
400
419
|
|
|
@@ -415,7 +434,7 @@ class Session {
|
|
|
415
434
|
await this._sessionState.clearCurrentVodCache(); // force reading up from shared store
|
|
416
435
|
}
|
|
417
436
|
}
|
|
418
|
-
|
|
437
|
+
|
|
419
438
|
const currentVod = await this._sessionState.getCurrentVod();
|
|
420
439
|
if (currentVod) {
|
|
421
440
|
try {
|
|
@@ -463,6 +482,14 @@ class Session {
|
|
|
463
482
|
async incrementAsync() {
|
|
464
483
|
await this._tickAsync();
|
|
465
484
|
const isLeader = await this._sessionStateStore.isLeader(this._instanceId);
|
|
485
|
+
// Avoid reading old values if new ones are on their way...
|
|
486
|
+
let tries = 10;
|
|
487
|
+
while (tries > 0 && this.isSwitchingBackFromLive) {
|
|
488
|
+
debug(`[${this._sessionId}]: Leader is currently setting new data in store. Waiting 500ms_${tries}`);
|
|
489
|
+
await timer(500);
|
|
490
|
+
tries--;
|
|
491
|
+
}
|
|
492
|
+
|
|
466
493
|
let sessionState = await this._sessionState.getValues(
|
|
467
494
|
["state", "mediaSeq", "discSeq", "vodMediaSeqVideo", "vodMediaSeqAudio"]);
|
|
468
495
|
let playheadState = await this._playheadState.getValues(["mediaSeq", "vodMediaSeqVideo", "vodMediaSeqAudio"]);
|
|
@@ -498,7 +525,7 @@ class Session {
|
|
|
498
525
|
sessionState.vodMediaSeqVideo = await this._sessionState.increment("vodMediaSeqVideo");
|
|
499
526
|
sessionState.vodMediaSeqAudio = await this._sessionState.increment("vodMediaSeqAudio");
|
|
500
527
|
}
|
|
501
|
-
|
|
528
|
+
|
|
502
529
|
if (sessionState.vodMediaSeqVideo >= currentVod.getLiveMediaSequencesCount() - 1) {
|
|
503
530
|
sessionState.vodMediaSeqVideo = await this._sessionState.set("vodMediaSeqVideo", currentVod.getLiveMediaSequencesCount() - 1);
|
|
504
531
|
sessionState.vodMediaSeqAudio = await this._sessionState.set("vodMediaSeqAudio", currentVod.getLiveMediaSequencesCount() - 1);
|
|
@@ -943,16 +970,19 @@ class Session {
|
|
|
943
970
|
await ChaosMonkey.loadVod(loadPromise);
|
|
944
971
|
cloudWatchLog(!this.cloudWatchLogging, 'engine-session',
|
|
945
972
|
{ event: 'loadVod', channel: this._sessionId, loadTimeMs: Date.now() - loadStart });
|
|
973
|
+
this.leaderIsSettingNextVod = true;
|
|
946
974
|
debug(`[${this._sessionId}]: next VOD loaded (${newVod.getDeltaTimes()})`);
|
|
947
975
|
debug(`[${this._sessionId}]: ${newVod.getPlayheadPositions()}`);
|
|
948
976
|
currentVod = newVod;
|
|
949
977
|
debug(`[${this._sessionId}]: msequences=${currentVod.getLiveMediaSequencesCount()}`);
|
|
950
|
-
await this._sessionState.remove("nextVod");
|
|
951
|
-
sessionState.currentVod = await this._sessionState.setCurrentVod(currentVod, { ttl: currentVod.getDuration() * 1000 });
|
|
952
978
|
sessionState.vodMediaSeqVideo = await this._sessionState.set("vodMediaSeqVideo", 0);
|
|
953
979
|
sessionState.vodMediaSeqAudio = await this._sessionState.set("vodMediaSeqAudio", 0);
|
|
954
980
|
sessionState.mediaSeq = await this._sessionState.set("mediaSeq", sessionState.mediaSeq + length);
|
|
955
981
|
sessionState.discSeq = await this._sessionState.set("discSeq", sessionState.discSeq + lastDiscontinuity);
|
|
982
|
+
debug(`[${this._sessionId}]: new sequence data set in store [${sessionState.mediaSeq}][${sessionState.discSeq}]`);
|
|
983
|
+
await this._sessionState.remove("nextVod");
|
|
984
|
+
sessionState.currentVod = await this._sessionState.setCurrentVod(currentVod, { ttl: currentVod.getDuration() * 1000 });
|
|
985
|
+
this.leaderIsSettingNextVod = false;
|
|
956
986
|
await this._playheadState.set("playheadRef", Date.now());
|
|
957
987
|
this.produceEvent({
|
|
958
988
|
type: 'NOW_PLAYING',
|