2023-02-02 22:04:58 +01:00
|
|
|
import { nanoid } from "nanoid";
|
|
|
|
import { _players } from "./cache";
|
|
|
|
import { VideoPlayerState } from "./types";
|
|
|
|
|
|
|
|
function initPlayer(): VideoPlayerState {
|
|
|
|
return {
|
2023-02-04 16:29:21 +01:00
|
|
|
interface: {
|
|
|
|
popout: null,
|
|
|
|
isFullscreen: false,
|
|
|
|
isFocused: false,
|
|
|
|
leftControlHovering: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
mediaPlaying: {
|
|
|
|
isPlaying: false,
|
|
|
|
isPaused: true,
|
|
|
|
isLoading: false,
|
|
|
|
isSeeking: false,
|
|
|
|
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,
|
2023-02-07 23:20:00 +01:00
|
|
|
draggingTime: 0,
|
2023-02-04 16:29:21 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
meta: null,
|
|
|
|
source: null,
|
|
|
|
|
2023-02-07 16:01:05 +01:00
|
|
|
error: null,
|
2023-02-02 22:04:58 +01:00
|
|
|
canAirplay: false,
|
2023-02-07 16:01:05 +01:00
|
|
|
initalized: false,
|
2023-02-04 16:29:21 +01:00
|
|
|
|
2023-02-07 16:01:05 +01:00
|
|
|
pausedWhenSeeking: false,
|
2023-02-03 16:34:41 +01:00
|
|
|
stateProvider: null,
|
2023-02-04 01:01:54 +01:00
|
|
|
wrapperElement: null,
|
2023-02-02 22:04:58 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|