rob-revisited/extensions/webrtc/doc/sidecar.md

2.4 KiB

The WebRTC sidecar protocol

bin/webrtc-gst.py (desktop) and the engine page module jumphp-webrtc.js (browser) speak the same protocol: one JSON object per line (sidecar: stdin / stdout; browser: JsBridge messages of type webrtc). JumPHP\WebRtc\Sidecar (no engine dependency) runs the sidecar and is also used by the JumPHP IDE (ide/src/Remote/ScreenHost.php).

Commands (op):

op fields
peer id, stun (stun://host:port or stun:host:port), turn (turn://user:pass@host:port) a new peer (an existing id is replaced)
channel id, label, ordered (bool), retransmits (int) a data channel (before offer)
screen id, fps, kbps, width (0 = full size), display, encoder (auto, x264, openh264, va, va2, vaapi, nvenc), input (bool) desktop only: the screen as an H.264 track (+ the input channel)
offer id makes the offer (event offer)
remote id, type (offer/answer), sdp the other side's description (an offer is answered: event answer)
ice id, candidate, mline the other side's ICE candidate (kept until the remote description is set)
send id, label, text or b64 a message on a channel
kbps / key id (kbps) screen bitrate / a key frame now
close / quit id / —

Events (ev): ready {version, encoders, gstreamer}, building (Docker image being built), offer / answer {id, sdp}, ice {id, candidate, mline}, state {id, state}, open / close {id, label}, message {id, label, text | b64}, screen {id, encoder, width, height}, error {id?, message, fatal?}, exit (the sidecar stopped).

The input channel of a screen peer (JSON messages, handled by the sidecar itself, never by PHP: latency): m {x, y: 0..1 of the screen} move, r {dx, dy pixels} relative move, b {b: 1 left | 2 middle | 3 right, d: down, x?, y?}, w {dy, dx: notches}, k {key: X keysym name (Return, Control_L, F5...) or one character, d}, txt {s: text, any Unicode}, kbps {kbps}, key (key frame), ping {at} -> pong {at}. The sidecar sends size {w, h, encoder} when the channel opens.

Pipeline (screen): ximagesrc ! queue leaky ! [videoscale] ! convert ! H.264 encoder (no B-frames, GOP 2 s) ! h264parse (au) ! rtph264pay (zero-latency aggregation, MTU 1200) ! webrtcbin (latency 0, max-bundle). The viewer should set receiver.jitterBufferTarget = 0.