You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an elixir backend where I can retrieve the ice servers from a turn server provider or a self hosted coturn, it's a graphql query that return something like this:
I have a global setupPeerConnectionConfig function.
constsetupPeerConnectionConfig=(adapter,iceServers)=>{constqs=newURLSearchParams(location.search);constforceTurn=qs.get("force_turn");constforceTcp=qs.get("force_tcp");constpeerConnectionConfig={};if(iceServers&&iceServers.urls!==null){if(forceTcp){iceServers.urls=iceServers.urls.filter((url)=>url.startsWith("turn")&&url.endsWith("tcp"));}consthasStunServer=!!iceServers.urls.find((url)=>url.startsWith('stun'));constnewIceServers=[];if(!forceTcp&&!forceTurn&&!hasStunServer){newIceServers.push({urls: "stun:stun1.l.google.com:19302"});}// remove __typename from the graphql querynewIceServers.push({username: iceServers.username,credential: iceServers.credential,urls: iceServers.urls});peerConnectionConfig.iceServers=newIceServers;if(forceTurn||forceTcp){peerConnectionConfig.iceTransportPolicy="relay";}}else{peerConnectionConfig.iceServers=[{urls: "stun:stun1.l.google.com:19302"},{urls: "stun:stun2.l.google.com:19302"}];}adapter.setPeerConnectionConfig(peerConnectionConfig);};
To test that your config is right, you can force going through turn server (iceTransportPolicy = "relay")
by adding in the url ?force_turn=true. To force turn via tcp, use ?force_tcp=true. Look at about:webrtc in Firefox to see the selected candidate.
In your adapter-ready listener, call the setupPeerConnectionConfig with the retrieved iceServers.
consticeServers=awaitcallToServerToGetIceServers();scene.addEventListener("adapter-ready",({detail: adapter})=>{// don't use any await here, it won't be awaited before connectingsetupPeerConnectionConfig(adapter,iceServers);// ... do your other things});scene.emit("connect");
otherwise new peer connections will use expired turn credential and the connection won't succeed. You can use a setTimout similar to the JWT I explained here mozilla/janus-plugin-sfu#77 (comment)
I should probably push both the linked comment and this issue into a document that I push in this repo.
The text was updated successfully, but these errors were encountered:
I have an elixir backend where I can retrieve the ice servers from a turn server provider or a self hosted coturn, it's a graphql query that return something like this:
I have a global
setupPeerConnectionConfig
function.To test that your config is right, you can force going through turn server (
iceTransportPolicy = "relay"
)by adding in the url
?force_turn=true
. To force turn via tcp, use?force_tcp=true
. Look atabout:webrtc
in Firefox to see the selected candidate.In your
adapter-ready
listener, call thesetupPeerConnectionConfig
with the retrieved iceServers.Getting an iceServers config asynchronously and using
connectOnLoad: true
are incompatible, there is no await foradapter-ready
listener in https://github.com/networked-aframe/networked-aframe/blob/41a6b484c8208ecb24e85855542a3fa40faf7bec/src/components/networked-scene.js#L33 so the user will connect before we get the config.If your turn credential is temporary, you will need to call regularly
otherwise new peer connections will use expired turn credential and the connection won't succeed. You can use a setTimout similar to the JWT I explained here mozilla/janus-plugin-sfu#77 (comment)
I should probably push both the linked comment and this issue into a document that I push in this repo.
The text was updated successfully, but these errors were encountered: