48 lines
975 B
TypeScript
Raw Normal View History

import { nanoid } from "nanoid";
import { _players } from "./cache";
import { VideoPlayerState } from "./types";
function initPlayer(): VideoPlayerState {
return {
isPlaying: false,
isPaused: true,
isFullscreen: false,
isFocused: false,
isLoading: false,
isSeeking: false,
isFirstLoading: true,
time: 0,
duration: 0,
volume: 0,
buffered: 0,
pausedWhenSeeking: false,
hasInitialized: false,
leftControlHovering: false,
hasPlayedOnce: false,
error: null,
popout: null,
seasonData: {
isSeries: false,
},
canAirplay: false,
2023-02-03 16:34:41 +01:00
stateProvider: null,
source: 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);
}