aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/game/ws.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-04 22:55:01 +0900
committernsfisis <nsfisis@gmail.com>2025-03-08 10:12:44 +0900
commit1e6df136d8202c8adf65948527f4c3e7583b338c (patch)
tree7c82476f6bbbc71d72ab7e71e39559eca197fd95 /backend/game/ws.go
parent54316868c3bec1ff9b04643dfe6c13cf56bf3246 (diff)
downloadphperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.gz
phperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.zst
phperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.zip
websocket to polling
Diffstat (limited to 'backend/game/ws.go')
-rw-r--r--backend/game/ws.go73
1 files changed, 0 insertions, 73 deletions
diff --git a/backend/game/ws.go b/backend/game/ws.go
deleted file mode 100644
index 47dc7cf..0000000
--- a/backend/game/ws.go
+++ /dev/null
@@ -1,73 +0,0 @@
-package game
-
-import (
- "log"
- "net/http"
- "time"
-
- "github.com/gorilla/websocket"
-)
-
-const (
- writeWait = 10 * time.Second
- pongWait = 60 * time.Second
- pingPeriod = (pongWait * 9) / 10
- maxMessageSize = 50 * 1024
-)
-
-var upgrader = websocket.Upgrader{
- ReadBufferSize: 1024,
- WriteBufferSize: 1024,
- CheckOrigin: func(r *http.Request) bool {
- // TODO: insecure!
- _ = r
- return true
- },
-}
-
-func servePlayerWs(hub *gameHub, w http.ResponseWriter, r *http.Request, playerID int) error {
- conn, err := upgrader.Upgrade(w, r, nil)
- if err != nil {
- return err
- }
- player := &playerClient{
- hub: hub,
- conn: conn,
- s2cMessages: make(chan playerMessageS2C),
- playerID: playerID,
- }
- hub.registerPlayer <- player
-
- go func() {
- err := player.writePump()
- log.Printf("%v", err)
- }()
- go func() {
- err := player.readPump()
- log.Printf("%v", err)
- }()
- return nil
-}
-
-func serveWatcherWs(hub *gameHub, w http.ResponseWriter, r *http.Request) error {
- conn, err := upgrader.Upgrade(w, r, nil)
- if err != nil {
- return err
- }
- watcher := &watcherClient{
- hub: hub,
- conn: conn,
- s2cMessages: make(chan watcherMessageS2C),
- }
- hub.registerWatcher <- watcher
-
- go func() {
- err := watcher.writePump()
- log.Printf("%v", err)
- }()
- go func() {
- err := watcher.readPump()
- log.Printf("%v", err)
- }()
- return nil
-}