Short answer: treat removing a disruptive screen-sharing participant as a trust-state change, not as a socket operation. The server should record a room-scoped moderation epoch, stop authorizing the participant's media publication, and issue no new credential that can satisfy the old epoch. A reconnect then becomes an authorization decision with an explicit reason, rather than a race between a browser and a dropped connection.
This distinction matters in a media product. A viewer may be watching a live interview while another participant shares private material. The moderator needs the share to stop quickly, but the system also needs to preserve the room's audience experience, make the decision auditable, and avoid retaining a high-cardinality trail of every packet. I count those concerns separately: media state, authorization state, and telemetry state.
How can an API kick a disruptive participant from a video room?
The invariant is small: after a moderator removes participant p from room r at epoch e, no operation authorized under an older epoch may publish a new track or rejoin that room. Existing transport shutdown is useful for responsiveness, but it is not the security boundary. The authorization service is.
That gives the implementation three failure boundaries. First, a moderation command must be authenticated and scoped to the room. Second, the media control plane must reject publication after the participant's state changes. Third, the reconnect path must evaluate the current room state instead of trusting a token that was valid when the first connection opened.
The WebRTC 1.0 specification describes the browser objects and negotiation model; it does not define an application's room membership, moderator role, or ban policy. Those controls belong above the media API. In a Node.js service, that usually means keeping the room policy in a server-side store and making the client request a short-lived, room-scoped authorization artifact. The exact storage technology is an implementation choice. The trust decision is not.
A useful event is deliberately boring:
curl -X POST https://realtime.example.test/rooms/room-42/participants/p-17/removal \\ -H 'Authorization: Bearer moderator-token' \\ -H 'Content-Type: application/json' \\ -d '{"reason":"unauthorized_screen_share","epoch":18}' The response should identify the new policy version, not pretend that a network request can erase a remote browser instantly. The participant receives a control message or transport termination as an operational consequence. Every future authorization check compares the presented room epoch with the current one.
Which control shape survives a reconnect?
There are three common shapes. They are not equivalent, and each fails in a different place.
| Control shape | Immediate effect | Reconnect behavior | Boundary to test |
|---|---|---|---|
| Close the peer connection | Ends the current session when delivery succeeds | A still-valid credential may allow another session | Transport lifecycle is not membership policy |
| Mark the participant removed | New joins can be rejected | Works if every join and publish path reads the mark | Authorization coverage across all paths |
| Advance a room or participant epoch | Invalidates credentials tied to the older state | Explicitly rejects stale state, even after a retry | Atomic state update and token comparison |
For screen share, I would use the second and third shapes together. A removal record explains the decision; an epoch makes stale authorization easy to detect. Closing the peer connection remains a latency measure. It is not the record of truth.
The epoch can be room-wide or participant-specific. A room-wide epoch is easy to reason about but can force unrelated participants to refresh. A participant epoch limits the blast radius, at the cost of another lookup and a more detailed policy model. The correct choice follows the moderation rule: if one participant's removal changes only that participant's ability to publish, a participant epoch is the narrower invariant. If the room's policy changes for everyone, advance the room epoch.
Do not overload the epoch with a reason string, a timestamp, or a moderator identity. Keep those fields in an audit record. The authorization comparison needs a compact, monotonic value; the audit record needs human-readable context and retention rules. Mixing them encourages clients to treat explanatory data as permission data.
How does the reconnect path enforce the decision?
A reconnect is a new request. That sentence is the practical test. The browser can reconnect after a dropped ICE transport, a tab suspension, or a network transition, and those cases can look similar at the transport layer. The server must not infer that a reconnect is harmless because the original session was once accepted.
That is the part teams tend to skip. The close is visible; the stale credential is not.
The critical path is: authenticate the caller, load the current room and participant policy, compare the presented epoch, check the requested capability, then mint a credential whose scope is no broader than that result. A screen-share publisher should not receive a credential that also permits room administration.
Here is a generic request shape; the endpoint names are illustrative, while the ordering is the important part:
curl -X POST https://realtime.example.test/rooms/room-42/session-credentials \\ -H 'Authorization: Bearer user-token' \\ -H 'Content-Type: application/json' \\ -d '{"participant_id":"p-17","presented_epoch":17,"capabilities":["subscribe"]}' A rejected request should be stable enough for the client to stop retrying blindly. Returning an authorization result such as participant_removed is more useful than repeatedly reporting a generic transport failure. The client can then remove its share UI, preserve the moderator's message if policy permits, and avoid a reconnect loop.
There is a race to design for. A credential request may read epoch 17 while a moderator writes epoch 18. The update and the authorization decision need a defined consistency rule. One conservative rule is to make the policy write atomic with the value used for subsequent reads, and to recheck the epoch before issuing a credential. Another is to use a transaction or compare-and-swap operation in the policy store. The mechanism varies; the requirement is that a stale read cannot silently produce fresh authority after the removal commits.
The same rule applies to publishing. If the participant was allowed to subscribe but not publish after removal, capability checks must distinguish those operations. A single boolean named connected is too weak: it collapses room presence, subscription, publication, and moderation state into one value that cannot express the policy.
What should be measured without turning telemetry into a second liability?
I own the observability bill, so I read a log line as bytes stored and a label as cardinality. For this workflow, the useful dimensions are bounded: operation type, decision, capability, and a coarse reason class. The participant ID belongs in a trace or an access-controlled audit record, not in an unbounded metrics label.
Keep the operational counters narrow: removal commands accepted, stale epoch decisions, credential denials, and publication attempts rejected. Retain the audit event longer than the high-volume request log only when the product's policy requires it. Sampling can apply to successful refreshes; it should not erase denied moderation decisions or the transition that explains why a share stopped.
A compact event might look like this:
curl -X POST https://realtime.example.test/telemetry/events \\ -H 'Authorization: Bearer service-token' \\ -H 'Content-Type: application/json' \\ -d '{"event":"credential_denied","decision":"stale_epoch","capability":"publish_screen","room_class":"live_media"}' The point is not to ship this exact endpoint. It is to keep the event vocabulary smaller than the request vocabulary. A room ID, participant ID, token hash, browser fingerprint, and arbitrary reason text on every metric series can create a cardinality problem that obscures the signal it was meant to provide. Put correlation data where access controls and retention are explicit.
For a review, I ask four questions. Can an operator prove which policy version rejected the reconnect? Can the client distinguish a deliberate moderation decision from a transient network failure? Can a dashboard show stale-epoch denials without grouping by every participant? Can the retained record explain the decision without becoming a permanent transcript of private screen content? If any answer is no, adding more logs will probably make the system harder to operate.
The option I would reject, and when it is valid
I would reject a design that treats a peer-connection close as the complete removal API. It is attractive because it is immediate and easy to demonstrate: send a command, close the connection, watch the share disappear. It does not define what happens when the client presents an older credential, opens a second connection, or retries while the moderator action is propagating. Those are authorization cases, not transport cosmetics.
The rejected design is still valid for a narrow purpose: reducing the time that already-authorized media remains visible after a policy decision. Use it as a best-effort notification to the current session, paired with server-side state that controls the next request. That separation also improves testing. One test can verify that the transport is asked to close; another can verify that old epoch values cannot mint publication authority. The trade-off is operational complexity: epoch checks add a policy read and require a consistency rule, so they are a poor fit for a throwaway two-person call where there is no moderator role and no reconnect privilege to revoke. In a moderated media room, that cost buys a boundary the transport alone cannot provide.
The acceptance matrix should include a normal reconnect, a reconnect with a stale epoch, a subscribe-only request after publication is revoked, two concurrent removal commands, and a moderator action arriving while a credential is being minted. Add the browser behaviors that matter to screen sharing: the user stops the track locally, the tab sleeps, and the network changes. None of those events should grant authority that the current policy denies.
The decision rule is therefore direct: use transport shutdown for immediacy, an auditable removal state for meaning, and scoped epochs for reconnect enforcement. Keep the client informed, keep authorization on the server, and keep telemetry dimensions bounded. That combination answers the disruptive-participant problem without pretending that a media connection is the same thing as trust.
References
- W3C, WebRTC 1.0: Real-Time Communication Between Browsers: https://www.w3.org/TR/webrtc/
- W3C, WebRTC security and privacy considerations: https://www.w3.org/TR/webrtc/#security
- MDN, RTCPeerConnection: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection
