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
|
// find the most recent active bridge
|
||||||
const sock = [...bridgeSockets]
|
const sock = [...bridgeSockets]
|
||||||
.sort((a, b) => (b.lastSuccessfulCall || 0) - (a.lastSuccessfulCall || 0))
|
.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;
|
if (sock) return sock;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -153,6 +153,7 @@ function handleWhatsAppMessage(ws: WebSocket, data: string) {
|
|||||||
console.log("[WhatsApp event]", event, data);
|
console.log("[WhatsApp event]", event, data);
|
||||||
|
|
||||||
if (event === "ready") {
|
if (event === "ready") {
|
||||||
|
ws.isAuthenticated = data.authenticated || false;
|
||||||
ws.deviceId = data.deviceId;
|
ws.deviceId = data.deviceId;
|
||||||
ws.deviceName = data.deviceName;
|
ws.deviceName = data.deviceName;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -2,6 +2,7 @@ import "ws";
|
|||||||
|
|
||||||
declare module "ws" {
|
declare module "ws" {
|
||||||
interface WebSocket {
|
interface WebSocket {
|
||||||
|
isAuthenticated?: boolean;
|
||||||
deviceId?: string;
|
deviceId?: string;
|
||||||
deviceName?: string;
|
deviceName?: string;
|
||||||
lastAlive?: number;
|
lastAlive?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user