清除ws发信息代码

pull/30/head
taoshihan1991 4 years ago
parent 30ac128a5f
commit f3420db5d4

@ -279,58 +279,6 @@ func singleBroadcaster(){
continue continue
} }
SendKefuOnline(clientMsg, visitor.conn) 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": case "ping":
msg := TypeMessage{ msg := TypeMessage{

@ -198,17 +198,20 @@
return; return;
} }
let _this=this;
let mes = {}; let mes = {};
mes.type = "chatMessage"; mes.type = "visitor";
mes.content = this.messageContent;
guest.content = this.messageContent; mes.from_id = guest.id;
mes.data = guest; mes.to_id = guest.to_id;
this.socket.send(JSON.stringify(mes)); mes.content = this.messageContent;
this.messageContent = ""; $.post("/message",mes,function(){
_this.messageContent = "";
});
let content = {} let content = {}
content.avator=guest.avator; content.avator=guest.avator;
content.content = guest.content; content.content = this.messageContent;
content.name = guest.name; content.name = guest.name;
content.is_kefu = true; content.is_kefu = true;
content.time = this.getNowDate(); content.time = this.getNowDate();

Loading…
Cancel
Save