2023-07-23 16:30:22 +02:00
|
|
|
import { MWStreamType } from "@/backend/helpers/streams";
|
|
|
|
import { MakeSlice } from "@/stores/player/slices/types";
|
|
|
|
import { ValuesOf } from "@/utils/typeguard";
|
|
|
|
|
|
|
|
export const playerStatus = {
|
|
|
|
IDLE: "idle",
|
|
|
|
SCRAPING: "scraping",
|
|
|
|
PLAYING: "playing",
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export type PlayerStatus = ValuesOf<typeof playerStatus>;
|
|
|
|
|
2023-08-15 19:55:48 +02:00
|
|
|
export interface SourceSliceSource {
|
|
|
|
url: string;
|
|
|
|
type: MWStreamType;
|
|
|
|
}
|
|
|
|
|
2023-07-23 16:30:22 +02:00
|
|
|
export interface SourceSlice {
|
|
|
|
status: PlayerStatus;
|
2023-08-15 19:55:48 +02:00
|
|
|
source: SourceSliceSource | null;
|
2023-07-23 16:30:22 +02:00
|
|
|
setStatus(status: PlayerStatus): void;
|
|
|
|
setSource(url: string, type: MWStreamType): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createSourceSlice: MakeSlice<SourceSlice> = (set) => ({
|
|
|
|
source: null,
|
|
|
|
status: playerStatus.IDLE,
|
|
|
|
setStatus(status: PlayerStatus) {
|
|
|
|
set((s) => {
|
|
|
|
s.status = status;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setSource(url: string, type: MWStreamType) {
|
|
|
|
set((s) => {
|
|
|
|
s.source = {
|
|
|
|
type,
|
|
|
|
url,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|