Websocket stream control

This commit is contained in:
2024-07-14 23:45:18 +08:00
parent 82dd04f8aa
commit 8f996bb697
8 changed files with 424 additions and 8 deletions

View File

@@ -28,3 +28,15 @@ func ClientUnregister(user models.Account, conn *websocket.Conn) {
delete(wsConn[user.ID], conn)
wsMutex.Unlock()
}
func WebsocketPush(uid uint, body []byte) (count int, success int, errs []error) {
for conn := range wsConn[uid] {
if err := conn.WriteMessage(1, body); err != nil {
errs = append(errs, err)
} else {
success++
}
count++
}
return
}