Files
ArtPlayer/packages/artplayer-proxy-mediabunny/src/EventTarget.js
T
Harvey Zhao 9d760a2f59 refactor: remove architecture documentation and improve code readability
- 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.
2026-01-01 17:25:21 +08:00

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))
}
}
}