Add WebRTC signalling to the edge protocol
A browser cannot signal to a gateway's go2rtc directly. Measured against go2rtc 1.9.14: it sends no Access-Control-Allow-Origin on any response, the SDP POST needs a preflight anyway because application/sdp is not a CORS-safelisted content type, and it checks its API password before CORS - so the preflight, which a browser always sends without credentials, gets a 401. A gateway is behind a workshop NAT besides, so nothing can dial in. So the cloud relays the SDP exchange over the socket the gateway already holds open: webrtc_offer down, webrtc_answer or webrtc_error back up. Signalling only - no video on this socket, and that is the design rather than a limitation of it. Media goes browser-to-gateway through a TURN relay, DTLS-SRTP encrypted, so neither the backend nor the relay can read it. The alternative was tunnelling fMP4 up this socket and streaming it from the API, which would have meant plaintext video through the cloud and - since <video> cannot send an Authorization header - a credential in a URL, the pattern /ws/telemetry rejected. webrtc_error is its own variant rather than an empty answer because the cloud holds a browser's request open on this, and a silent failure there is a viewer watching a video element that never loads.
This commit is contained in:
@@ -140,6 +140,48 @@
|
||||
"printer_id",
|
||||
"frames"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"title": "WebrtcAnswer",
|
||||
"description": "go2rtc's answer SDP for a WebrtcOffer, passed through verbatim.",
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "webrtc_answer"
|
||||
},
|
||||
"session_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"sdp": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"session_id",
|
||||
"sdp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"title": "WebrtcError",
|
||||
"description": "The gateway could not get an answer: no such camera, go2rtc not running, or it refused the offer. A variant of its own rather than an empty answer, so the viewer is told something instead of watching a video element that never loads.",
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "webrtc_error"
|
||||
},
|
||||
"session_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"session_id",
|
||||
"message"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user