From 5140d34664acc2b6d9c27c014f358e56d9693a8d Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Wed, 5 Nov 2025 03:00:14 -0500 Subject: [PATCH] bugfix --- user.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/user.go b/user.go index b22e54d..7e1a5b7 100644 --- a/user.go +++ b/user.go @@ -53,6 +53,9 @@ func userHandler(sock *websocket.Conn) { // Initialize the user instance user := User{ sock: sock, display: nil }; + // Acquire the sending mutex + user.sockSendMtx.Lock() + // Send back the config for the user to use sendMessage(sock, Message{ mtype: "config", @@ -64,6 +67,9 @@ func userHandler(sock *websocket.Conn) { }, }); + // Release the sending mutex + user.sockSendMtx.Unlock() + // Message loop for { // Receive a message @@ -136,11 +142,17 @@ func userHandler(sock *websocket.Conn) { // Log the connection log.Println("User successfully connected to display: ID='" + dispID + "'"); + // Acquire the sending mutex + user.sockSendMtx.Lock() + // Notify the user of the successful connection sendMessage(sock, Message{ mtype: "success", }); + // Release the sending mutex + user.sockSendMtx.Unlock() + case "webrtc-offer": // Check that the message contains an offer offer := msg.arguments["offer"]; @@ -173,6 +185,9 @@ func userHandler(sock *websocket.Conn) { // Release the user's display pointer user.displayMtx.Unlock(); + // Acquire the sending mutex + user.sockSendMtx.Lock() + // Send back the response sendMessage(sock, Message{ mtype: "webrtc-answer", @@ -181,6 +196,9 @@ func userHandler(sock *websocket.Conn) { }, }); + // Release the sending mutex + user.sockSendMtx.Unlock() + case "ice-candidate": // Check that the message contains an ice candidate candidate := msg.arguments["candidate"]