bitsy-ai / printnanny-os

Image repository, change logs, and issue tracking for PrintNanny OS
GNU Affero General Public License v3.0
23 stars 2 forks source link

WebRTC stream fails to load in Firefox #281

Open leigh-johnson opened 1 year ago

leigh-johnson commented 1 year ago

Describe the bug

WebRTC stream is failing to load using the following Firefox build:

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0

https://github.com/webrtcHacks/adapter

leigh-johnson commented 1 year ago

💥 Looks like we weren't using https://www.npmjs.com/package/webrtc-adapter in the Mission Control dash. Installing this shim now, then testing Firefox 🤞

leigh-johnson commented 1 year ago

Running Firefox 110.0 on MacOS, reproduced the original issue and seeing the following error:

Screenshot 2023-02-25 at 1 33 53 PM

Interestingly, WebRTC adapter reports:

WebRTC adaptor detected browser:  Not a supported browser. [logging.ts:28:17](http://travelpi.local/src/utils/logging.ts)
WebRTC adaptor detected version:  null [logging.ts:28:17](http://travelpi.local/src/utils/logging.ts)
leigh-johnson commented 1 year ago

Switching out the janode library for the official janus-gateway client library. The janode library is a bit behind (no multistream support) and I have a hunch the WebRTC adapter isn't getting initialized correctly when using janode.

leigh-johnson commented 1 year ago

Offer SDP

Working offer received in Chrome:

{type: 'offer', sdp: 'v=0\r\no=- 1677496298204612 1 IN IP4 46.8.174.74\r\ns=… 192.168.18.69 rport 35719\r\na=end-of-candidates\r\n'}
sdp
: 
"v=0\r\no=- 1677496298204612 1 IN IP4 46.8.174.74\r\ns=Mountpoint 1\r\nt=0 0\r\na=group:BUNDLE v1 v2\r\na=ice-options:trickle\r\na=fingerprint:sha-256 76:D9:AB:68:5E:F3:43:1D:AB:2D:3C:09:56:EB:E8:CA:54:EE:71:82:9C:0B:71:39:A9:79:BD:43:F7:B4:37:F6\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS *\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\nc=IN IP4 46.8.174.74\r\na=sendonly\r\na=mid:v1\r\na=rtcp-mux\r\na=ice-ufrag:B6aY\r\na=ice-pwd:9nOaaQQEPqV4+JPJRJfTg+\r\na=ice-options:trickle\r\na=setup:actpass\r\na=rtpmap:96 H264/90000\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=ssrc-group:FID 1443480017 2888513131\r\na=msid:janus janusv1\r\na=ssrc:1443480017 cname:janus\r\na=ssrc:2888513131 cname:janus\r\na=candidate:1 1 udp 2015363327 192.168.18.69 35719 typ host\r\na=candidate:2 1 udp 2015363583 fe80::ff27:4fa7:fa4d:848d 34505 typ host\r\na=candidate:3 1 udp 2015363839 fe80::dea6:32ff:feb0:65d 47357 typ host\r\na=candidate:4 1 udp 1679819007 46.8.174.74 50469 typ srflx raddr 192.168.18.69 rport 35719\r\na=end-of-candidates\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\nc=IN IP4 46.8.174.74\r\na=sendonly\r\na=mid:v2\r\na=rtcp-mux\r\na=ice-ufrag:B6aY\r\na=ice-pwd:9nOaaQQEPqV4+JPJRJfTg+\r\na=ice-options:trickle\r\na=setup:actpass\r\na=rtpmap:96 H264/90000\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=ssrc-group:FID 2261799486 1785232526\r\na=msid:janus janusv2\r\na=ssrc:2261799486 cname:janus\r\na=ssrc:1785232526 cname:janus\r\na=candidate:1 1 udp 2015363327 192.168.18.69 35719 typ host\r\na=candidate:2 1 udp 2015363583 fe80::ff27:4fa7:fa4d:848d 34505 typ host\r\na=candidate:3 1 udp 2015363839 fe80::dea6:32ff:feb0:65d 47357 typ host\r\na=candidate:4 1 udp 1679819007 46.8.174.74 50469 typ srflx raddr 192.168.18.69 rport 35719\r\na=end-of-candidates\r\n"
type
: 
"offer"
[[Prototype]]
: 
Object

Offer received in Firefox:

Handling SDP:  
Object { type: "offer", sdp: "v=0\r\no=- 1677496062519229 1 IN IP4 46.8.174.74\r\ns=Mountpoint 1\r\nt=0 0\r\na=group:BUNDLE v1 v2\r\na=ice-options:trickle\r\na=fingerprint:sha-256 76:D9:AB:68:5E:F3:43:1D:AB:2D:3C:09:56:EB:E8:CA:54:EE:71:82:9C:0B:71:39:A9:79:BD:43:F7:B4:37:F6\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS *\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\nc=IN IP4 46.8.174.74\r\na=sendonly\r\na=mid:v1\r\na=rtcp-mux\r\na=ice-ufrag:V1hB\r\na=ice-pwd:MaEwrvKGHi0aoxWBmvH/NG\r\na=ice-options:trickle\r\na=setup:actpass\r\na=rtpmap:96 H264/90000\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=ssrc-group:FID 541163871 2027188442\r\na=msid:janus janusv1\r\na=ssrc:541163871 cname:janus\r\na=ssrc:2027188442 cname:janus\r\na=candidate:1 1 udp 2015363327 192.168.18.69 60676 typ host\r\na=candidate:2 1 udp 2015363583 fe80::ff27:4fa7:fa4d:848d 39849 typ host\r\na=candidate:3 1 udp 2015363839 fe80::dea6:32ff:feb0:65d 46495 typ host\r\na=candidate:4 1 udp 1679819007 46.8.174.74 50465 typ srflx raddr 192.168.18.69 rport 60676\r\na=end-of-candidates\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\nc=IN IP4 46.8.174.74\r\na=sendonly\r\na=mid:v2\r\na=rtcp-mux\r\na=ice-ufrag:V1hB\r\na=ice-pwd:MaEwrvKGHi0aoxWBmvH/NG\r\na=ice-options:trickle\r\na=setup:actpass\r\na=rtpmap:96 H264/90000\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=ssrc-group:FID 2305771464 3946393070\r\na=msid:janus janusv2\r\na=ssrc:2305771464 cname:janus\r\na=ssrc:3946393070 cname:janus\r\na=candidate:1 1 udp 2015363327 192.168.18.69 60676 typ host\r\na=candidate:2 1 udp 2015363583 fe80::ff27:4fa7:fa4d:848d 39849 typ host\r\na=candidate:3 1 udp 2015363839 fe80::dea6:32ff:feb0:65d 46495 typ host\r\na=candidate:4 1 udp 1679819007 46.8.174.74 50465 typ srflx raddr 192.168.18.69 rport 60676\r\na=end-of-candidates\r\n" }

Answer SDP

Working SDP from chrome:

Received SDP:  
RTCSessionDescription {type: 'answer', sdp: 'v=0\r\no=- 8495921174311694754 2 IN IP4 127.0.0.1\r\ns…42e01f\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\n'}
sdp
: 
"v=0\r\no=- 8495921174311694754 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE v1 v2\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:u5Cp\r\na=ice-pwd:SLqlSxu3B2wNW06doleuHiNs\r\na=ice-options:trickle\r\na=fingerprint:sha-256 38:B3:8F:33:86:C2:4B:7A:FA:5B:24:F7:42:96:80:AA:EA:41:9C:7F:1B:92:B6:96:ED:A2:EA:DB:1E:E7:84:24\r\na=setup:active\r\na=mid:v1\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=recvonly\r\na=rtcp-mux\r\na=rtpmap:96 H264/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=fmtp:96 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:u5Cp\r\na=ice-pwd:SLqlSxu3B2wNW06doleuHiNs\r\na=ice-options:trickle\r\na=fingerprint:sha-256 38:B3:8F:33:86:C2:4B:7A:FA:5B:24:F7:42:96:80:AA:EA:41:9C:7F:1B:92:B6:96:ED:A2:EA:DB:1E:E7:84:24\r\na=setup:active\r\na=mid:v2\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=recvonly\r\na=rtcp-mux\r\na=rtpmap:96 H264/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=fmtp:96 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\n"
type
: 
"answer"
[[Prototype]]
: 
RTCSessionDescription

The rtpmap on Firefox's answer is totally bogus (looks like VP8/90000 is the default?)

Received SDP:  
Object { type: "answer", sdp: "v=0\r\no=mozilla...THIS_IS_SDPARTA-99.0 4572671792646605999 0 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\na=fingerprint:sha-256 43:BD:70:31:0A:3B:B0:05:CE:83:6E:9D:EB:97:54:9C:4F:C0:5D:3F:91:42:40:AB:38:79:1E:16:BE:A9:D7:0F\r\na=ice-options:trickle\r\na=msid-semantic:WMS *\r\nm=video 0 UDP/TLS/RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:v1\r\na=rtpmap:120 VP8/90000\r\nm=video 0 UDP/TLS/RTP/SAVPF 120\r\nc=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:v2\r\na=rtpmap:120 VP8/90000\r\n" }
leigh-johnson commented 1 year ago

Phew, I finally cut through the noise and figured out what's going on here.

There's an open issue for Firefox indicating builds > v86 cannot resolve ICE candidate proposals between two computers on the same LAN using mDNS. Firefox doesn't recognize these machines are on the same network, and tries to bounce packets off a TURN relay server to establish a WebRTC PeerConnection.

https://bugzilla.mozilla.org/show_bug.cgi?id=1698141

The Recommended Workaround

Use Chrome >= Version 110

The Workaround (to use Firefox)

I verified Firefox works if I...

  1. Connect Raspberry Pi to Tailscale network
  2. Connect browsing machine (e.g. laptop or desktop computer) to Tailscale network
  3. Disable mDNS candidate resolution in janus.cfg on Raspberry Pi, setting nat: { ignore_mdns = true }
  4. In Firefox, via about:config set media.peerconnection.ice.force_interface to the Tailscale tunnel interface, e.g. utun0 on MacOS

However, that's super involved and I can't verify if this works on Windows at the moment.

leigh-johnson commented 1 year ago

Pulling this from milestone v0.6.6, since it's just a workaround at the moment.

leigh-johnson commented 1 year ago

Let's flash a warning message on unsupported browsers (only Chrome is supported right now).