@@ -198,8 +198,14 @@ func IsTryingToReconnect(err error) (ok bool) {
198
198
const websocketReconectHeaderKey = "X-Websocket-Reconnect"
199
199
200
200
// Upgrade handles the connection, same as `ServeHTTP` but it can accept
201
- // a socket wrapper and it does return the connection or any errors.
202
- func (s * Server ) Upgrade (w http.ResponseWriter , r * http.Request , socketWrapper func (Socket ) Socket ) (* Conn , error ) {
201
+ // a socket wrapper and a "customID" that overrides the server's IDGenerator
202
+ // and it does return the connection or any errors.
203
+ func (s * Server ) Upgrade (
204
+ w http.ResponseWriter ,
205
+ r * http.Request ,
206
+ socketWrapper func (Socket ) Socket ,
207
+ customID string ,
208
+ ) (* Conn , error ) {
203
209
if atomic .LoadUint32 (& s .closed ) > 0 {
204
210
http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
205
211
return nil , errServerClosed
@@ -237,7 +243,12 @@ func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, socketWrapper f
237
243
}
238
244
239
245
c := newConn (socket , s .namespaces )
240
- c .id = s .IDGenerator (w , r )
246
+ if customID != "" {
247
+ c .id = customID
248
+ } else {
249
+ c .id = s .IDGenerator (w , r )
250
+ }
251
+
241
252
c .readTimeout = s .readTimeout
242
253
c .writeTimeout = s .writeTimeout
243
254
c .server = s
@@ -298,7 +309,7 @@ func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, socketWrapper f
298
309
// ServeHTTP completes the `http.Handler` interface, it should be passed on a http server's router
299
310
// to serve this neffos server on a specific endpoint.
300
311
func (s * Server ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
301
- s .Upgrade (w , r , nil )
312
+ s .Upgrade (w , r , nil , "" )
302
313
}
303
314
304
315
func (s * Server ) waitMessage (c * Conn ) bool {
0 commit comments