I'm currently working on a React-based project tha...
# ask-ai
d
I'm currently working on a React-based project that is using LiveKit Cloud. I've been testing this project locally using Firefox and have had no issues with connecting to LiveKit Cloud. We've recently deployed our project internally and are still using LiveKit Cloud. However, while I've been accessing the project through the deployment, I'm finding it cannot consistently connect to LiveKit Cloud from Firefox. I've noticed we get repeated error messages in the console indicating it could not establish a PC connection. I also notice a similar message when I run your connection test and try connecting to the provided Websocket URL using a generated token. Interestingly, this only seems to be an issue with Firefox. When I or other users have accessed it through Edge, Chrome or Safari, it connects just fine.I would appreciate any advice or potential troubleshooting steps to help mitigate this issue.
t
Thanks for reaching out, Corey. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you so much for sharing those details! To help you better, could you please let me know more about the error messages you’re seeing in the Firefox console? Also, is this happening with all versions of Firefox or just certain ones? And just to make sure, are there any network restrictions like firewalls or VPNs in the environment where you’re experiencing this issue? I’m here to help you get this sorted out! Sources: pkg/rtc/transport.go | Diagnosing Connection Errors with Connection Test Utility | Firewall Tips | Connecting to LiveKit | LiveKit Docs | WebRTC Codecs Guide - LiveKit
d
The main error message I'm getting in my terminal is: "WebRTC: ICE failed, your TURN server appears to be broken." I also notice when I run the LiveKit connection tester, the TURN check fails with a message: "cannot establish pc connection." The application is being accessed through my company's VPN. However, I suspect this is an issue with my home internet because this issue does not occur in the office or when I am connected to a hotspot.
t
It looks like you're encountering the error message "WebRTC: ICE failed, your TURN server appears to be broken," and the LiveKit connection tester shows a failed TURN check. This usually points to your home network possibly blocking UDP traffic or limiting WebRTC protocols. Since you mentioned this doesn’t happen at your office or on a hotspot, it seems like something specific to your home network setup. Let’s work through some steps together to help troubleshoot and hopefully resolve this: 1. Force TURN relay-only mode: You can configure your client to use TURN exclusively by setting
iceTransportPolicy: 'relay'
in the RTC configuration. This way, it bypasses direct UDP and TCP attempts, routing all traffic through TURN. 2. Ensure TURN/TLS accessibility: LiveKit Cloud offers TURN servers with TLS support on port 443. It’s a good idea to check that your home network allows outbound connections to
*.turn.livekit.cloud
on TCP/443. 3. Run the LiveKit Connection Test Utility: This tool helps validate WebSocket, WebRTC, and TURN connectivity. If the TURN test fails here, it’s a clear sign your home network might be blocking the necessary traffic. 4. Check your home network settings: Take a look at your router or firewall settings to ensure UDP traffic isn’t being blocked and WebRTC protocols aren’t restricted. You might need to tweak firewall rules or open specific ports. If you try these steps and still run into issues, please don’t hesitate to reach out. I’m here to help, and we can explore more solutions together. Sources: pkg/rtc/types/ice.go | Firewall Tips | Connecting to LiveKit | LiveKit Docs | Diagnosing Connection Errors with Connection Test Utility
d
How do I set the ICE transport policy in the LiveKitRoom React component?
t
To set the
iceTransportPolicy
in the
LiveKitRoom
React component, you can easily include it in the
connectOptions
prop, specifically inside the
rtcConfig
field. Here’s a friendly example to guide you:
Copy code
{``}
By setting
iceTransportPolicy: 'relay'
, you make sure all media traffic goes through TURN servers, which is especially helpful if you're dealing with restrictive network environments. If you have any questions or want to explore this further, just let me know—I’m here to help! Sources: Firewall Tips | packages/react/src/prefabs/PreJoin.tsx | android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
d
So, I tested adding this setting. Before I did this, my localhost instance of the application was able to connect to LiveKit without issue. Now, I'm getting the same errors in my development environment as in my prod deployment. Would I be correct in thinking there is definitely something with my home network be blocking TURN connections? Is there anything I can do to prevent my application from connecting via TURN in production?
t
It sounds like your home network might be blocking TURN connections, especially since enabling
iceTransportPolicy: 'relay'
led to the same errors in your development environment. To help your application avoid connecting via TURN in production, you can simply configure your LiveKit server to disable TURN altogether. Here’s a straightforward way to do this: 1. In your LiveKit server configuration file, set the
enabled
field under the
turn
configuration block to
false
. For example:
Copy code
turn:
  enabled: false
