close ws gracefully to avoid stale joiners
This commit is contained in:
1 parent
1dad19e6b6
commit
c89688afd2
9 files changed
+32
-14
No files matched your search
@@ -0,0 +1,17 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func CloseWS(ws *websocket.Conn) {
|
||||
if ws == nil {
|
||||
return
|
||||
}
|
||||
ws.WriteControl(websocket.CloseMessage,
|
||||
websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""),
|
||||
time.Now().Add(time.Second))
|
||||
ws.Close()
|
||||
}
|
||||
Reference in new issue
Block a user