fix: filter only authenticated socket
This commit is contained in:
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@ import "ws";
|
||||
|
||||
declare module "ws" {
|
||||
interface WebSocket {
|
||||
isAuthenticated?: boolean;
|
||||
deviceId?: string;
|
||||
deviceName?: string;
|
||||
lastAlive?: number;
|
||||
|
||||
Reference in New Issue
Block a user