add message in hub

This commit is contained in:
2026-04-28 20:17:37 +02:00
parent 79219971d0
commit a49f9f4615
18 changed files with 2125 additions and 51 deletions
+17
View File
@@ -2,6 +2,7 @@ package wsServer
import (
"context"
json2 "encoding/json"
"errors"
"log"
"net/http"
@@ -14,6 +15,7 @@ import (
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
"github.com/google/uuid"
)
func ServeWsConnection(responseWriter http.ResponseWriter, request *http.Request) {
@@ -74,6 +76,21 @@ func WsSendMessageCloseIfTimeout(user *types.User, message any) {
}
}
func WsSendMessageToMultipleCloseIfTimeout(users *[]types.User, excludeId uuid.UUID, message any) {
json, err := json2.Marshal(message)
if err != nil {
log.Printf("json marshal error: %v", err)
json = []byte{}
}
for _, user := range *users {
if user.Id != excludeId {
WsSendMessageCloseIfTimeout(&user, json)
}
}
}
func sendToAllMessageCloseIfTimeout(message *map[string]any) {
cache.Mu.RLock()
users := make([]*types.User, 0, len(cache.Users))