add files and ci
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m34s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m34s
This commit is contained in:
34
main.go
Normal file
34
main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
var room = NewRoom()
|
||||
|
||||
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
peer := NewPeer(conn)
|
||||
room.AddPeer(peer)
|
||||
log.Println("peer added", conn.LocalAddr().String())
|
||||
|
||||
go peer.ReadLoop()
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/ws", wsHandler)
|
||||
|
||||
log.Println("listening on :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
Reference in New Issue
Block a user