2023-02-04 01:01:54 +01:00
|
|
|
export type VideoPlayerEvent =
|
|
|
|
| "mediaplaying"
|
|
|
|
| "source"
|
|
|
|
| "progress"
|
2023-02-04 16:29:21 +01:00
|
|
|
| "interface"
|
2023-02-07 16:01:05 +01:00
|
|
|
| "meta"
|
|
|
|
| "error"
|
|
|
|
| "misc";
|
2023-02-02 22:04:58 +01:00
|
|
|
|
|
|
|
function createEventString(id: string, event: VideoPlayerEvent): string {
|
|
|
|
return `_vid:::${id}:::${event}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function sendEvent<T>(id: string, event: VideoPlayerEvent, data: T) {
|
|
|
|
const evObj = new CustomEvent(createEventString(id, event), {
|
|
|
|
detail: data,
|
|
|
|
});
|
|
|
|
document.dispatchEvent(evObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function listenEvent<T>(
|
|
|
|
id: string,
|
|
|
|
event: VideoPlayerEvent,
|
|
|
|
cb: (data: T) => void
|
|
|
|
) {
|
|
|
|
document.addEventListener<any>(createEventString(id, event), cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unlistenEvent<T>(
|
|
|
|
id: string,
|
|
|
|
event: VideoPlayerEvent,
|
|
|
|
cb: (data: T) => void
|
|
|
|
) {
|
|
|
|
document.removeEventListener<any>(createEventString(id, event), cb);
|
|
|
|
}
|