This commit is contained in:
Ryzerth
2025-11-04 19:18:53 -05:00
parent f494612908
commit 6605a2d933
4 changed files with 115 additions and 43 deletions

20
user.go
View File

@@ -10,6 +10,7 @@ import "github.com/gorilla/websocket"
type User struct {
// WebSocket used to communicate with the user
sock *websocket.Conn;
sockSendMtx sync.Mutex;
// Display mutex
displayMtx sync.Mutex;
@@ -18,6 +19,23 @@ type User struct {
display *Display;
}
// Send an ICE candiate to the user
func (this *User) iceCandidate(candidate string) {
// Acquire the sending mutex
this.sockSendMtx.Lock()
// Send the candidate
sendMessage(this.sock, Message{
mtype: "ice-candidate",
arguments: map[string]interface{}{
"candidate": candidate,
},
})
// Release the sending mutex
this.sockSendMtx.Unlock()
}
// Connection handler for users
func userHandler(sock *websocket.Conn) {
// Initialize the user instance
@@ -170,8 +188,6 @@ func userHandler(sock *websocket.Conn) {
// Send the ice candidtate to the display
user.display.iceCandidate(candidate);
// TODO: Check error
// Release the user's display pointer
user.displayMtx.Unlock();