AlexxIT/go2rtc · error
add track not supported for snapshot
Error message
add track not supported for snapshot
What it means
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.
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.
Example fix
// before snapClient := ring.NewSnapshotClient(...) snapClient.AddTrack(media, codec, track) // fails // after liveClient, _ := ring.Dial(ctx, cameraID, token) // WebRTC/live session liveClient.AddTrack(media, codec, track)
Defensive patterns
Strategy: validation
Validate before calling
if isSnapshotSession(client) {
return errors.New("AddTrack requires a live WebRTC session, not a snapshot client")
} Try / catch
if err := client.AddTrack(media, codec, track); err != nil {
if err.Error() == "add track not supported for snapshot" {
// fall back to snapshot capture instead of live streaming
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/ceb39342d2d41ef8.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/ring/client.go:328
}
func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
return c.prod.GetTrack(media, codec)
}
func (c *Client) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
if webrtcProd, ok := c.prod.(*webrtc.Conn); ok {
if media.Kind == core.KindAudio {
// Enable speaker
speakerPayload := map[string]interface{}{
"stealth_mode": false,
}
_ = c.wsClient.sendSessionMessage("camera_options", speakerPayload)
}
return webrtcProd.AddTrack(media, codec, track)
}
return fmt.Errorf("add track not supported for snapshot")
}
func (c *Client) Start() error {
return c.prod.Start()
}
func (c *Client) Stop() error {
if c.closed {
return nil
}
c.closed = true
if c.prod != nil {
_ = c.prod.Stop()
}
if c.wsClient != nil {View on GitHub (pinned to c245815e75)