Mistermanu#000
01/15/2025, 11:47 PMAttempting WebSocket connection (attempt ${attempt})...
);
const ws = new WebSocket(url);
websocketRef.current = ws;
ws.binaryType = 'arraybuffer';
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
if (ws.readyState !== WebSocket.OPEN) {
ws.close();
reject(new Error('Connection timeout'));
}
}, 5000);
ws.onopen = () => {
clearTimeout(timeout);
resolve(ws);
};
ws.onerror = () => {
clearTimeout(timeout);
reject(new Error('Connection failed'));
};
});
};Vapi
01/15/2025, 11:49 PMws.onerror
event to log or display more detailed information about the error. This can help you pinpoint the exact cause of the connection failure.
6. **Consult Documentation**: Double-check the VAPI documentation to ensure that you're following all the required steps for setting up the WebSocket connection.
7. **Contact Support**: If you've gone through all the above steps and still face issues, it might be best to reach out to VAPI support for further assistance.
If you'd like, I can assist you with implementing any of these steps or provide more detailed guidance on a specific part of the process. Just let me know how I can help!Vapi
01/15/2025, 11:49 PMMistermanu#000
01/16/2025, 12:01 AMVapi
01/16/2025, 12:02 AMlistenUrl
you received from VAPI is valid and has not expired. Some WebSocket URLs are only valid for a short period of time after generation.
2. **Check for Service Outages**: There might be a temporary service outage or maintenance on the VAPI side that is causing the WebSocket connection to fail. You can check the service status or reach out to VAPI support to confirm this.
3. **Authentication and Protocols**: Verify if there are any additional authentication steps or specific protocols required by VAPI that you need to follow when establishing a WebSocket connection.
4. **Contact VAPI Support**: Since the URL is provided by VAPI and you're following the correct procedure, it would be best to contact VAPI support for assistance. They can provide insights into whether there's an issue with the service or if there's something specific about your account or setup that needs to be addressed.
Remember to provide VAPI support with all the relevant details, including the exact error message, steps you've taken to troubleshoot, and any other pertinent information that could help them diagnose the issue.Mistermanu#000
01/16/2025, 12:03 AMShubham Bajaj
01/16/2025, 4:58 PMShubham Bajaj
01/16/2025, 4:59 PMsh
wscat -c wss://aws-us-west-2-production1-phone-call-websocket.vapi.ai/<call-id>/transport
Shubham Bajaj
01/16/2025, 5:01 PMShubham Bajaj
01/16/2025, 5:01 PMMistermanu#000
01/16/2025, 6:24 PMShubham Bajaj
01/17/2025, 3:18 PMts
import { WebSocket } from "ws";
import * as fs from "fs";
let pcmBuffer = Buffer.alloc(0);
const ws = new WebSocket(
"wss://phone-call-websocket.aws-us-west-2-backend-production2.vapi.ai/5c5e5--004e7/listen",
);
ws.on("open", () => console.log("WebSocket connection established"));
ws.on("message", (data: any, isBinary: any) => {
// console.log({ isBinary, data });
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: any) => {
console.error({ error });
console.error("WebSocket error:", error);
});
Shubham Bajaj
01/17/2025, 3:18 PMMistermanu#000
01/30/2025, 9:27 PM