//websocket连接
websocket(){
let that=this;
//是否支持websocket
if (!window.WebSocket) {
if (window.MozWebSocket) {
window.WebSocket = window.MozWebSocket;
} else {
that.$notify.error({
message: '您的浏览器不支持WebSockets'
});
}
}
that.This_ws = new WebSocket('ws://'+that.urlxx+'/match/ws?match_sn='+that.match_sn+'~pm');
//开始连接
that.This_ws.onopen = function (evt) {
console.log('开始连接');
ws.send("发送数据");
};
//接收消息
that.This_ws.onmessage = function (evt) {
let str = evt.data;
if (str != '') {
let backdata=JSON.parse(str);
console.log(backdata,"数据");
}
};
//断开连接
if(that.This_ws){
that.This_ws.onclose = function (evt) {
console.log('断开连接');
that.This_ws.close();
that.This_ws = null;
that.ws_state = false;
};
}
//连接出错
that.This_ws.onerror = function (evt) {
that.ws_state = false;
};
},