initial commit

This commit is contained in:
AlexandreRouma
2025-10-31 18:38:33 -04:00
commit 140bc3c3f5
16 changed files with 1637 additions and 0 deletions

42
wshandler.go Normal file
View File

@@ -0,0 +1,42 @@
package main
// Packages
import "log"
import "net/http"
import "github.com/gorilla/websocket"
// Create the websocket upgrader
var upgrader = websocket.Upgrader{}
// Handler for the signalling backend
func wsHandler(respWriter http.ResponseWriter, req *http.Request) {
// Upgrade the HTTP request to a WebSocket session
sock, err := upgrader.Upgrade(respWriter, req, nil)
if (err != nil) {
log.Print(err)
return
}
// Ensure that when this handler exits, the WebSocket closes
defer sock.Close()
// Receive the init message
msg := recvMessage(sock, 5000)
// If it's not an init message, give up
if msg.mtype != "init" { return }
// Handle the client depending on its type
switch msg.arguments["clientType"] {
case "user":
// Handle as a user
userHandler(sock)
case "display":
// Check that the display has provided its ID
if msg.arguments["dispID"] == nil { return }
// Handle as a display
displayHandler(sock, msg.arguments["dispID"].(string))
}
}