{"record":{"id":"ceb39342d2d41ef8","repo":"AlexxIT/go2rtc","slug":"add-track-not-supported-for-snapshot","errorCode":null,"errorMessage":"add track not supported for snapshot","messagePattern":"add track not supported for snapshot","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/ring/client.go","lineNumber":328,"sourceCode":"}\n\nfunc (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {\n\treturn c.prod.GetTrack(media, codec)\n}\n\nfunc (c *Client) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {\n\tif webrtcProd, ok := c.prod.(*webrtc.Conn); ok {\n\t\tif media.Kind == core.KindAudio {\n\t\t\t// Enable speaker\n\t\t\tspeakerPayload := map[string]interface{}{\n\t\t\t\t\"stealth_mode\": false,\n\t\t\t}\n\t\t\t_ = c.wsClient.sendSessionMessage(\"camera_options\", speakerPayload)\n\t\t}\n\t\treturn webrtcProd.AddTrack(media, codec, track)\n\t}\n\n\treturn fmt.Errorf(\"add track not supported for snapshot\")\n}\n\nfunc (c *Client) Start() error {\n\treturn c.prod.Start()\n}\n\nfunc (c *Client) Stop() error {\n\tif c.closed {\n\t\treturn nil\n\t}\n\n\tc.closed = true\n\n\tif c.prod != nil {\n\t\t_ = c.prod.Stop()\n\t}\n\n\tif c.wsClient != nil {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/ring/client.go#L310-L346","documentation":"Client.AddTrack only supports adding media tracks to a WebRTC (live-stream) session via the underlying production client. When the client was created for a snapshot session, no WebRTC track machinery exists, so the call fails with this sentinel error. It signals an API misuse: tracks are meaningless for a single still image.","triggerScenarios":"Calling AddTrack on a ring Client that was created in snapshot mode (e.g. via a snapshot/live-switch configuration) instead of a live WebRTC session.","commonSituations":"Reusing one Client for both snapshot capture and live streaming; code paths that unconditionally call AddTrack without checking whether the session is a snapshot; an upstream pipeline that always attaches audio/video tracks.","solutions":["Create a live-stream (WebRTC) client/session instead of a snapshot client before calling AddTrack.","If you only need a still image, drop the AddTrack call and use the snapshot API directly.","Check the session mode before adding tracks and branch your code accordingly."],"exampleFix":"// before\nsnapClient := ring.NewSnapshotClient(...)\nsnapClient.AddTrack(media, codec, track) // fails\n// after\nliveClient, _ := ring.Dial(ctx, cameraID, token) // WebRTC/live session\nliveClient.AddTrack(media, codec, track)","handlingStrategy":"validation","validationCode":"if isSnapshotSession(client) {\n    return errors.New(\"AddTrack requires a live WebRTC session, not a snapshot client\")\n}","typeGuard":null,"tryCatchPattern":"if err := client.AddTrack(media, codec, track); err != nil {\n    if err.Error() == \"add track not supported for snapshot\" {\n        // fall back to snapshot capture instead of live streaming\n    }\n    return err\n}","preventionTips":["Keep snapshot and live-stream clients separate; never reuse one for both.","Check session mode before attaching media tracks.","Document at call sites whether a given client is snapshot or live."],"tags":["ring","webrtc","snapshot","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}