Live streaming tech selection (#24374)

* allow users to select live streaming technology

* fix webrtc being downgraded to mse on load

`useUserPersistence` seeds state with the default and loads asynchronously, so the first render always used `mse` instead of the saved choice, and `useWebRTCGloballyAvailable` reports `checking` until the probe settles and re-enters that state on every consumer mount, so a saved `webrtc` was rewritten to `mse` even after the probe had already passed. On Safari the MSE player then timed out and latched the jsmpeg fallback. A pending probe now counts as available, the player waits on `autoLive` until the stored preferences load, and `handleError` gates on the mode in use since the fallback flag no longer implies webrtc is untried. A rejected IndexedDB read also resolves `loaded` now, so a blocked store can't leave the player waiting forever.

* add support for configurable ICE servers in WebRTC player

* add mic error state, fix dialog overwriting saved choice and dashboard ignoring stream

* tweaks
This commit is contained in:
Josh Hawkins
2026-09-16 09:12:06 -05:00
committed by GitHub
parent 79ca18d439
commit 64d6366ac4
26 changed files with 1940 additions and 283 deletions
+58 -2
View File
@@ -174,7 +174,7 @@ export function detectCameraAudioFeatures(
const twoWayAudio =
(!requireSecureContext || window.isSecureContext) &&
metadata.producers.find(
(metadata.producers ?? []).find(
(prod) =>
prod.medias &&
prod.medias.find((media) => media.includes("audio, sendonly")) !=
@@ -182,7 +182,7 @@ export function detectCameraAudioFeatures(
) != undefined;
const audioOutput =
metadata.producers.find(
(metadata.producers ?? []).find(
(prod) =>
prod.medias &&
prod.medias.find((media) => media.includes("audio, recvonly")) !=
@@ -195,6 +195,62 @@ export function detectCameraAudioFeatures(
};
}
const MEDIA_DIRECTIONS = new Set(["sendonly", "recvonly", "sendrecv"]);
// "sendonly" is the two-way-talk backchannel, not playback audio.
const PLAYBACK_DIRECTIONS = new Set(["recvonly", "sendrecv"]);
// Parses a go2rtc media line: "audio, recvonly, OPUS/48000/2" -> ["OPUS"],
// stripping the "/clockrate[/channels]" suffix.
function codecsFromMedia(media: string): string[] {
const parts = media.split(",").map((p) => p.trim());
return parts
.slice(1)
.filter((p) => !MEDIA_DIRECTIONS.has(p.toLowerCase()))
.map((p) => p.split("/")[0].toUpperCase());
}
function mediaDirection(media: string): string | undefined {
return media
.split(",")
.map((p) => p.trim().toLowerCase())
.find((p) => MEDIA_DIRECTIONS.has(p));
}
function codecsForKind(
metadata: LiveStreamMetadata | null | undefined,
kind: "video" | "audio",
directions?: Set<string>,
): string[] {
if (!metadata) return [];
const codecs = new Set<string>();
for (const producer of metadata.producers ?? []) {
for (const media of producer.medias ?? []) {
if (!media.trim().toLowerCase().startsWith(kind)) continue;
if (directions) {
const direction = mediaDirection(media);
if (!direction || !directions.has(direction)) continue;
}
codecsFromMedia(media).forEach((c) => codecs.add(c));
}
}
return Array.from(codecs);
}
export function getStreamVideoCodecs(
metadata: LiveStreamMetadata | null | undefined,
): string[] {
return codecsForKind(metadata, "video");
}
// go2rtc exposes a WebRTC-capable playback codec only when one is configured
// (e.g. an opus transcode) or the camera streams G.711 natively.
export function getPlaybackAudioCodecs(
metadata: LiveStreamMetadata | null | undefined,
): string[] {
return codecsForKind(metadata, "audio", PLAYBACK_DIRECTIONS);
}
const REPLAY_CAMERA_PREFIX = "_replay_";
/**