From ecc7834f44149b84d10b6c22249aaebda9fa56a5 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 1 Sep 2023 17:47:09 +0200 Subject: [PATCH] remove controller, introduce display interfaces --- src/components/player/display/base.ts | 0 .../player/display/displayInterface.ts | 21 ++++++------------- src/stores/player/controllers/base.ts | 21 ------------------- src/stores/player/controllers/types.ts | 6 ------ 4 files changed, 6 insertions(+), 42 deletions(-) create mode 100644 src/components/player/display/base.ts delete mode 100644 src/stores/player/controllers/base.ts delete mode 100644 src/stores/player/controllers/types.ts diff --git a/src/components/player/display/base.ts b/src/components/player/display/base.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/components/player/display/displayInterface.ts b/src/components/player/display/displayInterface.ts index 99ddc52c..0ce4cfdf 100644 --- a/src/components/player/display/displayInterface.ts +++ b/src/components/player/display/displayInterface.ts @@ -1,21 +1,12 @@ import { Source } from "@/components/player/hooks/usePlayer"; +import { Listener } from "@/utils/events"; -type EventMap = Record; -type EventKey = string & keyof T; -type EventReceiver = (params: T) => void; +export type DisplayInterfaceEvents = { + play: void; + pause: void; +}; -export interface Emitter { - on>(eventName: K, fn: EventReceiver): void; - off>(eventName: K, fn: EventReceiver): void; - emit>(eventName: K, params: T[K]): void; -} - -interface Listener { - on>(eventName: K, fn: EventReceiver): void; -} - -export interface DisplayInterface - extends Listener { +export interface DisplayInterface extends Listener { play(): void; pause(): void; load(source: Source): void; diff --git a/src/stores/player/controllers/base.ts b/src/stores/player/controllers/base.ts deleted file mode 100644 index 397bedc7..00000000 --- a/src/stores/player/controllers/base.ts +++ /dev/null @@ -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; - }, - }; -} diff --git a/src/stores/player/controllers/types.ts b/src/stores/player/controllers/types.ts deleted file mode 100644 index 46904497..00000000 --- a/src/stores/player/controllers/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Controller { - pause(): void; - play(): void; - setVolume(target: number): void; - registerVideoElement(videoElement: HTMLVideoElement): void; -}