From c3d4e6e1f91599354310e3ffe9712fd0612a690f Mon Sep 17 00:00:00 2001 From: "630892807@qq.com" <630892807@qq.com> Date: Mon, 8 Mar 2021 22:01:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ws/user.go | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/ws/user.go b/ws/user.go index 12063ce..7d6c9da 100644 --- a/ws/user.go +++ b/ws/user.go @@ -71,34 +71,6 @@ func AddKefuToList(kefu *User) { KefuList[kefu.Id] = newKefuConns } -//后端广播发送消息 -func kefuServerBackend() { - for { - message := <-message - var typeMsg TypeMessage - json.Unmarshal(message.content, &typeMsg) - conn := message.conn - if typeMsg.Type == nil || typeMsg.Data == nil { - continue - } - msgType := typeMsg.Type.(string) - log.Println("客户端:", string(message.content)) - - switch msgType { - //心跳 - case "ping": - msg := TypeMessage{ - Type: "pong", - } - str, _ := json.Marshal(msg) - Mux.Lock() - conn.WriteMessage(websocket.TextMessage, str) - Mux.Unlock() - } - - } -} - //给超管发消息 func SuperAdminMessage(str []byte) { return @@ -117,11 +89,11 @@ func OneKefuMessage(toId string, str []byte) { //新版 mKefuConns, ok := KefuList[toId] if mKefuConns != nil && ok { - log.Println("OneKefuMessage lock") - Mux.Lock() - defer Mux.Unlock() - log.Println("OneKefuMessage unlock") for _, kefu := range mKefuConns { + log.Println("OneKefuMessage lock") + Mux.Lock() + defer Mux.Unlock() + log.Println("OneKefuMessage unlock") kefu.Conn.WriteMessage(websocket.TextMessage, str) } }