add message in hub
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user