fix: filter only authenticated socket

This commit is contained in:
2026-09-22 14:21:10 +08:00
parent 21c30393fc
commit b7bbce7374
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -56,7 +56,7 @@ function getWhatsApp(deviceId?: string): WebSocket | null {
// find the most recent active bridge
const sock = [...bridgeSockets]
.sort((a, b) => (b.lastSuccessfulCall || 0) - (a.lastSuccessfulCall || 0))
.find((i) => i.readyState === WebSocket.OPEN);
.find((i) => i.readyState === WebSocket.OPEN && i.isAuthenticated);
if (sock) return sock;
return null;
@@ -153,6 +153,7 @@ function handleWhatsAppMessage(ws: WebSocket, data: string) {
console.log("[WhatsApp event]", event, data);
if (event === "ready") {
ws.isAuthenticated = data.authenticated || false;
ws.deviceId = data.deviceId;
ws.deviceName = data.deviceName;
}
+1
View File
@@ -2,6 +2,7 @@ import "ws";
declare module "ws" {
interface WebSocket {
isAuthenticated?: boolean;
deviceId?: string;
deviceName?: string;
lastAlive?: number;