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

Commit 83c1fa3

Browse files
feat(error): Switch items on error if available
1 parent 43f0b71 commit 83c1fa3

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
@@ -54,6 +54,8 @@ class MultiSource extends Meister.ParserPlugin {
5454
}
5555

5656
process(item) {
57+
this.currentItem = item;
58+
5759
return new Promise((resolve, reject) => {
5860
const hasDRM = typeof item.drmConfig === 'object';
5961
item.sources = this.restructureItems(item.sources, hasDRM); // eslint-disable-line
@@ -66,11 +68,30 @@ class MultiSource extends Meister.ParserPlugin {
6668
newItem.metadata = item.metadata; // eslint-disable-line
6769
}
6870

71+
this.on('playerError', this.onPlayerError.bind(this));
72+
6973
resolve(newItem);
7074
}
7175
});
7276
});
7377
}
78+
79+
onPlayerError() {
80+
// Unload our previous item.
81+
super.unload();
82+
83+
// We can remove the first item in our sources since it's not able to play.
84+
const removedItem = this.currentItem.sources.shift();
85+
86+
// Make sure we do have sources to play.
87+
if (!this.currentItem.sources.length) return;
88+
89+
console.warn(`${MultiSource.pluginName}: Item '${removedItem.type}' ran into an error while playing. Switching items for optimal experience.`);
90+
91+
// Now retry the whole flow.
92+
this.meister.setItem(this.currentItem);
93+
this.meister.load();
94+
}
7495
}
7596

7697
Meister.registerPlugin(MultiSource.pluginName, MultiSource);

0 commit comments

Comments
 (0)