From 7326a1c98b3fb4dfa7dc01e6c1bcf858bb098070 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 29 Dec 2021 12:05:32 +0100 Subject: [PATCH] mutext for voice and mobile conn --- modules/structs/WebClient.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/structs/WebClient.go b/modules/structs/WebClient.go index bab2805..cdbd79c 100644 --- a/modules/structs/WebClient.go +++ b/modules/structs/WebClient.go @@ -17,17 +17,23 @@ type WebClientDb struct { type WebClient struct { Uuid string MobileConn *websocket.Conn + mobileConnMu sync.Mutex VoiceConn *websocket.Conn + voiceConnMu sync.Mutex MobileCmdIDs []int mobileCmdMu sync.Mutex VoiceCmdIDs []int voiceCmdMu sync.Mutex - mu sync.Mutex } func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error { - webClient.mu.Lock() - defer webClient.mu.Unlock() + if conn == webClient.MobileConn { + webClient.mobileConnMu.Lock() + defer webClient.mobileConnMu.Unlock() + return conn.WriteMessage(websocket.BinaryMessage, msg) + } + webClient.voiceConnMu.Lock() + defer webClient.voiceConnMu.Unlock() return conn.WriteMessage(websocket.BinaryMessage, msg) }