// export default { // ws:{}, // setWs: function(newWs) { // this.ws = newWs // } // } // // // import store from '../store' // // // const WS = { // $ws:null, // webscoket实例 // wsUrl: 'http://132.232.92.186:8888/api/chatHub', // websocket链接地址 // // // createWS:function(){ // if('WebSocket' in window){ // this.$ws = new WebSocket(this.wsURl) // this.$ws.onopen = this.wsOpen // this.$ws.onmessage = this.wsMessage // this.$ws.onerror = this.wsError // this.$ws.onclose = this.wsClose // } else { // alert('当前浏览器不支持webSocket') // } // }, // // // wsOpen:function() { // this.$ws.send('连接成功') // console.log('== websocket open ==') // // // heartBeat.start() // }, // // // wsMessage:function(msg) { // console.log('== websocket message ==', msg) // // // heartBeat.reset() // store.commit('SET_WS_MSG', msg.data) // }, // // // wsError: function(err){ // console.log('== websocket error ==', err) // }, // // // wsClose: function(event){ // console.log('== websocket close ==', event) // } // } // // // const heartBeat = { // timeout:3000, // 心跳重连时间 // timeoutObj:null, // 定时器 // reset:function(){ // clearInterval(this.timeoutObj) // console.log('websocket 心跳') // WS.start() // }, // start:function(){ // this.timeoutObj = setTimeout(function(){ // if(WS.$ws.readyState === 1){ // WS.$ws.send('HeartBeat') // } // },this.timeout) // } // } // export default WS