Monitor Listen URL is different that what is in va...
# support
s
Vapi docs -> wss://aws-us-west-2-production1-phone-call-websocket.vapi.ai/7420f27a-30fd-4f49-a995-5549ae7cc00d/transport My logs -> wss://aws-us-west-2-production2-phone-call-websocket.vapi.ai/e499fca2-87a2-43fb-aec4-3b3013540672/listen I am getting failures on my end for some reason. I imagine because the url is not correct? My code: const connectWebSocket = (url: string) => { console.log(url) const socket = new WebSocket(url); socketRef.current = socket; socket.binaryType = 'arraybuffer'; socket.onopen = () => { console.log('WebSocket connection established.'); }; socket.onmessage = async (event) => { if (!audioContextRef.current) { audioContextRef.current = new AudioContext(); } try { const audioData = event.data as ArrayBuffer; const audioBuffer = await audioContextRef.current.decodeAudioData(audioData); const source = audioContextRef.current.createBufferSource(); source.buffer = audioBuffer; source.connect(audioContextRef.current.destination); source.start(); } catch (error) { console.error('Error decoding audio:', error); } }; socket.onerror = (error) => { console.error('WebSocket error:', error); }; socket.onclose = () => { console.log('WebSocket connection closed.'); setCallInProgress(false); }; }; https://cdn.discordapp.com/attachments/1294765466069500036/1294765466505449563/image.png?ex=670c33ce&is=670ae24e&hm=3d2f408e3f71f8dcd86db2dd2c24c3607dc40bf7f2984c2af69d5f7690e01319&
v
@SlaviSavanovic It looks like you've provided two different WebSocket URLs, one for documentation and one from your logs. If you're experiencing failures, it could be due to several reasons, including incorrect URL, network issues, or server-side problems. The code snippet you've provided seems to be for establishing a WebSocket connection and handling incoming audio data. The URL you use to connect to the WebSocket should be provided by VAPI and must be correct and specific to your session or service. If you're getting errors, here are a few steps you can take to troubleshoot the issue: 1. **Verify the WebSocket URL**: Ensure that the WebSocket URL you are using is the one provided by VAPI for your specific session or service. The URLs you've posted seem to be for different environments (production1 and production2), so make sure you're using the correct one. 2. **Check Network Connection**: Ensure that your network allows WebSocket connections and that there are no firewalls or proxies blocking the connection. 3. **Server-Side Logs**: Check the server-side logs for any errors or messages that could indicate why the connection is failing. 4. **Error Handling**: Your code includes an
onerror
event handler. Make sure to log the error details to understand what might be going wrong. 5. **WebSocket Support**: Ensure that the environment where your code is running supports WebSockets. 6. **Reconnection Logic**: Implement reconnection logic in case the WebSocket connection drops unexpectedly. If you've checked all these and are still facing issues, it might be helpful to provide more details about the errors you're encountering. If the problem persists, please ask support for more info on this.
You can continue this conversation by mentioning me in the message.
Got it. Tagging @User for additional help.
s
@supportr Realizing now this might be because I am calling from localhost
@User ^
@User Just checking to see if anyone has seen this?
s
you cannot connect to secure websocket connection from localhost or unsecure websocket.
what else issue your facing on this? @SlaviSavanovic
s
I tried https and that is what the screen shot is above
If you check vapi's docs, there is a /transport url in the demonstration, where the api actually returns / listen. I am still having the exact same issue. I am running next.js and connect to websocket via client side to display live audio output from the call and transcription looking to add some control functionality. But i cannot get the websocket to connect.
Vapi Docs Demonstration -> const WebSocket = require('ws'); const fs = require('fs'); let pcmBuffer = Buffer.alloc(0); const ws = new WebSocket("wss://aws-us-west-2-production1-phone-call-websocket.vapi.ai/7420f27a-30fd-4f49-a995-5549ae7cc00d/transport"); ws.on('open', () => console.log('WebSocket connection established')); ws.on('message', (data, isBinary) => { if (isBinary) { pcmBuffer = Buffer.concat([pcmBuffer, data]); console.log(
Received PCM data, buffer size: ${pcmBuffer.length}
); } else { console.log('Received message:', JSON.parse(data.toString())); } }); ws.on('close', () => { if (pcmBuffer.length > 0) { fs.writeFileSync('audio.pcm', pcmBuffer); console.log('Audio data saved to audio.pcm'); } }); ws.on('error', (error) => console.error('WebSocket error:', error));
The problem was the call was not established. The user has to pick up the phone before attempting to connect to web socket. It's working now. Incase anyone else has this issue. I would try to connect to the websocket every 2 seconds 30 times (one minute) and if no connection is established there is a further issue. Thanks for the help
4 Views