Files
client/app/renderer/js/state.js
T
omar 7287fdb63e
ci / linux-x64 (push) Failing after 1m26s
ci / linux-arm64-cross (push) Failing after 2m20s
TeamsPeach desktop client: Electron UI, Rust core bridge, TS6 stream viewer, CI
2026-10-24 03:31:54 +03:00

48 lines
1.2 KiB
JavaScript

// Single renderer state object plus a tiny topic bus. The core snapshot is replaced wholesale (bridge §5).
export const S = {
core: { status: 'starting' },
profile: null,
prefs: null,
conn: { state: 'disconnected', address: '', reason: null },
snap: null,
audio: { input_muted: false, output_muted: false, transmitting: false },
talking: new Set(),
view: 'main',
ptt: false,
codecBlocked: null,
};
const listeners = new Map();
export function on(topic, fn) {
if (!listeners.has(topic)) listeners.set(topic, new Set());
listeners.get(topic).add(fn);
}
export function emit(topic, payload) {
const set = listeners.get(topic);
if (!set) return;
for (const fn of set) fn(payload);
}
export function ownClient() {
const snap = S.snap;
if (!snap) return null;
return snap.clients.find((c) => c.id === snap.own_client_id) ?? null;
}
export function ownChannel() {
const snap = S.snap;
if (!snap) return null;
return snap.channels.find((c) => c.id === snap.own_channel_id) ?? null;
}
export function clientById(id) {
return S.snap ? S.snap.clients.find((c) => c.id === id) ?? null : null;
}
export function isConnected() {
return S.conn.state === 'connected' && S.snap !== null;
}