Closed LanTenDragon closed 1 year ago
Turns out I do not need a TURN server, STUN is enough even for both parties behind symmetric NAT. Im not sure how hole punching is achieved with just STUN,
The main problem is my misunderstanding of the WebRTC steps and behaviours. (CMIIW)
/api/whep
endpoint, the SDP
does not contain any candidates.I think something like this could work as a solution.
1. On the frontend (browser-side), perform peerConnection.createOffer() as usual
2. Listen on peerConnection.onicegatheringstatechange() event
3. On ice gathering completion, add the SDP and browser ICE candidates into the API call's body
4. Perform peerConnection.addIceCandidate() on the server side.
I saw this comment, and tried to replicate it, but without any success.
What I have tried:
localhost:8080
, and added TURN severs according to the linked comment.desktop port 8080
toGCP VM port 58080
using sshssh -R 58080:127.0.0.1:8080 foo@bar.com
http://bar.com:58080/yourStreamkey
(no https, it should not matter, right?)Scenario 1
To simulate a scenario where both the broadcast and the viewer are behind symmetric NAT, and to prevent LAN candidate pairs being picked, I performed the steps above with one extra change, setting
ICETransportPolicy: webrtc.ICETransportPolicyRelay
inwebrtc.Config
. Visithttp://bar.com:58080/yourStreamkey
in Chrome on the same PC as broadcast-box is running or Chrome on a laptop in the same LAN. The stream cannot be loaded. Looking atchrome://webrtc-internals
, I get a red box withconnectionstatechange: failed
.candidateType=relay
entries are present in both local and remote stats tableScenario 2
For a more realistic scenario, I used 4G LTE mobile data and Chrome on Android to view the broadcast. I did steps 1-5, this time not touching
ICETransportPolicy
. Looking atchrome://webrtc-internals
on android, I get the same red box withconnectionstatechange: failed
. Similarly,candidateType=relay
entries are present in both local and remote stats table.Both scenarios have been repeated with two different TURN servers
Pion TURN server
hosted on the VM in step 2Pion TURN client
-ping to ensure that it is workingmetered.ca
TURN server