mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 01:05:08 +01:00
remove controller, introduce display interfaces
This commit is contained in:
parent
8fe3385fb1
commit
ecc7834f44
0
src/components/player/display/base.ts
Normal file
0
src/components/player/display/base.ts
Normal file
@ -1,21 +1,12 @@
|
||||
import { Source } from "@/components/player/hooks/usePlayer";
|
||||
import { Listener } from "@/utils/events";
|
||||
|
||||
type EventMap = Record<string, any>;
|
||||
type EventKey<T extends EventMap> = string & keyof T;
|
||||
type EventReceiver<T> = (params: T) => void;
|
||||
export type DisplayInterfaceEvents = {
|
||||
play: void;
|
||||
pause: void;
|
||||
};
|
||||
|
||||
export interface Emitter<T extends EventMap> {
|
||||
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> {
|
||||
export interface DisplayInterface extends Listener<DisplayInterfaceEvents> {
|
||||
play(): void;
|
||||
pause(): void;
|
||||
load(source: Source): void;
|
||||
|
@ -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;
|
||||
},
|
||||
};
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
export interface Controller {
|
||||
pause(): void;
|
||||
play(): void;
|
||||
setVolume(target: number): void;
|
||||
registerVideoElement(videoElement: HTMLVideoElement): void;
|
||||
}
|
Loading…
Reference in New Issue
Block a user