mirror of
https://github.com/AlexandreRouma/wiscast.git
synced 2026-04-20 08:22:42 +00:00
initial commit
This commit is contained in:
42
wshandler.go
Normal file
42
wshandler.go
Normal 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user