export type VideoPlayerEvent = | "mediaplaying" | "source" | "progress" | "interface" | "meta" | "error" | "misc"; function createEventString(id: string, event: VideoPlayerEvent): string { return `_vid:::${id}:::${event}`; } export function sendEvent(id: string, event: VideoPlayerEvent, data: T) { const evObj = new CustomEvent(createEventString(id, event), { detail: data, }); document.dispatchEvent(evObj); } export function listenEvent( id: string, event: VideoPlayerEvent, cb: (data: T) => void ) { document.addEventListener(createEventString(id, event), cb); } export function unlistenEvent( id: string, event: VideoPlayerEvent, cb: (data: T) => void ) { document.removeEventListener(createEventString(id, event), cb); }