Extract the shared bus-drain and control-dispatch machinery (LC-616) #575
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/lc616-rtc-machinery"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes LC-616. The mechanical follow-up deferred from LC-613 (#574).
What was duplicated
call.jsandvoice.jseach open a WebSocket "bus" the server pushes OOB fragments into, and each binds one delegated click listener for its control bar. Two idioms were duplicated:call.js's call bus and control bus, andvoice.js's voice bus. All three are the same MutationObserver differing only in the bus id, the event attribute, and the handler.clicklistener with at.closest(sel) -> handler; returnchain, same idiom in both files.What this adds
A new
server/assets/rtc_common.jsexposingwindow.LetsChatRtc:watchBus(busId, eventAttr, handler)- the drain, parameterized by exactly the three tokens that differed.bindControls(map)- one delegated listener from aselector -> fn(el, event)map, matching the first selector the target is inside and short-circuiting, as the old if/else chains did. The handler gets(el, event), which is what letscall.js's start-button case keep itspreventDefault+ room/peer context extraction; every other case is a nullary handler.Loaded before both consumers; base.html is the only place these scripts load.
Still surface-specific, on purpose
Per LC-613, the media operations (mute/camera/screen) and the signaling frames stay per-file - they are genuinely different between one
RTCPeerConnection, a mesh, and the SFU. This PR is machinery only.No behaviour change (no JS harness, so verified by)
node --check)handleSignal/handleControl/handleEvent) and thewatchBus()/watchControlBus()registration sites are intactdeferscripts,rtc_common.jsfirst, sowindow.LetsChatRtcis defined before the consumers execute their IIFEs(el, e)signature and itsisFiniteguard, and insertion-order dispatch (start checked first)just checkclean.Net
~90 lines of duplication removed across two files for ~70 in one shared module - single source of truth. One new global namespace (
LetsChatRtc), offset by the room global LC-613 already removed, so the overall global count is flat.🤖 Generated with Claude Code
https://claude.ai/code/session_01FhDVMViNHqUbwmfe2aXTv5