Also, double-check that no external TURN servers are listed in the
turn_servers
section under the
rtc
configuration. Just a heads-up: disabling TURN might affect users who are behind strict firewalls, since TURN usually acts as a helpful fallback when direct peer-to-peer connections aren’t possible. If you have any questions or want to explore other options, please don’t hesitate to reach out—I’m here to help! Sources: pkg/service/turn.go | Firewall Tips
d
To be clear, I am using LiveKit Cloud. I do not have the ability to change that setting.
t
In LiveKit Cloud, TURN servers are automatically enabled and managed to help ensure you have a reliable connection, especially if you're behind restrictive networks. I understand you might want to disable TURN, but currently, there isn't an option to do so because it plays a key role in keeping your connection stable. If you have particular compliance or networking needs, I'd recommend reaching out to LiveKit directly—they might have enterprise solutions or network isolation options that could work for you. Please feel free to ask if you have any more questions or need further help—I'm here for you! Sources: cmd/server/main.go | Configuring firewalls | LiveKit Docs
d
So I guess I'm just trying to figure out does localhost need to contact a TURN server to make the connection? Why is it when I change the setting to 'relay', I get the error message?
t
Hey there! When you're working on localhost development, you usually don't need a TURN server for WebRTC connections in LiveKit because localhost setups often allow direct peer-to-peer communication via UDP. That said, if you set
iceTransportPolicy: 'relay'
, it makes all the traffic go through a TURN server, skipping the direct peer-to-peer route. This is why you might see that error message if your home network is blocking TURN connections. In networks with more restrictions, TURN servers play a key role in relaying traffic when direct connections just can’t happen. So, if your home network is blocking TURN, the connection will fail when
iceTransportPolicy: 'relay'
is turned on. Please feel free to reach out if you'd like me to explain anything further or if you need any more help—I’m here for you! Sources: Connecting to LiveKit | LiveKit Docs | Deploying LiveKit | LiveKit Docs | Diagnosing Connection Errors with Connection Test Utility
d
So does it seem plausible that, when the application is in production, it has to use a TURN server for WebRTC connections? If so, is there anything I can do on my end with the application to make it connect?
t
It’s quite possible that your application in production might need to use a TURN server for WebRTC connections, especially if the network environment is a bit restrictive (like blocking UDP traffic). LiveKit Cloud is thoughtfully designed to support these situations by providing TURN servers with TLS support on port 443, which behaves like standard HTTPS traffic—making it much more likely to work smoothly even in restrictive settings. Here are some friendly steps you can follow to help ensure your connections go through successfully: 1. Check Your Firewall Rules: Make sure your network allows outbound connections to: ◦
*.livekit.cloud
on TCP/443 for signaling ◦
*.turn.livekit.cloud
on TCP/443 for TURN over TLS ◦ Optional: UDP ports 50000–60000 for direct WebRTC media 1. Try Forcing TURN Usage: If direct connections aren’t working, you can set your application to use TURN exclusively by adding
iceTransportPolicy: 'relay'
in your RTC configuration. This way, all traffic will go through the TURN servers. 2. Test Your Connectivity: Use the LiveKit Connection Tester to check WebSocket, WebRTC, and TURN connectivity right in your production environment. Please feel free to reach out if you have any more questions or need a hand with anything else—I’m here to help! Sources: Firewall Tips | Documentation/ImprovingCallReliability.md | Connecting to LiveKit | LiveKit Docs | Configuring firewalls | LiveKit Docs
d
Quick question - how do I test my firewall rules? I'm 99% sure they allow all outbound connections, but is there a quick way I can test?
t
To help you test your firewall rules for LiveKit connectivity, you can use the LiveKit Connection Test Utility. It’s a great tool to check if any network restrictions might be blocking the connections you need. Here’s a simple way to get started: 1. Run the LiveKit Connection Test: Head over to https://livekit.io/connection-test and run the tests for WebSocket, WebRTC, and TURN connectivity. This will give you a clear idea if any specific traffic is being blocked. 2. Check Your Firewall Rules: Make sure your firewall allows outbound traffic to these addresses: ◦
*.livekit.cloud
on TCP/443 for WebSocket signaling ◦
*.turn.livekit.cloud
on TCP/443 for TURN over TLS ◦ Optional: UDP ports 50000–60000 for direct WebRTC media ◦ Optional: UDP/3478 for TURN/UDP and STUN 1. Try Forcing TURN Usage: If needed, you can configure your application to use TURN only by setting
iceTransportPolicy: 'relay'
in the RTC configuration. This helps route all traffic through TURN servers, which often work better with restrictive firewalls. If you find that all tests are failing, it’s a strong sign that your firewall or VPN might be blocking LiveKit traffic. Please feel free to reach out if you’d like me to help you troubleshoot further! Sources: Diagnosing Connection Errors with Connection Test Utility | Configuring firewalls | LiveKit Docs | Firewall Tips
d
As I shared earlier, I have already run the LiveKit connection tester. It failed at the TURN step and said it could not establish pc connection. Why is this happening and what can I do about it?
Further, why is this only happening in Firefox and not other browsers?
t
I'm sorry to hear you're encountering the "could not establish pc connection" error during the TURN step in the LiveKit connection tester. This usually points to some challenges with ICE negotiation or network restrictions. Let's walk through why this might be happening and some steps you can take to resolve it: 1. Why This Happens: ◦ Your network might be blocking TURN servers, possibly due to firewall or NAT settings. ◦ UDP traffic could be restricted, preventing TURN/UDP from establishing a connection. ◦ Access to TURN/TLS (over TCP/443) might be limited, which is essential for networks with stricter rules. 1. What You Can Do: ◦ Check that your firewall allows outbound traffic to
*.turn.livekit.cloud
on TCP/443—this is usually the most firewall-friendly route. ◦ Make sure UDP traffic is allowed on ports 50000–60000 and 3478 for TURN/UDP and WebRTC media. ◦ Try forcing TURN relay-only mode by setting
iceTransportPolicy: 'relay'
in your RTC configuration, so all traffic goes through TURN servers. ◦ If possible, temporarily disable any VPNs or firewalls to see if they might be causing the connection issue. 1. Testing: You can also use the WebRTC Trickle ICE sample to check TURN server connectivity from outside your setup. Please feel free to reach out if you need more help or want to explore additional troubleshooting steps—I’m here to support you! Sources: src/room/RTCEngine.ts | Diagnosing Connection Errors with Connection Test Utility | Firewall Tips | Configuring firewalls | LiveKit Docs | Documentation/ImprovingCallReliability.md
It seems like the TURN connection issue you're experiencing in Firefox is related to how Firefox handles WebRTC and ICE negotiation differently from other browsers. Firefox tends to have stricter WebRTC behaviors, and this can cause issues if TURN/TLS (over TCP/443) isn’t set up just right or if there are any inconsistencies in your ICE server configuration. Let’s try a few steps together to get this sorted out: 1. Ensure TURN/TLS is Configured: Please double-check that your LiveKit Cloud setup includes
turns:
URLs in the ICE server configuration. TURN/TLS (over TCP/443) tends to work better with firewalls and improves compatibility with Firefox. 2. Force TURN Relay Usage: You might want to configure your application to use TURN exclusively by setting
rtcConfig: { iceTransportPolicy: 'relay' }
. This way, all traffic goes through TURN servers, which can help. 3. Run the Connection Test Utility: Try using the LiveKit Connection Tester on Firefox. It’s a handy tool that can help pinpoint whether the issue happens at the WebSocket, WebRTC, or TURN stage. 4. Update SDKs: Make sure you’re running the latest version of the LiveKit SDK. Updates often include fixes for browser-specific quirks like this. If you’re still running into trouble after these steps, it might be due to how Firefox handles DTLS or SRTP during the TURN connection phase. Please don’t hesitate to reach out—I’m here to help you through this! Sources: Firewall Tips | Configuring firewalls | LiveKit Docs | src/connectionHelper/checks/turn.ts | Diagnosing Connection Errors with Connection Test Utility | CHANGELOG.md
d
Can I contact someone to enquire about this further?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!