Adapt With Close

This commit is contained in:
mr
2026-03-12 16:20:47 +01:00
parent ad29297377
commit a11d764729
5 changed files with 30 additions and 7 deletions

View File

@@ -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