Loading files
"use client";
import { useEffect } from "react";
import { RoomEvent, type Room } from "livekit-client";
import { BROADCAST_TOPIC, type BroadcastControl } from "@/lib/types";
/**
* Lets a redeploy reach an already-running egress page: on the "broadcast" control message
* (POST /api/broadcast/reload) the page reloads itself. The egress + RTMP session persist through the
* reload. Shared by the landscape and vertical broadcast pages.
*/
export function useBroadcastReload(room: Room | null) {
useEffect(() => {
if (!room) return;
const onData = (payload: Uint8Array, _p?: unknown, _k?: unknown, topic?: string) => {
if (topic !== BROADCAST_TOPIC) return;
try {
const msg = JSON.parse(new TextDecoder().decode(payload)) as BroadcastControl;
if (msg.action === "reload") window.location.reload();
} catch {
/* ignore malformed */
}
};
room.on(RoomEvent.DataReceived, onData);
return () => {
room.off(RoomEvent.DataReceived, onData);
};
}, [room]);
}
05241c15dThis file is pinned to the selected release. Download the original to open it in your design tool.