webrtc-mock
Skill2 starsChanged 4 months agoMITView on GitHub
Use when touching any WebRTC code during the mockup phase — local getUserMedia, peer connection, remote stream simulation, signalling stubs. The contract is: real local stream + faithfully-faked remote stream, so the code path is identical when real signalling lands in Phase 5.
In this repository3 other files it gives its agents.
- agent-uiSkill
- mock-stateSkill
- widget-componentSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 21
Use real navigator.mediaDevices.getUserMedia for the local stream.
- Very specific: line 22
Use real getDisplayMedia for screen sharing for the same reason.
- Very specific: line 28
Always call stream.getTracks().forEach(t => t.stop()) when ending a session.
- Very specific: line 32
Don't fake getUserMedia. The camera permission flow is the most fragile UX in the product.
- Very specific: line 33
Don't store MediaStream objects in a Zustand/store value as a deep observable.
- Distinctive: line 34
Don't bypass the mock bus for signalling.
- Very specific: line 35
Don't use <video autoplay muted> without playsinline on iOS Safari — full-screen takeover surprise.
- Very specific: line 36
Don't call setRemoteDescription with a null SDP.
- Very specific: line 37
Don't ship a MediaStream to the host page (widget context).
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
webrtc-mock
WebRTC is the part most likely to surprise us in Phase 5 because the API is fiddly and the failure modes are platform-specific. The mock strategy is therefore: use the real API for everything that touches the user (camera permission, local preview, track add/remove, screen capture) and fake only the signalling and the remote stream. Anything we test in the mock should behave the same against a real backend.
When to use
- Touching any WebRTC-related file (
*RtcConnection.ts, video tile components, screen-share buttons, permission prompts) - Wiring local camera/mic preview in the widget or agent app
- Implementing the "incoming call" UX (ringing, accept, decline)
- Simulating an agent or visitor on the other end during demos
Skip for non-media code (chat messages, soft locks) — those go via the mock event bus, not this skill.
Do
- Use real
navigator.mediaDevices.getUserMediafor the local stream. We want the real camera permission UX — there is no faking it. - Use real
getDisplayMediafor screen sharing for the same reason. - Stub
RTCPeerConnectionbehind aPeerConnectionLikeclass that has the same shape (addTrack,createOffer,createAnswer,setRemoteDescription,addIceCandidate,ontrack,onicecandidate). The mock pipes local tracks straight to the remoteMediaStreamit exposes viaontrack. - The "remote" video stream on the visitor side is rendered from a
<canvas>showing an animated "Agent placeholder" tile (initials in a Fraunces letter, ticking 1Hz waveform). Capture it withcanvas.captureStream(15). - The "remote" stream on the agent side is a small looped
<video>element of stock footage piped throughvideo.captureStream(30)— so the agent sees motion, not a still. - Emit/consume signalling events through the mock bus using the existing
webrtc:offer/webrtc:answer/webrtc:iceschemas. Do not invent a parallel transport. - Track every active
MediaStreamand everyRTCPeerConnectionin a registry so a singlecleanup()call can stop all tracks and close all connections — the demo's "reset mock state" button calls it. - Always call
stream.getTracks().forEach(t => t.stop())when ending a session. Browsers leak the camera light otherwise.
Don't
- Don't fake
getUserMedia. The camera permission flow is the most fragile UX in the product; faking it means we discover real bugs at the worst possible moment (Phase 5 demo). - Don't store
MediaStreamobjects in a Zustand/store value as a deep observable. They're not serializable. Hold a stream id and look it up in the registry. - Don't bypass the mock bus for signalling. The whole point is that swapping to Socket.IO doesn't touch this layer.
- Don't use
<video autoplay muted>withoutplaysinlineon iOS Safari — full-screen takeover surprise. - Don't call
setRemoteDescriptionwith anullSDP. Always check bothoffer.sdpandanswer.sdpexist before forwarding. - Don't ship a
MediaStreamto the host page (widget context). All WebRTC objects live inside the widget's Shadow DOM tree.
One short example
// packages/widget/src/webrtc/MockPeerConnection.ts
export class MockPeerConnection {
remoteStream = new MediaStream();
onicecandidate: ((c: RTCIceCandidateInit | null) => void) | null = null;
ontrack: ((stream: MediaStream) => void) | null = null;
addTrack(track: MediaStreamTrack): void {
// Mock loopback: visitor's own track also appears on the "remote" stream
// so the agent-side canvas placeholder is what the visitor sees, and
// the visitor's camera is what the agent (in the mock) sees.
this.remoteStream.addTrack(track);
}
async createOffer(): Promise<RTCSessionDescriptionInit> {
return { type: 'offer', sdp: `mock-offer\n` };
}
async createAnswer(): Promise<RTCSessionDescriptionInit> {
return { type: 'answer', sdp: `mock-answer\n` };
}
async setRemoteDescription(_d: RTCSessionDescriptionInit): Promise<void> {
queueMicrotask(() => this.ontrack?.(this.remoteStream));
}
async addIceCandidate(_c: RTCIceCandidateInit): Promise<void> {}
close(): void {
this.remoteStream.getTracks().forEach((t) => t.stop());
}
}Reference
- Event schema (signalling events):
packages/shared/src/events/schema.ts - Bus interface:
packages/shared/src/events/mock-bus.ts - Phase docs:
dev-docs/phase-1-widget-mockup.md(Sessions 1.4, 1.5)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

