We are since a week ago experience problems with S...
# ask-ai
g
We are since a week ago experience problems with Safari for both MacOS and iOS where we get an WebSocket connection error with error message "bad response from the server" It is working perfectly on Chrome. And have been working for Safari until latest Safari update (we believe it can have an correlation with that release) How can we continue to debugg to understand how to solve it
t
Thanks for reaching out, Jens. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm sorry to hear you're experiencing the WebSocket connection error "bad response from the server" in Safari. This can sometimes happen after the latest Safari update, but don't worry—we can work through this together. Here are some helpful steps to troubleshoot and hopefully resolve the issue: • Run Connection Diagnostics: Try using LiveKit's Connection Test utility to check WebSocket, WebRTC, and TURN server connectivity. This is a great way to pinpoint any Safari-specific hiccups. • Check Network Configuration: It’s worth making sure there aren’t any network blocks like firewalls or VPNs that might be interfering with the WebSocket connections. • Safari Update-Specific Debugging: Clearing Safari’s cache, testing in private browsing mode, and verifying that WebRTC and WebSocket features are enabled in Safari’s developer settings can often help. • Adjust WebSocket Timeout: Sometimes, Safari updates require a bit more patience—so adjusting the
websocketTimeout
in your SignalOptions to allow longer connection times might do the trick. • Verify Authentication: Double-check that your access token is valid and correctly formatted since it’s attached to the WebSocket header. If you’re still seeing the error after trying these steps, it might be related to changes in Safari’s WebSocket or WebRTC implementation. Please feel free to reach out—I’d be happy to help you set up specific diagnostics or discuss your Safari version and when exactly the error happens (like during initial connection or reconnection). We’ll figure this out together! Sources: Sources/LiveKit/Core/SignalClient.swift | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki | src/js/safari/safari_shim.js | src/api/WebSocketStream.ts | Diagnosing Connection Errors with Connection Test Utility
g
How do i do the connection diagnotics
t
Let's walk through how you can perform connection diagnostics using LiveKit's Connection Test utility. I’m here to help you every step of the way! 1. Install the LiveKit Client SDK: First, make sure you have the LiveKit Client SDK installed in your project. You can easily add it using npm:
npm install @livekit/client-sdk
2. Import the ConnectionCheck Class: Next, include the ConnectionCheck utility in your project by adding this code:
import { ConnectionCheck } from '@livekit/client-sdk';
3. Set Up the Connection Test: Now, use the following snippet to check your WebSocket, WebRTC, and TURN server connectivity:
Copy code
const checker = new ConnectionCheck({
  url: 'your-project-url',
  token: 'your-token'
});

// Run WebSocket connectivity check specifically
const websocketResult = await checker.checkWebsocket();
const webrtcResult = await checker.checkWebRTC();
const turnResult = await checker.checkTURN();
4. Analyze the Results: These results will help you understand if there are any issues with WebSocket connectivity, WebRTC functionality, or TURN server access. Just be sure to replace
'your-project-url'
and
'your-token'
with your actual LiveKit server URL and a valid access token. If you’d like, I’m happy to guide you through generating the token or setting up the test—just let me know!
g
Please help with generating the token
t
I'm here to help you generate an access token for connection diagnostics! You have a few options to choose from, so pick the one that feels right for you: 1. Using the LiveKit CLI: This is the fastest way to get started. Just run this command: `lk token create --join --room my-room --identity my-identity`Remember to swap out
my-room
with your actual room name and
my-identity
with a unique participant identity that you choose. 2. Using the Node.js SDK: If you prefer to generate the token programmatically, here’s a handy snippet: `import { AccessToken } from 'livekit-server-sdk'; const at = new AccessToken('your-api-key', 'your-api-secret', { identity: 'participant-name', ttl: '10m', }); at.addGrant({ roomJoin: true, room: 'room-name', }); const token = at.toJwt();`Just replace
'your-api-key'
,
'your-api-secret'
,
'participant-name'
, and
'room-name'
with your own details. 3. Using the Python SDK: For those using Python, here’s a simple function to create your token:
Copy code
from livekit import AccessToken

def create_token(api_key, api_secret):
    token = AccessToken(api_key, api_secret)
    token.identity = 'participant-name'
    token.add_grant(room_join=True, room='room-name')
    return token.to_jwt()
Feel free to let me know which method sounds best for you, and I’d be happy to guide you through the next steps or answer any questions you might have! Sources: livekit-agents/livekit/agents/inference/_utils.py | README.md | Analytics API | LiveKit Docs | Authentication | LiveKit Docs | LiveKit CLI Setup | LiveKit Docs