mutext for voice and mobile conn

master
Alex 2021-12-29 12:05:32 +01:00
parent eb5cce66f5
commit 7326a1c98b
1 changed files with 9 additions and 3 deletions

View File

@ -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)
}