msg
This commit is contained in:
@@ -65,6 +65,7 @@
|
|||||||
},
|
},
|
||||||
// 初始化websocket
|
// 初始化websocket
|
||||||
_init_ws: function () {
|
_init_ws: function () {
|
||||||
|
const me = this
|
||||||
if (!this.web_socket && this.coop_mind_id) {
|
if (!this.web_socket && this.coop_mind_id) {
|
||||||
const ws = new WebSocket(this.coop_ws_url + '?_' + this.coop_mind_id)
|
const ws = new WebSocket(this.coop_ws_url + '?_' + this.coop_mind_id)
|
||||||
this.web_socket = ws
|
this.web_socket = ws
|
||||||
@@ -75,9 +76,7 @@
|
|||||||
}
|
}
|
||||||
ws.onmessage = function (e) {
|
ws.onmessage = function (e) {
|
||||||
//当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
|
//当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
|
||||||
// console.log(e.data);
|
me._oper_jsmind_with_ws_message(e.data)
|
||||||
console.log('onmessage:');
|
|
||||||
console.log(JSON.parse(e.data));
|
|
||||||
}
|
}
|
||||||
ws.onclose = function (e) {
|
ws.onclose = function (e) {
|
||||||
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
||||||
@@ -117,6 +116,10 @@
|
|||||||
_build_evt_param: function () {
|
_build_evt_param: function () {
|
||||||
return {'client_id': this.client_id, 'log_uuid': Jm.util.uuid.newid(), 'coop_mind_id': this.coop_mind_id}
|
return {'client_id': this.client_id, 'log_uuid': Jm.util.uuid.newid(), 'coop_mind_id': this.coop_mind_id}
|
||||||
},
|
},
|
||||||
|
// 调用jsmind接口
|
||||||
|
_oper_jsmind_with_ws_message: function (message) {
|
||||||
|
const msg_json = JSON.parse(message)
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* body:
|
* body:
|
||||||
* # {evt:'add_node',data:[parent_node.id,nodeid,topic,data],node:nodeid}
|
* # {evt:'add_node',data:[parent_node.id,nodeid,topic,data],node:nodeid}
|
||||||
@@ -130,17 +133,25 @@
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
js_mind_callback_: function (type, body) {
|
js_mind_callback_: function (type, body) {
|
||||||
|
|
||||||
const evt = body.evt
|
const evt = body.evt
|
||||||
if (!!evt) {
|
if (!!evt) {
|
||||||
const param = this._build_evt_param()
|
const param = this._build_evt_param()
|
||||||
Jm.util.json.merge(body, param)
|
Jm.util.json.merge(body, param)
|
||||||
|
|
||||||
// 序列化数据,处理特殊字符
|
// 序列化数据,处理特殊字符
|
||||||
const msg = Jm.util.json.json2string(body).replaceAll('\\n', '<br/>')
|
let msg = Jm.util.json.json2string(body)
|
||||||
|
msg = this.handle_spec_str(msg)
|
||||||
this._send_ws_message(msg)
|
this._send_ws_message(msg)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 处理特殊字符
|
||||||
|
handle_spec_str: function (msg) {
|
||||||
|
if (!!msg) {
|
||||||
|
return msg.replaceAll('\\n', '<br/>')
|
||||||
|
}
|
||||||
|
return msg
|
||||||
|
},
|
||||||
|
// 发送ws消息
|
||||||
_send_ws_message: function (msg) {
|
_send_ws_message: function (msg) {
|
||||||
if (this.web_socket) {
|
if (this.web_socket) {
|
||||||
this.web_socket.send(msg)
|
this.web_socket.send(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user