@@ -40,10 +40,10 @@ func RunWebSocketServer(listener net.Listener) {
40
40
Handler : gr ,
41
41
}
42
42
server .SetKeepAlivesEnabled (false )
43
- log .Printf ("Running websocket server on %s\n " , listener .Addr ())
43
+ log .Printf ("[websocket] running websocket server on %s\n " , listener .Addr ())
44
44
err := server .Serve (listener )
45
45
if err != nil {
46
- log .Printf ("[error] trying to run websocket server: %v\n " , err )
46
+ log .Printf ("[websocket] error trying to run websocket server: %v\n " , err )
47
47
}
48
48
}
49
49
@@ -81,7 +81,7 @@ func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []
81
81
r := recover ()
82
82
if r != nil {
83
83
rtnErr = fmt .Errorf ("panic: %v" , r )
84
- log .Printf ("panic in processMessage: %v\n " , r )
84
+ log .Printf ("[websocket] panic in processMessage: %v\n " , r )
85
85
debug .PrintStack ()
86
86
}
87
87
if rtnErr == nil {
@@ -108,7 +108,7 @@ func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []
108
108
msgBytes , err := json .Marshal (rpcMsg )
109
109
if err != nil {
110
110
// this really should never fail since we just unmarshalled this value
111
- log .Printf ("error marshalling rpc message: %v\n " , err )
111
+ log .Printf ("[websocket] error marshalling rpc message: %v\n " , err )
112
112
return
113
113
}
114
114
rpcInputCh <- msgBytes
@@ -125,7 +125,7 @@ func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []
125
125
msgBytes , err := json .Marshal (rpcMsg )
126
126
if err != nil {
127
127
// this really should never fail since we just unmarshalled this value
128
- log .Printf ("error marshalling rpc message: %v\n " , err )
128
+ log .Printf ("[websocket] error marshalling rpc message: %v\n " , err )
129
129
return
130
130
}
131
131
rpcInputCh <- msgBytes
@@ -152,21 +152,21 @@ func processMessage(jmsg map[string]any, outputCh chan any, rpcInputCh chan []by
152
152
processWSCommand (jmsg , outputCh , rpcInputCh )
153
153
}
154
154
155
- func ReadLoop (conn * websocket.Conn , outputCh chan any , closeCh chan any , rpcInputCh chan []byte ) {
155
+ func ReadLoop (conn * websocket.Conn , outputCh chan any , closeCh chan any , rpcInputCh chan []byte , routeId string ) {
156
156
readWait := wsReadWaitTimeout
157
157
conn .SetReadLimit (64 * 1024 )
158
158
conn .SetReadDeadline (time .Now ().Add (readWait ))
159
159
defer close (closeCh )
160
160
for {
161
161
_ , message , err := conn .ReadMessage ()
162
162
if err != nil {
163
- log .Printf ("ReadPump error: %v\n " , err )
163
+ log .Printf ("[websocket] ReadPump error (%s) : %v\n " , routeId , err )
164
164
break
165
165
}
166
166
jmsg := map [string ]any {}
167
167
err = json .Unmarshal (message , & jmsg )
168
168
if err != nil {
169
- log .Printf ("Error unmarshalling json: %v\n " , err )
169
+ log .Printf ("[websocket] error unmarshalling json: %v\n " , err )
170
170
break
171
171
}
172
172
conn .SetReadDeadline (time .Now ().Add (readWait ))
@@ -197,7 +197,7 @@ func WritePing(conn *websocket.Conn) error {
197
197
return nil
198
198
}
199
199
200
- func WriteLoop (conn * websocket.Conn , outputCh chan any , closeCh chan any ) {
200
+ func WriteLoop (conn * websocket.Conn , outputCh chan any , closeCh chan any , routeId string ) {
201
201
ticker := time .NewTicker (wsInitialPingTime )
202
202
defer ticker .Stop ()
203
203
initialPing := true
@@ -211,22 +211,22 @@ func WriteLoop(conn *websocket.Conn, outputCh chan any, closeCh chan any) {
211
211
} else {
212
212
barr , err = json .Marshal (msg )
213
213
if err != nil {
214
- log .Printf ("cannot marshal websocket message: %v\n " , err )
214
+ log .Printf ("[websocket] cannot marshal websocket message: %v\n " , err )
215
215
// just loop again
216
216
break
217
217
}
218
218
}
219
219
err = conn .WriteMessage (websocket .TextMessage , barr )
220
220
if err != nil {
221
221
conn .Close ()
222
- log .Printf ("WritePump error: %v\n " , err )
222
+ log .Printf ("[websocket] WritePump error (%s) : %v\n " , routeId , err )
223
223
return
224
224
}
225
225
226
226
case <- ticker .C :
227
227
err := WritePing (conn )
228
228
if err != nil {
229
- log .Printf ("WritePump error: %v\n " , err )
229
+ log .Printf ("[websocket] WritePump error (%s) : %v\n " , routeId , err )
230
230
return
231
231
}
232
232
if initialPing {
@@ -250,6 +250,7 @@ func HandleWsInternal(w http.ResponseWriter, r *http.Request) error {
250
250
if err != nil {
251
251
w .WriteHeader (http .StatusUnauthorized )
252
252
w .Write ([]byte (fmt .Sprintf ("error validating authkey: %v" , err )))
253
+ log .Printf ("[websocket] error validating authkey: %v\n " , err )
253
254
return err
254
255
}
255
256
conn , err := WebSocketUpgrader .Upgrade (w , r , nil )
@@ -258,7 +259,6 @@ func HandleWsInternal(w http.ResponseWriter, r *http.Request) error {
258
259
}
259
260
defer conn .Close ()
260
261
wsConnId := uuid .New ().String ()
261
- log .Printf ("New websocket connection: windowid:%s connid:%s\n " , windowId , wsConnId )
262
262
outputCh := make (chan any , 100 )
263
263
closeCh := make (chan any )
264
264
eventbus .RegisterWSChannel (wsConnId , windowId , outputCh )
@@ -269,6 +269,7 @@ func HandleWsInternal(w http.ResponseWriter, r *http.Request) error {
269
269
routeId = wshutil .MakeWindowRouteId (windowId )
270
270
}
271
271
defer eventbus .UnregisterWSChannel (wsConnId )
272
+ log .Printf ("[websocket] new connection: windowid:%s connid:%s routeid:%s\n " , windowId , wsConnId , routeId )
272
273
// we create a wshproxy to handle rpc messages to/from the window
273
274
wproxy := wshutil .MakeRpcProxy ()
274
275
wshutil .DefaultRouter .RegisterRoute (routeId , wproxy )
@@ -293,12 +294,12 @@ func HandleWsInternal(w http.ResponseWriter, r *http.Request) error {
293
294
go func () {
294
295
// read loop
295
296
defer wg .Done ()
296
- ReadLoop (conn , outputCh , closeCh , wproxy .FromRemoteCh )
297
+ ReadLoop (conn , outputCh , closeCh , wproxy .FromRemoteCh , routeId )
297
298
}()
298
299
go func () {
299
300
// write loop
300
301
defer wg .Done ()
301
- WriteLoop (conn , outputCh , closeCh )
302
+ WriteLoop (conn , outputCh , closeCh , routeId )
302
303
}()
303
304
wg .Wait ()
304
305
close (wproxy .FromRemoteCh )
0 commit comments