import { useEffect, useState } from "react"; import { useCopy } from "../../ui/copy"; import { Glyph } from "../../ui/icons"; import { MAX_RELAY_CAPACITY } from "../protocol"; import type { NativeRelayCapacity } from "../app-link"; import type { ChannelController } from "../types"; import { ChannelSettingsError } from "./ChannelSettingsDialog"; import { useSettingsAction } from "../../ui/use-settings-action"; import "./channel-interface-control.css"; function ForwardingLimit({ label, value, disabled, onChange }: { label: string; value: number; disabled?: boolean; onChange(value: number): void; }) { const { t } = useCopy(); return ; } export function ChannelForwardingSettings({ channel }: { channel: ChannelController }) { const { t } = useCopy(); const [open, setOpen] = useState(false); const [app, setApp] = useState(null); const [failed, setFailed] = useState(false); const { error, run } = useSettingsAction(open); const read = channel.appRelayCapacity; const connected = channel.connection === "connected"; useEffect(() => { setApp(null); setFailed(false); if (!open || !connected || !channel.appConnected) return; const lifetime = new AbortController(); void read(lifetime.signal).then(value => { if (!lifetime.signal.aborted) setApp(value); }, () => { if (!lifetime.signal.aborted) setFailed(true); }); return () => lifetime.abort(); }, [open, connected, channel.appConnected, channel.sessionId, read]); if (!channel.self) return null; return
setOpen(event.currentTarget.open)}> {t("channel.forwarding.title")}

{t("channel.forwarding.note")}

{channel.appConnected && (app ? { void run(() => channel.setAppRelayOverride(app, value < 0 ? null : value), setApp); }} /> :

{t(failed || !connected ? "room.relay.appUnavailable" : "common.loading")}

)}
; }