mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-12 23:36:15 -08:00
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
import { errorHandle, isMobile, has, def } from '../utils';
|
|
import miniProgressBar from './miniProgressBar';
|
|
import autoOrientation from './autoOrientation';
|
|
import autoPlayback from './autoPlayback';
|
|
import fastForward from './fastForward';
|
|
import lock from './lock';
|
|
|
|
export default class Plugins {
|
|
constructor(art) {
|
|
this.art = art;
|
|
this.id = 0;
|
|
|
|
const { option } = art;
|
|
|
|
if (option.miniProgressBar && !option.isLive) {
|
|
this.add(miniProgressBar);
|
|
}
|
|
|
|
if (option.lock && isMobile) {
|
|
this.add(lock);
|
|
}
|
|
|
|
if (option.autoPlayback && !option.isLive) {
|
|
this.add(autoPlayback);
|
|
}
|
|
|
|
if (option.autoOrientation && isMobile) {
|
|
this.add(autoOrientation);
|
|
}
|
|
|
|
if (option.fastForward && isMobile && !option.isLive) {
|
|
this.add(fastForward);
|
|
}
|
|
|
|
for (let index = 0; index < option.plugins.length; index++) {
|
|
this.add(option.plugins[index]);
|
|
}
|
|
}
|
|
|
|
add(plugin) {
|
|
this.id += 1;
|
|
const result = plugin.call(this.art, this.art);
|
|
if (result instanceof Promise) {
|
|
return result.then((res) => this.next(plugin, res));
|
|
} else {
|
|
return this.next(plugin, result);
|
|
}
|
|
}
|
|
|
|
next(plugin, result) {
|
|
const pluginName = (result && result.name) || plugin.name || `plugin${this.id}`;
|
|
errorHandle(!has(this, pluginName), `Cannot add a plugin that already has the same name: ${pluginName}`);
|
|
def(this, pluginName, {
|
|
value: result,
|
|
});
|
|
return this;
|
|
}
|
|
}
|