import {useNetwork} from './useNetwork' const short = (id: string) => id.slice(0, 8) + '…' + id.slice(-4) const time = (ms: number) => new Date(ms).toLocaleTimeString() export default function App() { const {snapshot, dispatch} = useNetwork() const {selfId, connectedAt, centralId, amCentral, roster, state, version} = snapshot return (

CommonView

You

ID: {short(selfId)}
Connected at: {time(connectedAt)}
Role:{' '} {amCentral ? 'CENTRAL (source of truth)' : 'peer'}
Central peer:{' '} {centralId ? short(centralId) : '(none)'}

Shared state

counter = {state.counter}
version {version}
{' '}

Commands are sent to the central peer, which updates the authoritative state and broadcasts it back to everyone.

Peers in room ({roster.length})

{roster.map(p => ( ))}
ID Connected Role
{short(p.peerId)} {p.isSelf ? ' (you)' : ''} {time(p.connectedAt)} {p.isCentral ? 'central' : 'peer'}
) }