askrobots / network-computer
Public
Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.
Dan Quellhorst
Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353)
a1d92f3
1 month, 3 weeks ago
History
proto.go · 3.8 KB · 71 lines
| 1 | // Package proto defines the signaling messages exchanged through nc-rendezvous |
| 2 | // and the input events carried on the WebRTC data channel. |
| 3 | package proto |
| 4 | |
| 5 | import "encoding/json" |
| 6 | |
| 7 | // Message is the envelope for everything that crosses the signaling WebSocket. |
| 8 | // The rendezvous only looks at Type, To and Name; it fills in From. |
| 9 | type Message struct { |
| 10 | Type string `json:"type"` // register, hosts, offer, answer, ice, error |
| 11 | Name string `json:"name,omitempty"` // register: host name |
| 12 | To string `json:"to,omitempty"` // routing target: host name or client id |
| 13 | From string `json:"from,omitempty"` // filled by the rendezvous |
| 14 | |
| 15 | SDP string `json:"sdp,omitempty"` // offer / answer |
| 16 | PIN string `json:"pin,omitempty"` // offer: the host PIN the client was given |
| 17 | Pair string `json:"pair,omitempty"` // offer: a pairing token instead of the PIN; answer: a fresh one |
| 18 | Candidate json.RawMessage `json:"candidate,omitempty"` // ice: RTCIceCandidateInit as JSON |
| 19 | Hosts []string `json:"hosts,omitempty"` // hosts reply |
| 20 | Error string `json:"error,omitempty"` |
| 21 | } |
| 22 | |
| 23 | // ICEServer mirrors the browser's RTCIceServer shape so /config can be fed |
| 24 | // straight into a RTCPeerConnection and into Pion. |
| 25 | type ICEServer struct { |
| 26 | URLs []string `json:"urls"` |
| 27 | Username string `json:"username,omitempty"` |
| 28 | Credential string `json:"credential,omitempty"` |
| 29 | } |
| 30 | |
| 31 | // Config is what GET /config returns. Mode is "secure" (signaling over TLS) |
| 32 | // or "insecure" (plain HTTP) so clients can show which posture they are in. |
| 33 | type Config struct { |
| 34 | ICEServers []ICEServer `json:"iceServers"` |
| 35 | Mode string `json:"mode,omitempty"` |
| 36 | } |
| 37 | |
| 38 | // InputEvent is one message on the "input" data channel. JSON for the spike; |
| 39 | // a packed binary form comes later. Coordinates are normalised 0..1 across the |
| 40 | // captured display so the client never needs to know the host resolution. |
| 41 | type InputEvent struct { |
| 42 | T string `json:"t"` // mm, mr, md, mu, wh, kd, ku, display, keyboard, clip, clipget, clipnow, clipnone, launch, voice, tz |
| 43 | X float64 `json:"x,omitempty"` // mm: absolute normalised position (md/mu too, with At) |
| 44 | Y float64 `json:"y,omitempty"` // |
| 45 | DX float64 `json:"dx,omitempty"` // mr: relative move in pixels; wh: scroll delta in pixels |
| 46 | DY float64 `json:"dy,omitempty"` // |
| 47 | B int `json:"b,omitempty"` // md/mu: 0 left, 1 middle, 2 right |
| 48 | // md/mu: X,Y say where the press happened. Moves travel on an unordered |
| 49 | // channel and can arrive after the press; the host moves there first. |
| 50 | At bool `json:"at,omitempty"` |
| 51 | Code string `json:"code,omitempty"` // kd/ku: KeyboardEvent.code, e.g. "KeyA" |
| 52 | W int `json:"w,omitempty"` // display: requested screen width in pixels |
| 53 | H int `json:"h,omitempty"` // display: requested screen height |
| 54 | S float64 `json:"s,omitempty"` // display: UI scale, 1 = 100% |
| 55 | // keyboard: the client's layout, e.g. "us", "us:dvorak". Keys travel as |
| 56 | // physical positions, so the host must turn them into characters with the |
| 57 | // same layout the client uses. |
| 58 | Layout string `json:"layout,omitempty"` |
| 59 | // clip: clipboard text, in pieces; More is set on every piece but the last. |
| 60 | Text string `json:"text,omitempty"` |
| 61 | More bool `json:"more,omitempty"` |
| 62 | // voice: On starts or stops listening (client to host); Kind says what an |
| 63 | // event from the desk is: state, heard, said, did, error. input (client to |
| 64 | // host): Kind is "touch" or "pointer", what the person is using. |
| 65 | On bool `json:"on,omitempty"` |
| 66 | Once bool `json:"once,omitempty"` // voice: stop listening after one phrase |
| 67 | Kind string `json:"kind,omitempty"` |
| 68 | // input (client to host): Device is "phone", "tablet" or "desktop", the |
| 69 | // kind of screen and hands the person has, next to Kind (touch/pointer). |
| 70 | Device string `json:"device,omitempty"` |
| 71 | } |