2023-01-24 17:12:37 +00:00
|
|
|
import { MWStreamQuality, MWStreamType } from "@/backend/helpers/streams";
|
2023-01-17 20:12:39 +00:00
|
|
|
import { useContext, useEffect, useRef } from "react";
|
2023-01-08 12:15:32 +00:00
|
|
|
import { VideoPlayerDispatchContext } from "../VideoContext";
|
|
|
|
|
|
|
|
interface SourceControlProps {
|
|
|
|
source: string;
|
2023-01-13 23:12:56 +00:00
|
|
|
type: MWStreamType;
|
2023-01-24 17:12:37 +00:00
|
|
|
quality: MWStreamQuality;
|
2023-01-08 12:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function SourceControl(props: SourceControlProps) {
|
|
|
|
const dispatch = useContext(VideoPlayerDispatchContext);
|
2023-01-17 20:12:39 +00:00
|
|
|
const didInitialize = useRef(false);
|
2023-01-08 12:15:32 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-17 20:12:39 +00:00
|
|
|
if (didInitialize.current) return;
|
2023-01-08 12:15:32 +00:00
|
|
|
dispatch({
|
|
|
|
type: "SET_SOURCE",
|
|
|
|
url: props.source,
|
2023-01-10 18:53:55 +00:00
|
|
|
sourceType: props.type,
|
2023-01-24 17:12:37 +00:00
|
|
|
quality: props.quality,
|
2023-01-08 12:15:32 +00:00
|
|
|
});
|
2023-01-17 20:12:39 +00:00
|
|
|
didInitialize.current = true;
|
2023-01-10 18:53:55 +00:00
|
|
|
}, [props, dispatch]);
|
2023-01-08 12:15:32 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|