Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 0e22325

Browse files
feat(error): Allow disabling of switching when a successful played item has been found
1 parent e9bdbb0 commit 0e22325

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/js/MultiSource.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import packageJson from '../../package.json';
22

33
class MultiSource extends Meister.ParserPlugin {
4+
constructor(config, meister) {
5+
super(config, meister);
6+
7+
// Keep track when a successful play has been done.
8+
// This way we can prevent multisource from loading a new item in.
9+
this.successfulPlayed = false;
10+
}
411

512
static get pluginName() {
613
return 'MultiSource';
@@ -66,12 +73,17 @@ class MultiSource extends Meister.ParserPlugin {
6673
}
6774

6875
this.currentItem = item;
76+
this.successfulPlayed = false;
6977

7078
// Set default config
7179
if (typeof this.currentItem.switchItemOnError === 'undefined') {
7280
this.currentItem.switchItemOnError = true;
7381
}
7482

83+
if (typeof this.currentItem.disableFallbackAfterSuccess === 'undefined') {
84+
this.currentItem.disableFallbackAfterSuccess = true;
85+
}
86+
7587
return new Promise((resolve, reject) => {
7688
const hasDRM = typeof item.drmConfig === 'object';
7789
item.sources = this.restructureItems(item.sources, hasDRM); // eslint-disable-line
@@ -86,6 +98,10 @@ class MultiSource extends Meister.ParserPlugin {
8698

8799
if (this.currentItem.switchItemOnError) {
88100
this.on('playerError', this.onPlayerError.bind(this));
101+
102+
if (this.currentItem.disableFallbackAfterSuccess) {
103+
this.on('playerPlaying', this.onPlayerPlaying.bind(this));
104+
}
89105
}
90106

91107
resolve(newItem);
@@ -94,6 +110,10 @@ class MultiSource extends Meister.ParserPlugin {
94110
});
95111
}
96112

113+
onPlayerPlaying() {
114+
this.successfulPlayed = true;
115+
}
116+
97117
onPlayerError() {
98118
// Unload our previous item.
99119
super.unload();
@@ -103,6 +123,7 @@ class MultiSource extends Meister.ParserPlugin {
103123

104124
// Make sure we do have sources to play.
105125
if (!this.currentItem.sources.length) return;
126+
if (this.successfulPlayed) return;
106127

107128
console.warn(`${MultiSource.pluginName}: Item '${removedItem.type}' ran into an error while playing. Switching items for optimal experience.`);
108129

0 commit comments

Comments
 (0)