WebRTC leaves signaling to the application. Peers must exchange session descriptions and connectivity candidates through a separate channel, and that channel must decide who belongs to a room. A description is not proof of user identity. Offer and answer state changes are asynchronous; reordered or replayed messages can apply to the wrong connection attempt. A room protocol therefore needs authenticated participants, a session generation, message type, bounded payload, sequence or dedupe rule, and expiry. The server should not broadcast private room messages to every connected browser.
WebRTC Signaling, Room Authorization, and Offer Order
Working case
Reviewers 29 and 47 are assigned to consultation room 62. Reviewer 29 sends an offer tagged generation 6. Reviewer 47 answers, and both exchange candidates for that generation. Reviewer 47 loses case access while a stale candidate is in flight; the signaling server denies later messages and closes the subscription. A delayed answer from generation 5 arrives after a reconnect and is ignored. Neither case title nor annotation text is embedded in the signaling event.
Implementation boundary
function acceptSignal(activeGeneration, messageGeneration, memberAllowed) {
return memberAllowed && activeGeneration === messageGeneration;
}
console.log(acceptSignal(6, 5, true));
// Output: falseAuthorize join and every signaling message against current room membership, not only a one-time room token. Bind messages to a room ID, sender identity, recipient identity, and generation. Validate description and candidate types and size before forwarding. Apply remote descriptions in the right peer state, then add candidates when their associated remote description is available. Define how both sides handle simultaneous offers, reconnects, and a closed room; a simple product may nominate one offerer to reduce glare. Keep logs coarse and expire stored signaling messages quickly.
Cost and boundaries
Signaling traffic is usually small compared with media, but retries and candidate bursts can fill a room service if messages are unbounded. Membership checks may require a cached authorization decision with a short lifetime and revocation path. Ordering metadata costs a few bytes per event and saves difficult reconnection bugs. Measure offer-to-answer latency, rejected generations, denied room messages, failed state transitions, and room cleanup delay. Do not use peer connection success to infer that the signaling server enforced access.
Failure trace
A stale answer from an earlier call is applied to a new RTCPeerConnection and throws a state error. Another server trusts a room ID supplied by the browser and forwards candidates to a reviewer removed from the case. Test simultaneous join, duplicate offer, out-of-order candidate, late answer, revoked membership, two open tabs, and a room closed before media starts. Ensure a failed negotiation does not leave a local microphone track running.
Verification
- Every message is room-authorized.
- Old generations cannot mutate a new negotiation.
- Descriptions and candidates have bounded validated envelopes.
Practice drill
Write a message schema for room 62 with sender, recipient, generation, type, and bounded payload. Replay generation 5 after generation 6 begins and verify rejection. Remove reviewer 47 mid-exchange and attempt to publish a candidate. Test simultaneous offers under the selected offerer rule. Capture only coarse state-transition events in logs and confirm no private case text appears in the signaling envelope.
Decision note
Treat signaling as a private application protocol with authorization and ordering, not as a passive message pipe.
Common Mistakes
- Using a room identifier as authorization.
- Applying a delayed answer to a new connection.
- Logging private case content with signaling events.
Connected lessons
Build Project: private peer consultation and review Web Development: browser compute and peer sessions quiz; follow WebRTC and Peer Media Sessions; Media Capture Consent and Track Lifecycle; WebRTC ICE, TURN Fallback, and Session Recovery; Data Channel Backpressure and Peer State; Server-Sent Events or WebSocket for Live Views; Live Update Reconnect and Event Ordering.
