AlexxIT/go2rtc · error
failed to send codec request
Error message
failed to send codec request: %w
What it means
On WebRTC datachannel open, the JSON 'codec' request could not be sent to Tuya's datachannel (sendMessageToDataChannel failed), so the client is closed with this wrapped error — codec negotiation cannot begin. Wraps the send error.
Solutions
- Retry the connection; transient data channel setup races can cause this
- Verify WebRTC/DTLS connectivity to the Tuya cloud
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at pkg/tuya/client.go:262 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/d595dafeac844781.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/tuya/client.go:262
// fmt.Printf("tuya: datachannel error: %s\n", err.Error())
client.Close(err)
})
client.dc.OnClose(func() {
// fmt.Println("tuya: datachannel closed")
client.Close(errors.New("datachannel: closed"))
})
client.dc.OnOpen(func() {
// fmt.Println("tuya: datachannel opened")
codecRequest, _ := json.Marshal(DataChannelMessage{
Type: "codec",
Msg: "",
})
if err := client.sendMessageToDataChannel(codecRequest); err != nil {
client.Close(fmt.Errorf("failed to send codec request: %w", err))
}
})
}
// Set up pc handler
client.conn.Listen(func(msg any) {
switch msg := msg.(type) {
case *pion.ICECandidate:
_ = sendOffer.Wait()
if err := mqttClient.SendCandidate("a=" + msg.ToJSON().Candidate); err != nil {
client.Close(err)
}
case pion.PeerConnectionState:
switch msg {
case pion.PeerConnectionStateNew:
break
case pion.PeerConnectionStateConnecting:View on GitHub (pinned to c245815e75)