WebRTC server #
Rubylight docs › Play together · Configuration · Features · Hardware matrix
Rubylight can stream over WebRTC to a Samsung Tizen TV or a browser, alongside the Moonlight protocol. The server is off by default. It speaks the Moonlight WebRTC TV protocol, version 2, which mlopezsegura designed for the Tizen TV app and the browser client. While it is off, no WebRTC socket is open and the Moonlight path is unchanged.
For users covers setup and use; For client authors covers Rubylight's behaviour and extensions to the protocol.
For users #
Turn it on #
- In the console, open All settings → Network and find the WebRTC group.
- Switch on WebRTC server.
- Save and restart Rubylight when the console asks; the setting takes effect after a restart.
Or open Stream in the browser under Advanced in the sidebar and press Turn on: it saves the setting and restarts Rubylight in one step, after asking first if a device is streaming.
If another program already holds a port, the console shows a webrtc_server warning, the log names the error and the server does not run. Rubylight never moves to another port on its own. Pick a free WebRTC signalling port or WebRTC media port instead.
Ports and firewall #
| What | Port | Setting |
|---|---|---|
| Discovery | UDP 8000, always | none |
| Signalling (WebSocket) | TCP 8000 | webrtc_port |
| Media, audio and input | UDP 8001 | webrtc_media_port |
| Guests of the console's stream | UDP 8002-8005 | webrtc_media_port + 1 to + 4 |
| The guest and play pages and their sockets | TCP 47991 | Base port + 2; the guest page answers only while an invite link works, the play page only the local network and Tailscale |
TVs send their discovery broadcast to UDP 8000, so discovery stays there even when you move the signalling port. The reply tells the TV which signalling port to use. The installer's Windows Firewall rule allows butterpollo.exe inbound on every port, so an installed host needs nothing more. On a portable host, allow these ports. The full list of settings is in Configuration.
Broadcasts do not cross routers. A TV on another subnet needs the PC's address entered by hand.
Pair a TV or a browser #
- Open the app on the TV or the browser client. It finds the PC, or you enter its address.
- The app shows a four-digit PIN.
- In the console, open Devices. The request appears with the device name and a WebRTC badge, next to any Moonlight requests.
- Enter the PIN there and confirm.
The app then holds a client ID and a secret and signs in with them from then on. The secret is stored in sunshine_state.json and is never shown in the console. A request lasts 5 minutes and allows one attempt.
The TV app and the browser client pair over the plain ws:// signalling port, which protocol version 2 does not encrypt: the secret crosses the network once, in the pairing reply, where a passive observer on the local network could read it. After that it never crosses the network again; the app proves it with a one-time challenge. The host log notes each device paired this way. Pair on a network you trust, and unpair a device on Devices if someone could have watched that exchange. The console's Stream page and the play page in a TV browser pair and sign in over the console's TLS ports (wss://) instead.
Stream in the console #
The console's Stream page plays a game from this PC in the browser tab, with no app and no pairing: AV1, HEVC or H.264 at any resolution and frame rate the host offers, stereo sound, keyboard and mouse.
- Turn on the WebRTC server (see above) and restart Rubylight.
- Open the console from a device on the local network or Tailscale, sign in, open Stream and click Connect.
- Pick a game. Click the picture to play: keys, the mouse and the scroll wheel go to the PC while the picture has focus, and when capture supports hardware cursor separation the browser draws your mouse pointer locally at your display's refresh rate. Click outside the picture, or press Ctrl+Alt+Shift+Z, to release focus; the mouse stays released until you click the picture again instead of snapping back on hover. Quit app ends the stream and the game, Disconnect only the stream.
The page signals over the console's own HTTPS port (wss://, at /api/webrtc/signal), so the WebRTC signalling port is not used, and it signs in with the console session. The browser streams as the device "Console (your user name)" on Devices; disable it there to stop the console from streaming. Signing out ends the stream within 5 seconds. One tab or browser holds the connection at a time: connecting from another one ends the stream in the first, which says so. The Picture panel lists only the codecs this browser receives over WebRTC (RTCRtpReceiver.getCapabilities) that the host also offers, with the resolutions and frame rates the host's encoder takes for each. The first time, the page picks a codec the browser decodes in hardware (Media Capabilities), AV1 first, then HEVC, then H.264, at 1080p and 60 fps or the nearest offered; it remembers your choice in the browser. In the project's tests Chromium and Firefox 159 offer AV1 and H.264; HEVC appears only where the browser has an H.265 receiver (see below). The page drops the host's a=imageattr line, which is there for Samsung's TVs, before handing the offer to the browser: Firefox refuses it ("Min is not smaller than max").
The browser does not say why the host refused the connection, so the page lists the causes (it asks you to sign in again when the tab's sign-in has lapsed): the tab is not signed in or opened the console from an address the host does not list as its own (csrf_allowed_origins), the device is not on the local network or Tailscale, the WebRTC server is off or was turned on without a restart, or the console device is disabled.
Once the offer is answered, the picture and sound travel over UDP webrtc_media_port, not over the console's port. If nothing comes back on it within 8 seconds, or the encrypted connection isn't up 30 seconds after the first answer, the page ends the attempt and says what it saw, with the address and port (what each message means).
A browser on the PC itself may open the console at 127.0.0.1 or localhost. Firefox makes no connection attempt to a loopback address, so on a host bound to all addresses the page is offered the PC's network address instead (the first hardware adapter's IPv4 address). With bind_address = 127.0.0.1 (or --bind 127.0.0.1) there is no other address to offer, and Firefox says so on the page. Such a stream doesn't turn off the monitors: an exclusive display layout, and ensure_only_display on a physical display, run as extended_primary, because the browser showing the stream is on one of them. The device doesn't learn that layout, and the log's stream display selection line says why it ran.
A reverse proxy or tunnel on the PC also connects from the PC, for a browser that may be anywhere, so such a request doesn't count as the PC's own and the configured layout stays. The host looks for Forwarded or X-Forwarded-*, a Host at another port than the one connected to (no port means 80 or 443), and a Host or Origin other than loopback, the address the connection reached, or the PC's own name (with or without .local). That covers nginx, cloudflared, tailscale serve, and ssh -L or netsh portproxy at another port or address. A forward that adds no header and that the browser opens at localhost on the same port, like ssh -L 47990:localhost:47990, can't be told apart: the monitors stay on, so what plays is visible at the PC. A browser on the PC that opens the console under a longer name, such as pc.tailnet.ts.net, counts as elsewhere, and an exclusive layout turns its monitors off.
Play in a TV browser #
A TV, console or car browser plays games from this PC with no app: it pairs once like a TV, then lists the PC's games and plays one full screen.
- Turn on the WebRTC server (see above) and restart Rubylight.
- In the browser, open
https://<PC address>:47991/play(the guest port, base port + 2). The browser warns that the connection is not private: the page uses the console's own self-signed certificate. Accept it once; the browser remembers it for this address. - The page shows a four-digit PIN and the name it pairs as, such as "Xbox" or "Edge on Windows". In the console, open Devices, enter the PIN there and confirm.
- Pick a game with the remote, the arrow keys or a controller (D-pad or left stick, A to start).
Hold Back, Escape or the controller's View (Select, Create, −) button for a second for the stream menu, a dock at the bottom of the picture: Back to game, Full screen, Sound, Stats, Disconnect (the game keeps running) and Quit game. With a mouse or a finger, move or tap once and click the handle that shows at the top edge. Stats shows a small capsule in the top right corner with the frame rate, the bitrate and the round trip the browser itself measures, and the codec and height it receives; the page asks the browser once a second and only while the capsule shows, and remembers the choice in its site data. The hints at the bottom name the buttons of the input last used (an Xbox, PlayStation or Nintendo pad, a keyboard or a TV remote); with touch or a mouse there are none. The chip at the top of the games picks the codec; the first time the page picks one as the Stream page does. Browsers allow sound and full screen only after a key press or a click, and a controller press does not count: if the game starts silent, press a key or click once.
The browser keeps its device ID and secret in its site data (localStorage), never in the address: clearing the site's data pairs it anew. It is a paired WebRTC device like a TV and gets what a TV gets: the first device paired with the PC may do everything, later ones only watch until you allow more on Devices. Unpairing or disabling it there ends its access at once. The page answers only devices on the local network and Tailscale; everyone else gets the same plain "not found" as any other path on the guest port. Only the connection's own address counts, never headers such as X-Forwarded-For. A 100.64.0.0/10 address is taken as Tailscale only when it reaches the PC's own Tailscale address, and a connection from the PC's default gateway is refused: a router that rewrites forwarded connections to its own address, or a carrier-grade NAT neighbour, would otherwise look local. Some setups still make an internet connection look local: a tunnel on the PC (Cloudflare Tunnel, ngrok), a reverse proxy, netsh portproxy, or a router that rewrites forwards to an address other than its gateway one (Guests in the browser). What protects you then is the pairing itself: nothing pairs until you type the PIN in the console, the console and the tray notice show the address each request came from before the name it chose, and a name that contains its own PIN, a digit other than 0-9, or an invisible format or line-break character is refused. That name check can't catch everything (Chinese numerals, letters that look like digits, a PIN spelled out in words), and the device picks its own PIN, so the address shown with the request is what tells you whose it is. Pair only a device you are holding, from the address you expect. Each device may ask to pair five times a minute, and a PIN that does not match is a warning in the host log.
Guests #
While you stream on the Stream page, Guests → Invite makes a link for up to four friends to watch in their own browsers, view only or with their controller, keyboard and mouse. Guests need no app, account or pairing, and connect straight to your PC with no relay. The PC encodes once for everyone, and a slow guest drops frames alone. Guests in the browser has the setup, the ports to forward, the certificate warning and the threat model.
The Devices page #
Paired TVs and browsers are listed on Devices with a WebRTC badge. Disable a device to keep it paired but refuse it. Unpair it to remove it. Either one disconnects the device at once, and ends its stream. At most 32 are kept; the oldest go first.
What streams #
| Part | What you get |
|---|---|
| Video | H.264, HEVC and AV1 at 720p, 1080p and 1440p; HEVC and AV1 also at 4K. AV1 appears only when the GPU's encoder supports it. 30, 60, 90 and 120 fps at every resolution, as far as the GPU's encoder can keep up (see below). |
| HDR | HEVC Main10 and AV1 10-bit at 1080p, 1440p and 4K. The host display must already be in HDR. If it is not, or it leaves HDR during the stream, the stream ends with an error. The host never tone-maps to SDR. |
| Audio | Stereo, 5.1 and 7.1. Surround needs a client that asks for it and decodes it; in practice, a Chromium-based browser. |
| Gamepad | Gamepads with rumble. |
| Gamepad as a mouse | Hold Start for 750 ms and release it. The stick moves the pointer, the D-pad scrolls, and A, B, X, LB and RB click. Do it again to turn it off. |
| Keyboard and mouse | From a client that opens the input channel (see below), such as the console's Stream page, /play and guest links, with zero-latency client-side cursor rendering on virtual displays and Desktop Duplication. The standalone browser client does not open input. |
The host reads how much its encoder can do (the throughput limit AMF or NVENC reports per codec) and offers only the frame rates it can encode in real time: a slower AMD GPU may list 4K at 30 and 60 only. A driver that reports no limit gets 60 fps and below. Measured clean on an RX 7900 XT: 90 and 120 fps at 1080p with all three codecs, 1440p120 with HEVC, and 4K120 with HEVC and AV1. Also offered where the encoder reports it can: 720p at 90 and 120, H.264 at 1440p above 60, AV1 at 1440p90 and 1440p120, 90 fps at 1440p and 4K, HDR above 60 fps, GPUs with a lower throughput limit, and drivers that report no limit.
A request for anything the host cannot send is refused with an error. There is no fallback: no SDR for an HDR request, no H.264 for AV1, no stereo for a surround request.
One stream runs at a time. A WebRTC stream and a Moonlight stream exclude each other, and a start that conflicts gets an error instead of taking over.
Network and safety #
Signalling is plain ws://, so it is not encrypted. Signing in keeps other devices from using or interrupting the stream; it does not hide what the app and the PC say to each other. The media itself is encrypted (DTLS-SRTP). Use it on a trusted LAN only.
Browsers let any page they show open a WebSocket to any address, so the signalling port checks which page opened it (its Origin) before it answers:
| Origin | Answer |
|---|---|
| None, as from the TV app's runtime or a program | Accepted; auth-required carries the PC's Wake-on-LAN address for the TV's reachability probe |
file:// or another scheme that is not http or https, as from a packaged TV app |
Accepted, as above |
A page on this PC or the local network: an address there (including Tailscale's 100.64.0.0/10), localhost, a name without a dot, a name ending in .local, .lan, .home.arpa, .internal or .localdomain, or the PC's own name |
Accepted; the Wake-on-LAN address comes only after signing in (gateway-status) |
https://openstreamco.github.io, where the protocol's browser client is published |
Accepted, as a page |
An entry of Trusted origins (csrf_allowed_origins) |
Accepted, as a page |
Any other page, and null (which a sandboxed frame of any site sends) |
Refused with 403 before the upgrade, with the reason in the reply and the host log |
A browser client served from elsewhere (your own domain, say) needs its origin, such as https://games.example.com, in Trusted origins.
Rubylight serves only peers on the local network: loopback, private (RFC 1918), link-local, unique-local IPv6 and carrier-grade NAT (100.64.0.0/10) addresses. Anything else is closed before its first message and logged. Do not forward these ports on your router. The one exception is guests of the console's stream, who may come from anywhere with a link: the guest port (TCP 47991, which serves nothing of the console's) and their media ports (UDP 8002-8005) may be forwarded (What must be reachable). The play page on the guest port still refuses every address outside the local network and Tailscale, and pairs only with the PIN you type in the console (Play in a TV browser). Never forward the console's port, TCP 47990.
For client authors #
Rubylight implements protocol version 2 as the upstream protocol document describes it: discovery, pairing, authentication, apps, start-session, switch-session, the stop messages and the host's offer. Read that for the messages. This part covers the host behaviour a client must handle and Rubylight's extensions. A stock client sees exactly protocol v2.
The host's offer #
The host sends the offer. It carries one video codec at a fixed payload type, one Opus audio track, and two DataChannels it creates itself:
| Label | Kind | Use |
|---|---|---|
control |
ordered, reliable | Host to client: JSON rumble and mouse-mode, plus binary 0x5541 cursor shapes and 0x5542 live cursor positions when requested. Client to host: request-keyframe and cursor-shape-request. |
gamepad |
unordered, no retransmits | Client to host: gamepad messages. |
The host is ICE-lite. Its local candidate is the address your connection reached plus webrtc_media_port (over loopback, on a host bound to all addresses, the PC's network address: see above). It uses no STUN or TURN server, accepts client trickle ICE candidate messages alongside connectivity checks, and holds a 12-second disconnect grace window (with fast ICE restart retries) so brief Wi-Fi drops or network handovers recover without ending the stream.
The host checks your answer. A changed codec or profile is an error, and the host never falls back to something else.
The video track offers NACK with RTX, so a lost packet is resent instead of costing a keyframe, and negotiates transport-wide congestion feedback (transport-cc) so the host adapts video bitrate smoothly on packet loss, NACKs or pacer backlog. The host paces its packets at a rate above the stream's bitrate and scales its UDP pacing batch ceiling to the stream's frame period so high-refresh streams spread packets evenly across each frame instead of bursting. The HEVC level-id and AV1 level-idx follow the mode, the rate and the bitrate (up to 5.2 for 4K120).
The host's control messages carry a v:
{"v":2,"type":"mouse-mode","controllerId":0,"controllerSlot":0,"active":true}
{"v":2,"type":"rumble","controllerId":0,"controllerSlot":0,"strongMagnitude":0.5,"weakMagnitude":0.25,"leftTrigger":0,"rightTrigger":0}
mouse-mode uses "v":2. Magnitudes are 0 to 1.
Keyframes and logs #
A client may ask for a keyframe on the control channel, besides an RTCP PLI or FIR. All three set the same request on the host:
{"type":"request-keyframe"}
client-log is a signalling message, not a DataChannel message. It travels on the WebSocket like any other protocol message, and carries at most 100 lines. The host writes them to its debug log. The first line of a session that starts with connection failed: goes in the default log as a warning instead, so a report of why the peer connection failed reaches a log users send in; the host limits how often such lines are logged across all connections.
{"version":2,"type":"client-log","lines":["decoder reset","frame 1024 late"]}
The extensions object #
capabilities carries an extensions object. Stock clients ignore it. It reads:
"extensions": {
"audioChannels": [2, 6, 8],
"input": {"label": "input", "version": 1, "keyboard": true, "mouse": true},
"codecFrameRates": [
{"width": 1280, "height": 720, "codec": "h264", "frameRates": [30, 60, 90, 120]},
...
]
}
audioChannelslists the channel countsstart-sessionaccepts inaudio.channels.inputsays the host accepts a client-opened DataChannel with that label.keyboardandmousesay what it carries.codecFrameRateslists, for each mode and codec, the frame rates that codec takes on this host's encoder. AvideoModesentry lists only the rates every one of its codecs takes, so any listed rate works with any listed codec. When the encoder's limits differ by codec, a codec may take more rates than its mode lists, or a codec that cannot take 60 fps at a mode may be left out of the mode and appear only here. The host accepts every pair listed here.
version stays 2. An extension is used only when the client asks for it: a 6 or 8 for audio.channels, an input channel, or a rate from codecFrameRates.
Surround audio #
The host always offers standard opus/48000/2 with stereo=1. When start-session asks for 6 or 8 channels, the host sends the audio as Opus multistream. Chromium refuses multiopus in a remote offer, so the client puts it in its own answer:
- Ask for
"audio":{"channels":6}or8. - Set the remote offer, then create the answer.
- Rewrite the answer's audio
a=rtpmaptomultiopus/48000/Nand set itsa=fmtpto libwebrtc's canonical layout:
| Channels | num_streams |
coupled_streams |
channel_mapping |
|---|---|---|---|
| 6 (5.1) | 4 | 2 | 0,4,1,2,3,5 |
| 8 (7.1) | 5 | 3 | 0,6,1,2,3,4,5,7 |
For 5.1 the audio lines of the answer then read like this:
a=rtpmap:111 multiopus/48000/6
a=fmtp:111 channel_mapping=0,4,1,2,3,5;num_streams=4;coupled_streams=2;minptime=10;useinbandfec=1
- Set that as the local description. The payload type is the one in the offer (currently 111). The
minptimeanduseinbandfecvalues are yours to choose.
The host takes the stream count, coupled count and mapping from your answer when they are valid for the channel count, and encodes with exactly that layout. A changed channel count or an invalid layout is an error.
A stereo answer to a surround request is refused with an error, never downgraded to a stereo stream. Only receivers that decode multiopus can use surround. Chromium-based browsers do; surround on the Tizen TV app has not been tested.
Stereo in Chromium #
Chromium decodes Opus as mono unless its own answer's fmtp has stereo=1. Add stereo=1 to the audio a=fmtp line of your answer.
Browser support for video #
In the project's tests, Chrome 155 receives H.265 (the harness starts it with --enable-features=WebRtcAllowH265Receive) and Edge 155 has no H.265 receiver. A client that asks for HEVC on a browser without a receiver gets no picture. Check RTCRtpReceiver.getCapabilities('video') before you ask.
The input channel #
For keyboard and mouse, open a DataChannel labelled input after you have signed in. It must be ordered and reliable. The host accepts one, and closes a channel with any other unknown label, or an input channel that is unordered or unreliable.
Send each message as a text frame of JSON with "v":1. Binary frames are dropped. A message the host cannot parse is dropped and logged.
| Message | Example | Notes |
|---|---|---|
| Key | {"v":1,"type":"key","code":"KeyA","down":true} |
code is the DOM KeyboardEvent.code. Modifiers are ordinary keys. An unknown code is dropped and counted in the stream summary. |
| Text | {"v":1,"type":"text","text":"é"} |
At most 32 characters per message. For input method output and characters with no key. |
| Relative move | {"v":1,"type":"mouse-move","dx":-3,"dy":5} |
Pixels, for pointer lock. Clamped to 16-bit values. |
| Absolute move | {"v":1,"type":"mouse-position","x":0.5,"y":0.25} |
A fraction of the video, clamped to 0 to 1. |
| Button | {"v":1,"type":"mouse-button","button":0,"down":true} |
DOM button numbers 0 to 4: left, middle, right, back, forward. |
| Wheel | {"v":1,"type":"wheel","dx":0,"dy":120} |
120 units per notch, with DOM signs: a positive dy scrolls down. |
The device's permissions on the Devices page gate keyboard and mouse input as they do for Moonlight. A guest of the console's stream gets the input channel only with an invite for keyboard and mouse, and its input is checked against both the invite and the console device's permissions (Guests in the browser). When the channel closes, the stream stops or the session switches, the host releases every key and button it holds for you, so nothing stays pressed. On the built-in WebRTC Stream, Guest and /play pages, pressing Ctrl+Alt+Shift+Z or clicking outside the video keeps mouse and wheel input released until you click the video again.
Client-side cursor #
When capture supports hardware cursor separation (Rubylight's virtual display driver idd-push / auto, or Desktop Duplication) and client_cursor is enabled, a WebRTC client can opt into zero-latency client-side cursor rendering by sending a JSON text message on control:
{"type":"cursor-shape-request","enabled":true,"wantPosition":true}
The host then streams binary frames over the control channel (with a 1 MiB SCTP send buffer): each frame starts with a 2-byte little-endian message type (0x5541 for cursor shape with up to 96×96 RGBA pixels and a 32-entry LRU image cache, or 0x5542 for normalized live cursor position and visibility) followed by the same rubylight_protocol::cursor_shape payload used over Moonlight (Control messages). Late-joining guests receive the current cursor shape immediately when they opt in. Clients that do not send cursor-shape-request, or streams without hardware cursor separation, keep the OS cursor in the video.
Gamepads #
Gamepad messages (gamepad-connected, gamepad-state, gamepad-disconnected) follow the upstream protocol and the TV app. Send them on the gamepad channel with "v":2; the host accepts "v":1 too. A client may also announce its pads on control. Every pad is announced to the PC as an Xbox pad. Holding Start for 750 ms and releasing it toggles mouse mode for that pad, as described above, and the host reports the change with mouse-mode.