-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's been a while since I've looked deeply at the client code, and I found a ton of (in retrospect) obvious ways to remove unnecessary layers of abstraction and generally make the whole thing easier to understand.
- Loading branch information
Showing
7 changed files
with
76 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,77 @@ | ||
import React from "react"; | ||
import { Helmet } from "react-helmet"; | ||
|
||
import { useWebRTC } from "../WebRTC"; | ||
import rpc from "../rpc"; | ||
|
||
import "./index.scss"; | ||
|
||
import Title from "./Title"; | ||
import Header from "./Header"; | ||
import ChannelSelector from "./ChannelSelector"; | ||
import VideoPlayer from "./VideoPlayer"; | ||
import { useTunerStatus } from "../TunerStatus"; | ||
|
||
export default function App() { | ||
const webRTC = useWebRTC(); | ||
const tunerStatus = useTunerStatus(); | ||
|
||
const selectedChannel = | ||
tunerStatus.Connection === "Connected" && tunerStatus.State !== "Stopped" | ||
? tunerStatus.ChannelName | ||
: undefined; | ||
|
||
return ( | ||
<div className="AppContainer"> | ||
<Title /> | ||
<Header /> | ||
<ChannelSelector | ||
selected={ | ||
tunerStatus.Connection === "Connected" && | ||
tunerStatus.State !== "Stopped" | ||
? tunerStatus.ChannelName | ||
: undefined | ||
} | ||
onTune={(ChannelName) => | ||
rpc("tune", { ChannelName }).catch(console.error) | ||
} | ||
selected={selectedChannel} | ||
onTune={(ch) => rpc("tune", { ChannelName: ch }).catch(console.error)} | ||
/> | ||
<VideoPlayer stream={webRTC.MediaStream} /> | ||
</div> | ||
); | ||
} | ||
|
||
function Title() { | ||
const tunerStatus = useTunerStatus(); | ||
|
||
const titleText = | ||
tunerStatus.Connection === "Connected" && tunerStatus.State !== "Stopped" | ||
? `${tunerStatus.ChannelName} | Hypcast` | ||
: "Hypcast"; | ||
|
||
return ( | ||
<Helmet> | ||
<title>{titleText}</title> | ||
</Helmet> | ||
); | ||
} | ||
|
||
function VideoPlayer({ stream }: { stream: undefined | MediaStream }) { | ||
const videoElement = React.useRef<null | HTMLVideoElement>(null); | ||
|
||
React.useEffect(() => { | ||
if (videoElement.current !== null) { | ||
videoElement.current.srcObject = stream ?? null; | ||
} | ||
}, [stream]); | ||
|
||
/* eslint-disable jsx-a11y/media-has-caption */ | ||
// Lack of closed caption support is a longstanding deficiency in Hypcast. | ||
// After experimenting with several approaches in GStreamer, I'm ashamed to | ||
// say that I have yet to identify one that works reliably and consistently. | ||
// Also, it is not clear that the eventual implementation of closed captions | ||
// will involve WebVTT, which is what this rule actually looks for (through | ||
// the presence of a <track> element), so it may need to remain disabled even | ||
// after closed caption support is in place. | ||
return ( | ||
<main className="VideoPlayer"> | ||
<video | ||
style={{ display: stream === undefined ? "none" : undefined }} | ||
ref={videoElement} | ||
autoPlay | ||
controls | ||
/> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters