From f3420db5d4bf5598ceb787cd29b8afdba694c59f Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Thu, 23 Jul 2020 17:48:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E9=99=A4ws=E5=8F=91=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/chat.go | 52 -------------------------------------- static/html/chat_page.html | 17 ++++++++----- 2 files changed, 10 insertions(+), 59 deletions(-) diff --git a/controller/chat.go b/controller/chat.go index 0f06215..9f5fa53 100644 --- a/controller/chat.go +++ b/controller/chat.go @@ -279,58 +279,6 @@ func singleBroadcaster(){ continue } SendKefuOnline(clientMsg, visitor.conn) - case "kfChatMessage": - json.Unmarshal(msgData, &clientMsg) - models.CreateMessage(clientMsg.Id,clientMsg.ToId,clientMsg.Content,"kefu") - guest,ok:=clientList[clientMsg.ToId] - if guest==nil||!ok{ - continue - } - conn := guest.conn - - msg := TypeMessage{ - Type: "message", - Data: ClientMessage{ - Name: clientMsg.Name, - Avator: clientMsg.Avator, - Id: clientMsg.Id, - Time: time.Now().Format("2006-01-02 15:04:05"), - ToId: clientMsg.ToId, - Content: clientMsg.Content, - }, - } - str, _ := json.Marshal(msg) - conn.WriteMessage(websocket.TextMessage,str) - //kefuConns,ok := kefuList[clientMsg.Id] - //if kefuConns==nil||!ok{ - // continue - //} - //for _,kefuConn:=range kefuConns{ - // kefuConn.WriteMessage(websocket.TextMessage,str) - //} - - case "chatMessage": - json.Unmarshal(msgData, &clientMsg) - models.CreateMessage(clientMsg.ToId,clientMsg.Id,clientMsg.Content,"visitor") - kefuConns,ok := kefuList[clientMsg.ToId] - if kefuConns==nil||!ok{ - continue - } - msg := TypeMessage{ - Type: "message", - Data: ClientMessage{ - Avator: clientMsg.Avator, - Id: clientMsg.Id, - Name: clientMsg.Name, - ToId: clientMsg.ToId, - Content: clientMsg.Content, - Time: time.Now().Format("2006-01-02 15:04:05"), - }, - } - str, _ := json.Marshal(msg) - for _,kefuConn:=range kefuConns{ - kefuConn.WriteMessage(websocket.TextMessage,str) - } //心跳 case "ping": msg := TypeMessage{ diff --git a/static/html/chat_page.html b/static/html/chat_page.html index d7e1a69..744ec88 100644 --- a/static/html/chat_page.html +++ b/static/html/chat_page.html @@ -198,17 +198,20 @@ return; } + let _this=this; let mes = {}; - mes.type = "chatMessage"; - - guest.content = this.messageContent; - mes.data = guest; - this.socket.send(JSON.stringify(mes)); - this.messageContent = ""; + mes.type = "visitor"; + mes.content = this.messageContent; + mes.from_id = guest.id; + mes.to_id = guest.to_id; + mes.content = this.messageContent; + $.post("/message",mes,function(){ + _this.messageContent = ""; + }); let content = {} content.avator=guest.avator; - content.content = guest.content; + content.content = this.messageContent; content.name = guest.name; content.is_kefu = true; content.time = this.getNowDate();