浏览器WebSocket的使用
Example:
if('WebSocket' in window){
var ws=new WebSocket(this.host?token=xxxxxxxx)
ws.onopen = function(){
console.log('opened')
};
ws.onmessage = function(evt){
try {
const evtData=JSON.parse(evt.data)
console.log(evtData)
}
catch(err){
console.log(evt.data)
}
};
ws.onclose = function(evt){
console.log('closed');
};
ws.onerror = function(evt){
console.log(evt)
};
}else{
alert("您的浏览器不支持此功能")
}