remove controller, introduce display interfaces

This commit is contained in:
mrjvs 2023-09-01 17:47:09 +02:00
parent 8fe3385fb1
commit ecc7834f44
4 changed files with 6 additions and 42 deletions

View File

View File

@ -1,21 +1,12 @@
import { Source } from "@/components/player/hooks/usePlayer"; import { Source } from "@/components/player/hooks/usePlayer";
import { Listener } from "@/utils/events";
type EventMap = Record<string, any>; export type DisplayInterfaceEvents = {
type EventKey<T extends EventMap> = string & keyof T; play: void;
type EventReceiver<T> = (params: T) => void; pause: void;
};
export interface Emitter<T extends EventMap> { export interface DisplayInterface extends Listener<DisplayInterfaceEvents> {
on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
emit<K extends EventKey<T>>(eventName: K, params: T[K]): void;
}
interface Listener<T extends EventMap> {
on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
}
export interface DisplayInterface<Events extends EventMap>
extends Listener<Events> {
play(): void; play(): void;
pause(): void; pause(): void;
load(source: Source): void; load(source: Source): void;

View File

@ -1,21 +0,0 @@
import { Controller } from "@/stores/player/controllers/types";
export function useBaseController(): Controller {
let el: HTMLVideoElement | undefined;
return {
registerVideoElement(video) {
el = video;
},
pause() {
el?.pause();
},
play() {
el?.play();
},
setVolume(target) {
if (!el) return;
el.volume = target;
},
};
}

View File

@ -1,6 +0,0 @@
export interface Controller {
pause(): void;
play(): void;
setVolume(target: number): void;
registerVideoElement(videoElement: HTMLVideoElement): void;
}