var url =‘wss://localhost:8131/elevator_abeyance/websocket/bi?token=.eyJhdWQiOiIxMzEiLCJleHAiOjE2NjE5OTYzNTF9.3WCpDIx0ui1dcZvw_IFLIabnWC-XOKkktDlV_GNJhb8’
socket = new WebSocket(url);
console.log(socket, 'socket 实例----')
socket.onopen = function(){
console.log('连接上了')
window.alert('连接上了')
socket.send(JSON.stringify({"keyline":"1524688836977201090","socketType":"02"}))
//socket.send(JSON.stringify({"keyline":"1524688836977201052","socketType":"01"}))
//socket.send(JSON.stringify({"keyline":"1524688836987202222","socketType":"03"}))
//socket.send(JSON.stringify({"device_ID":"31105001162017050721,31104403002018002323","request_Type":"RTC"}))
}
socket.onmessage = function(event){
console.log('传递的信息')
console.log(event)
}
//心跳检测
var heartCheck = {
timeout: 120000,
timeoutObj: null,
serverTimeoutObj: null,
start: function () {
console.log(‘start’);
var self = this;
this.timeoutObj && clearTimeout(this.timeoutObj);
this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
this.timeoutObj = setTimeout(function () {
//发送测试信息,后端收到后,返回一个消息,
websocket.send(JSON.stringify({“keyline”:“1524688836977201090”,“socketType”:“02”}));
self.serverTimeoutObj = setTimeout(function () {
//websocket.close();
}, self.timeout);
}, this.timeout)
}
}