1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-08 17:27:40 +01:00
smov/src/video/state/events.ts
Jelle van Snik 76e4bc5851 shortcuts, progress saving fix, error handling, airplay, safe are for full screen only
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
2023-02-07 16:01:05 +01:00

35 lines
792 B
TypeScript

export type VideoPlayerEvent =
| "mediaplaying"
| "source"
| "progress"
| "interface"
| "meta"
| "error"
| "misc";
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);
}