Skip to content

webcam (go2rtc) disconnects regularly in safari on macos #2183

@mmerickel

Description

@mmerickel

Mainsail Version:

2.13.2

Browser:

Safari

Device:

Laptop

Operating System:

macOS

What happened?

Added webcam (go2rtc) integration to my local go2rtc instance hosted by home assistant/frigate.

Stream URL: http://hass.local:1984?cam=ender3pro_cam
Snapshot URL: http://hass.local:1984/api/frame.jpeg?cam=ender3pro_cam

This stream works fine except that there is a blip every 40-ish seconds it disconnects and reconnects the stream.

[Log] [WebRTC go2rtc] connecting to ws://hass.local:1984/api/ws?src=ender3pro_cam&media=video (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] open (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] connection state changed – "connecting" (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] connection state changed – "connected" (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] connection state changed – "disconnected" (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] terminating (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] close (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] connecting to ws://hass.local:1984/api/ws?src=ender3pro_cam&media=video (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] open (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] connection state changed – "connecting" (WebrtcGo2rtc-2a46754e.js, line 1)
[Log] [WebRTC go2rtc] connection state changed – "connected" (WebrtcGo2rtc-2a46754e.js, line 1)

The time between the "connected" and "disconnected" lines is consistently about 40 seconds.

What did you expect to happen instead?

no blip - solid stream like on Chrome

How to reproduce this bug?

I'm using Safari Version 18.4 (20621.1.15.11.10) on macOS 15.4. This issue does not occur when I use Chrome Version 135.0.7049.85 (Official Build) (arm64) and appears to be specific to Safari in my testing. I have also reproduced this issue using Safari on iOS.

Additional information:

I spent some time trying to debug this and as I said above this appears to be specific to Safari as I've had my Chrome tab open for 20 minutes without any issue, no drops / reconnects. With or without the STUN config change I mention below - Chrome is rock solid.

I googled around about webrtc connections dropping after 40 seconds and uncovered some comments about Safari, mostly on iOS, having issues with ICE server config / connections and manifesting in similar timeouts. With that in mind I tweaked the javascript to comment out the default iceServers config here:

iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
and it actually did make a big difference but didn't fully fix the issue. With the STUN server removed it changed the behavior (consistently) such that the initial connection would remain open for 6-7 minutes. After this time it would disconnect and then reconnect every 40 seconds or so similarly to before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions