Install the mediasoup npm package (requires Node.js and build tools for the C++ worker); import mediasoup and call mediasoup.createWorker() with rtcMinPort and rtcMaxPort matching your open firewall range.
On the created Worker, call worker.createRouter({ mediaCodecs }) passing an array of codec capability objects (e.g., VP8, opus) to create a Router that all participants in one room will share.
For each participant, call router.createWebRtcTransport({ listenIps, enableUdp, enableTcp, preferUdp }) — listenIps should include your server's announced IP — and send the returned id, iceParameters, iceCandidates, and dtlsParameters back to the client via your signaling channel.
The client calls device.load({ routerRtpCapabilities }) then creates its own send/recv transports and signals the DTLS role back; call serverTransport.connect({ dtlsParameters }) on the server side to complete the DTLS handshake.
For publishing, the client signals produce intent; call transport.produce({ kind, rtpParameters }) on the server and return the new producerId to the client.
For subscribing, call router.canConsume({ producerId, rtpCapabilities }) then transport.consume({ producerId, rtpCapabilities, paused: true }), send consumer parameters to the client, and let the client resume after rendering.
Known gotchas
Each mediasoup Worker runs a single C++ subprocess; spawn one Worker per CPU core and distribute Routers across them — running a large room on a single Worker saturates one core.
The announced IP in listenIps must be the server's public IP or NAT-mapped address; using 0.0.0.0 without an announcedIp causes ICE candidates that are unreachable from outside.
Consumers start paused by default; failing to call consumer.resume() on the server or resumeConsumer on the client results in no media flowing even after a successful handshake.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp