Adapt With Close
This commit is contained in:
@@ -60,9 +60,21 @@ func (o *GeneralController) GetAll() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
func Websocket(user string, w http.ResponseWriter, r *http.Request) {
|
||||
func Websocket(user string, groups []string, dataType int, w http.ResponseWriter, r *http.Request) {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
defer ws.Close()
|
||||
defer func() {
|
||||
ws.Close()
|
||||
infrastructure.SearchMu.Lock()
|
||||
if ch, ok := infrastructure.SearchStream[user]; ok {
|
||||
close(ch)
|
||||
delete(infrastructure.SearchStream, user)
|
||||
}
|
||||
infrastructure.SearchMu.Unlock()
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CLOSE_SEARCH,
|
||||
DataType: dataType,
|
||||
})
|
||||
}()
|
||||
for msg := range infrastructure.SearchStream[user] {
|
||||
if websocket.JSON.Send(ws, msg) != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user