From 333cf981c94896ff42f826077791e69ede55730b Mon Sep 17 00:00:00 2001 From: Abdulhade Date: Fri, 14 Nov 2025 03:56:00 +0300 Subject: [PATCH] Created websocket signaler handler placeholder --- api/http_handler.go | 14 ++++++++++++-- api/ws_handler.go | 21 +++++++++++++++++++++ go.mod | 2 ++ go.sum | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 api/ws_handler.go diff --git a/api/http_handler.go b/api/http_handler.go index 6834ea9..34ea7af 100644 --- a/api/http_handler.go +++ b/api/http_handler.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/gorilla/mux" + "github.com/gorilla/websocket" ) 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) { - // This will create the websocket for the signaling service. vars := mux.Vars(r) party := vars["party"] 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) } diff --git a/api/ws_handler.go b/api/ws_handler.go new file mode 100644 index 0000000..e81645d --- /dev/null +++ b/api/ws_handler.go @@ -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 + } + } +} diff --git a/go.mod b/go.mod index 2113e65..a117d9a 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module echo go 1.22.2 require github.com/gorilla/mux v1.8.1 + +require github.com/gorilla/websocket v1.5.3 diff --git a/go.sum b/go.sum index 7128337..7ed87b7 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= 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=