Files
google-nest-sdm-local/Notes.MD
T3vl 2061dd1f4b Main Commit
Added All Base Files, Fork the Scrypted Repo And Paste!
2024-09-15 15:26:50 -05:00

10 lines
2.6 KiB
Markdown

# Notes on How Scrypted Handles WebRTC "Cloud" Cameras (Starling is local:)
When I orignially wrote this plugin I had planned to make a camera with a seperate WebRTC NPM package, but Scrypted Makes using WebRTC cameras A LOT easier because of the built-in WebRTC plugin.
How you add a WebRTC camera is all your plugin really needs to is the handshake between the "Camera" and the "WebRTC" plugin for it to stream and work with Scrypted. I will explain how I did it below:
WebRTC requires a "offerSdp", which you send to the camera, and then the camera returns an "AnswerSdp" and due to the way Google/Starling designed this call only one API call is actually needed for all of this, the same API call also provides the "StreamId" which is then used to actually pull the stream over the WebRTC protocol.
How I did this with the Starling Home Hub, which is **very** similar to Google's (sh*t) official SDM API, is your browser, or in this case, Scrypted WebRTC plugin generates a offerSdp with the parameters of sending AND receiving Audio, and only receiving video, so "sendrecv" for audio, and "recvonly" for video (you can see it in the "startRTCSignalingSession" function). Once this offerSdp is generated we then encode it to Base64 as Nest Cams, and therefore Starling Require it to be in Base 64 (this is to make sending the Sdp easier), to send this Sdp we use the .../stream?key POST endpoint.
Once we send that POST request the camera will (starling) will respond with a StreamId, and the answerSdp. The offerSdp is used to tell the camera what video/audio parameters the client supports/ is requesting, where the answerSdp is telling the client what the camera supports/ what "its getting" (what the camera is sending). Since the Nest Cam will send it in Base64 encoding and the WebRTC plugin needs it to be in plain text we decode the Base64 and then the WebRTC plugin uses the StreamId along with the AnswerSdp and plays the camera stream to Scrypted NVR, or a HomeKit client etc.
Since these StreamId's expire we need to renew them using the .../streamId/extend?key= POST request, we do this every minute to keep the Stream stable and continuous, and once we are done streaming from the camera, we use the .../streamId/stop?key= to terminate the StreamId (we make a new one for every new stream). As an example if NVR is streaming (recording) with one StreamId, it will be renewed every minute, and if a HomeKit client starts streaming the camera too, the NVR StreamId will not be touched, it will continue recording like normal. A new StreamId will be generated for the HomeKit client and renewed until the client disconnects, where then it will terminate the StreamId.