Created websocket signaler handler placeholder

This commit is contained in:
2025-11-14 03:56:00 +03:00
parent 5791786a9f
commit 333cf981c9
4 changed files with 37 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/websocket"
) )
func ping(w http.ResponseWriter, r *http.Request) { func ping(w http.ResponseWriter, r *http.Request) {
@@ -28,13 +29,22 @@ func createSession(w http.ResponseWriter, r *http.Request) {
`) `)
} }
var upgrader = websocket.Upgrader{}
func signalWS(w http.ResponseWriter, r *http.Request) { func signalWS(w http.ResponseWriter, r *http.Request) {
// This will create the websocket for the signaling service.
vars := mux.Vars(r) vars := mux.Vars(r)
party := vars["party"] party := vars["party"]
session := vars["session"] session := vars["session"]
fmt.Printf("Initiating a websocket, party=%s session=%s", party, session) fmt.Printf("Initiating a websocket, party=%s session=%s\n", party, session)
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
fmt.Printf("Error initiating websocket, r.URL=%s e=%s", r.URL.String(), err)
}
websocketSignaler(conn)
} }

21
api/ws_handler.go Normal file
View File

@@ -0,0 +1,21 @@
package api
import "github.com/gorilla/websocket"
func websocketSignaler(conn *websocket.Conn) {
defer conn.Close()
for {
msgType, msg, err := conn.ReadMessage()
if err != nil {
return
}
// Let's just echo for now as a placeholder
err = conn.WriteMessage(msgType, msg)
if err != nil {
return
}
}
}

2
go.mod
View File

@@ -3,3 +3,5 @@ module echo
go 1.22.2 go 1.22.2
require github.com/gorilla/mux v1.8.1 require github.com/gorilla/mux v1.8.1
require github.com/gorilla/websocket v1.5.3

2
go.sum
View File

@@ -1,2 +1,4 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=