diff --git a/thrimbletrimmer/src/common/streamInfo.tsx b/thrimbletrimmer/src/common/streamInfo.tsx index f0caef5..d71f7b5 100644 --- a/thrimbletrimmer/src/common/streamInfo.tsx +++ b/thrimbletrimmer/src/common/streamInfo.tsx @@ -4,4 +4,34 @@ export class StreamVideoInfo { streamName: string; streamStartTime: DateTime; streamEndTime: DateTime | null; + + public static defaultFromURL(): StreamVideoInfo | null { + const url = new URL(window.location.href); + const urlParams = url.searchParams; + const stream = urlParams.get("stream"); + const start = urlParams.get("start"); + const end = urlParams.get("end"); + if (stream === null) { + return null; + } + if (start === null) { + return null; + } + const startTime = DateTime.fromISO(start, { zone: "utc" }); + if (!startTime.isValid) { + return null; + } + let endTime: DateTime | null = null; + if (end !== null) { + endTime = DateTime.fromISO(end, { zone: "utc" }); + if (!endTime.isValid) { + return null; + } + } + return { + streamName: stream, + streamStartTime: startTime, + streamEndTime: endTime, + }; + } } diff --git a/thrimbletrimmer/src/common/video.tsx b/thrimbletrimmer/src/common/video.tsx index dd61acd..2a2ba94 100644 --- a/thrimbletrimmer/src/common/video.tsx +++ b/thrimbletrimmer/src/common/video.tsx @@ -27,13 +27,20 @@ export const VIDEO_FRAMES_PER_SECOND = 30; export const PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4, 8]; export interface StreamTimeSettingsProps { + /** Getter for the signal to get the time when the run starts. */ busStartTime: Accessor; + /** Getter for the StreamVideoInfo signal. Used to set field values and, if applicable, apply defaults. */ streamVideoInfo: Accessor; + /** Setter for the StreamVideoInfo signal. */ setStreamVideoInfo: Setter; - /// If true, shows a link to the same page with the specified stream and time range. For the link to work, the host - /// page must support defaulting the link data into the StreamVideoInfo. + /** + * If true, shows a link to the same page with the specified stream and time range. For the link to work, the host + * page must support defaulting the link data into the StreamVideoInfo. + */ showTimeRangeLink: boolean; + /** Getter for the signal containing the list of errors to display. */ errorList: Accessor; + /** Setter for the signal containing the list of errors to display. */ setErrorList: Setter; } diff --git a/thrimbletrimmer/src/restreamer/Restreamer.tsx b/thrimbletrimmer/src/restreamer/Restreamer.tsx index 13e3101..6fe3a4a 100644 --- a/thrimbletrimmer/src/restreamer/Restreamer.tsx +++ b/thrimbletrimmer/src/restreamer/Restreamer.tsx @@ -91,11 +91,15 @@ const RestreamerWithDefaults: Component = (props) => { return <>; } const [busStartTime, setBusStartTime] = createSignal(busStartTimeDefault); - const [streamVideoInfo, setStreamVideoInfo] = createSignal({ - streamName: props.defaults.video_channel, - streamStartTime: DateTime.utc().minus({ minutes: 10 }), - streamEndTime: null, - }); + let defaultStreamInfo = StreamVideoInfo.defaultFromURL(); + if (defaultStreamInfo === null) { + defaultStreamInfo = { + streamName: props.defaults.video_channel, + streamStartTime: DateTime.utc().minus({ minutes: 10 }), + streamEndTime: null, + }; + } + const [streamVideoInfo, setStreamVideoInfo] = createSignal(defaultStreamInfo); const [playerTime, setPlayerTime] = createSignal(0); const [mediaPlayer, setMediaPlayer] = createSignal(); const [videoFragments, setVideoFragments] = createSignal([]);