This commit is contained in:
aqu415
2022-02-15 21:06:02 +08:00
parent 2782fda765
commit 2c5db12e04
2 changed files with 9 additions and 3 deletions
+8 -3
View File
@@ -72,11 +72,13 @@
ws.onopen = function () {
//当WebSocket创建成功时,触发onopen事件
console.log("open");
ws.send("hello"); //将消息发送到服务端
ws.send(`{"h":"w"}`); //将消息发送到服务端
}
ws.onmessage = function (e) {
//当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
console.log(e.data);
// console.log(e.data);
console.log('onmessage:');
console.log(JSON.parse(e.data));
}
ws.onclose = function (e) {
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
@@ -142,7 +144,10 @@
param.data = data.join(';')
param.node = body.node
param.coop_mind_id = this.coop_mind_id
console.log(param)
// 序列化数据,处理特殊字符
const msg = Jm.util.json.json2string(param).replaceAll('\\n', '<br/>')
this._send_ws_message(msg)
}
},
_send_ws_message: function (msg) {