构建事件代理

This commit is contained in:
Harvey Zack committed 2018-12-18 10:41:34 +08:00
1 parent f4c2e11b86
commit b7e740ae61
6 files changed
+233 -13

No files matched your search

+32 -2
View File
@@ -1,24 +1,54 @@
import Emitter from 'tiny-emitter';
import CheckSupport from './checkSupport';
import EventProxy from './eventProxy';
import CreatMediaSource from './creatMediaSource';
import * as utils from './utils';
import config from './config';
let id = 0;
class Flv extends Emitter {
constructor(mediaElement, url) {
super();
utils.errorHandle(mediaElement instanceof HTMLVideoElement, 'The first parameter is not a video tag element');
utils.errorHandle(typeof url === 'string', 'The second parameter is not a string type');
this.mediaElement = mediaElement;
this.url = url;
this.support = new CheckSupport(this);
this.events = new EventProxy(this);
this.mediaSource = new CreatMediaSource(this);
id += 1;
this.id = id;
Flv.instances.push(this);
}
static get version() {
return '__VERSION__';
}
static get config() {
return config;
}
static get utils() {
return utils;
}
load() {
console.log(this);
console.log(this.id);
}
destroy() {
console.log(this);
this.events.destroy();
Flv.instances.splice(Flv.instances.indexOf(this), 1);
this.emit('destroy');
}
}
Object.defineProperty(Flv, 'instances', {
value: [],
});
window.Flv = Flv;
export default Flv;