Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 632d79dd57 | |||
| b296d73367 |
@@ -294,6 +294,11 @@ func (wsClient *SafeWebsocketClient) reconnectHandler() {
|
|||||||
default: // prevent blocking if chan is full
|
default: // prevent blocking if chan is full
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(wsClient.reconnectChans) > 1 {
|
||||||
|
wsClient.reconnectChans = wsClient.reconnectChans[1:]
|
||||||
|
} else {
|
||||||
|
wsClient.reconnectChans = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-wsClient.ctx.Done():
|
case <-wsClient.ctx.Done():
|
||||||
log.Println("reconnect handler stopped due to client shutdown")
|
log.Println("reconnect handler stopped due to client shutdown")
|
||||||
|
|||||||
@@ -64,10 +64,12 @@ func (b *SafeWebsocketServerBuilder) HandleFunc(pattern string, fn func(http.Res
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscribedPath string, writeFunc func(chan []byte)) *SafeWebsocketServerBuilder {
|
func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscribedPath string, writeFunc func(writeChannel chan []byte)) *SafeWebsocketServerBuilder {
|
||||||
h := internal.NewHub()
|
h := internal.NewHub()
|
||||||
h.Run()
|
h.Run()
|
||||||
|
|
||||||
|
go writeFunc(h.Broadcast)
|
||||||
|
|
||||||
b.mux.HandleFunc(pattern+subscribedPath, func(w http.ResponseWriter, r *http.Request) {
|
b.mux.HandleFunc(pattern+subscribedPath, func(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, err := b.upgrader.Upgrade(w, r, nil)
|
conn, err := b.upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,7 +87,7 @@ func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscri
|
|||||||
|
|
||||||
go internal.WritePump(c, h)
|
go internal.WritePump(c, h)
|
||||||
go internal.ReadPump(c, h)
|
go internal.ReadPump(c, h)
|
||||||
go writeFunc(h.Broadcast)
|
|
||||||
})
|
})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user