mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-18 02:21:20 -08:00
- Deleted ARCHITECTURE.md file to streamline project documentation. - Refactored AudioEngine, EventTarget, MediaBunnyEngine, VideoEngine, VideoShim, and index.js for improved readability by adding consistent line breaks and spacing. - Enhanced code structure by ensuring single-responsibility principles and clearer flow in methods. - Updated TypeScript definitions for better clarity on options available in the artplayer-proxy-mediabunny package.
38 lines
705 B
JavaScript
38 lines
705 B
JavaScript
/**
|
|
* Event Target Implementation
|
|
* Simple event system for video events
|
|
*/
|
|
export default class EventTarget {
|
|
constructor() {
|
|
this.listeners = new Map()
|
|
}
|
|
|
|
addEventListener(type, fn) {
|
|
if (!this.listeners.has(type)) {
|
|
this.listeners.set(type, [])
|
|
}
|
|
this.listeners.get(type).push(fn)
|
|
}
|
|
|
|
removeEventListener(type, fn) {
|
|
const list = this.listeners.get(type)
|
|
if (!list)
|
|
return
|
|
|
|
const index = list.indexOf(fn)
|
|
if (index >= 0) {
|
|
list.splice(index, 1)
|
|
}
|
|
}
|
|
|
|
emit(type, detail) {
|
|
const evt = new Event(type)
|
|
evt.detail = detail
|
|
|
|
const list = this.listeners.get(type)
|
|
if (list) {
|
|
list.forEach(fn => fn(evt))
|
|
}
|
|
}
|
|
}
|