AlexxIT/go2rtc · error

wrong answer:

Error message

wrong answer: 

What it means

go2rtcClient expects the first JSON message on the go2rtc WS signaling channel to have type "webrtc/answer"; anything else (typically "webrtc/error") aborts with this error including the message payload.

Solutions

  1. Check the exact msg content after "wrong answer: " — if it says the source is not found, fix the src name
  2. Verify the stream exists and is online on the remote go2rtc instance (check its web UI/API)
  3. Ensure the WS endpoint is actually a go2rtc /api/ws signaling endpoint, not another service
  4. Test the same src with a simpler consumer (e.g. HLS) to confirm the source works

Example fix

// before
const ws = new WebSocket("ws://host:1984/api/ws?src=camra1");
// after
const ws = new WebSocket("ws://host:1984/api/ws?src=camera1");
Defensive patterns

Strategy: try-catch

Try / catch

prod, err := go2rtcClient(url)
if err != nil && strings.HasPrefix(err.Error(), "wrong answer: ") {
	log.Printf("go2rtc signaling rejected: %s", strings.TrimPrefix(err.Error(), "wrong answer: "))
	// verify src exists on remote go2rtc before reconnecting
}

Prevention

When it happens

Trigger: Connecting to a go2rtc server where the src name is unknown/invalid, the source stream is not running, or the server sends an error response instead of the SDP answer.

Common situations: Stream name typo in the ws URL (?src=name); the target stream isn't defined or failed to start on the remote go2rtc; pointing at a non-go2rtc WS endpoint that replies with a different protocol message.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/45e03c5c450c8f5e. Report an issue: GitHub.

Appendix: source

Thrown at internal/webrtc/client.go:145

	// 3. Create offer
	offer, err := prod.CreateOffer(medias)
	if err != nil {
		return nil, err
	}

	// 4. Send offer
	msg := &ws.Message{Type: "webrtc/offer", Value: offer}
	connMu.Lock()
	_ = conn.WriteJSON(msg)
	connMu.Unlock()

	// 5. Get answer
	if err = conn.ReadJSON(msg); err != nil {
		return nil, err
	}

	if msg.Type != "webrtc/answer" {
		err = errors.New("wrong answer: " + msg.String())
		return nil, err
	}

	answer := msg.String()
	if err = prod.SetAnswer(answer); err != nil {
		return nil, err
	}

	// 6. Continue to receiving candidates
	go func() {
		var err error

		for {
			// receive data from remote
			var msg ws.Message
			if err = conn.ReadJSON(&msg); err != nil {
				break
			}

View on GitHub (pinned to c245815e75)