82 lines
1.5 KiB
TypeScript
Raw Normal View History

import { nanoid } from "nanoid";
import { _players } from "./cache";
import { VideoPlayerState } from "./types";
export function resetForSource(s: VideoPlayerState) {
const state = s;
state.mediaPlaying = {
isPlaying: false,
isPaused: true,
isLoading: false,
isSeeking: false,
isDragSeeking: false,
isFirstLoading: true,
hasPlayedOnce: false,
volume: 0,
};
state.progress = {
time: 0,
duration: 0,
buffered: 0,
draggingTime: 0,
};
state.initalized = false;
}
function initPlayer(): VideoPlayerState {
return {
2023-02-04 16:29:21 +01:00
interface: {
popout: null,
isFullscreen: false,
isFocused: false,
leftControlHovering: false,
popoutBounds: null,
2023-02-04 16:29:21 +01:00
},
mediaPlaying: {
isPlaying: false,
isPaused: true,
isLoading: false,
isSeeking: false,
isDragSeeking: false,
2023-02-04 16:29:21 +01:00
isFirstLoading: true,
hasPlayedOnce: false,
2023-02-04 18:24:06 +01:00
volume: 0,
2023-02-04 16:29:21 +01:00
},
progress: {
time: 0,
duration: 0,
buffered: 0,
draggingTime: 0,
2023-02-04 16:29:21 +01:00
},
meta: null,
source: null,
error: null,
canAirplay: false,
initalized: false,
2023-02-04 16:29:21 +01:00
pausedWhenSeeking: false,
hlsInstance: null,
2023-02-03 16:34:41 +01:00
stateProvider: null,
2023-02-04 01:01:54 +01:00
wrapperElement: null,
};
}
export function registerVideoPlayer(): string {
const id = nanoid();
if (_players.has(id)) {
throw new Error("duplicate id");
}
_players.set(id, initPlayer());
return id;
}
export function unregisterVideoPlayer(id: string) {
if (_players.has(id)) _players.delete(id);
}