48 lines
1.2 KiB
JavaScript
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;
|
|
}
|