This commit is contained in:
AlexandreRouma
2025-11-05 03:00:14 -05:00
parent f352b50f18
commit 5140d34664

18
user.go
View File

@@ -53,6 +53,9 @@ func userHandler(sock *websocket.Conn) {
// Initialize the user instance // Initialize the user instance
user := User{ sock: sock, display: nil }; user := User{ sock: sock, display: nil };
// Acquire the sending mutex
user.sockSendMtx.Lock()
// Send back the config for the user to use // Send back the config for the user to use
sendMessage(sock, Message{ sendMessage(sock, Message{
mtype: "config", mtype: "config",
@@ -64,6 +67,9 @@ func userHandler(sock *websocket.Conn) {
}, },
}); });
// Release the sending mutex
user.sockSendMtx.Unlock()
// Message loop // Message loop
for { for {
// Receive a message // Receive a message
@@ -136,11 +142,17 @@ func userHandler(sock *websocket.Conn) {
// Log the connection // Log the connection
log.Println("User successfully connected to display: ID='" + dispID + "'"); log.Println("User successfully connected to display: ID='" + dispID + "'");
// Acquire the sending mutex
user.sockSendMtx.Lock()
// Notify the user of the successful connection // Notify the user of the successful connection
sendMessage(sock, Message{ sendMessage(sock, Message{
mtype: "success", mtype: "success",
}); });
// Release the sending mutex
user.sockSendMtx.Unlock()
case "webrtc-offer": case "webrtc-offer":
// Check that the message contains an offer // Check that the message contains an offer
offer := msg.arguments["offer"]; offer := msg.arguments["offer"];
@@ -173,6 +185,9 @@ func userHandler(sock *websocket.Conn) {
// Release the user's display pointer // Release the user's display pointer
user.displayMtx.Unlock(); user.displayMtx.Unlock();
// Acquire the sending mutex
user.sockSendMtx.Lock()
// Send back the response // Send back the response
sendMessage(sock, Message{ sendMessage(sock, Message{
mtype: "webrtc-answer", mtype: "webrtc-answer",
@@ -181,6 +196,9 @@ func userHandler(sock *websocket.Conn) {
}, },
}); });
// Release the sending mutex
user.sockSendMtx.Unlock()
case "ice-candidate": case "ice-candidate":
// Check that the message contains an ice candidate // Check that the message contains an ice candidate
candidate := msg.arguments["candidate"] candidate := msg.arguments["candidate"]