1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // export default {
- // ws:{},
- // setWs: function(newWs) {
- // this.ws = newWs
- // }
- // }
- // // <!--引入store,用于管理socket推送来的消息-->
- // import store from '../store'
- // // <!--封装websocket对象-->
- // const WS = {
- // $ws:null, // webscoket实例
- // wsUrl: 'http://132.232.92.186:8888/api/chatHub', // websocket链接地址
- // // <!--初始化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')
- // }
- // },
- // // <!--webSocket 打开-->
- // wsOpen:function() {
- // this.$ws.send('连接成功')
- // console.log('== websocket open ==')
- // // <!--开始心跳-->
- // heartBeat.start()
- // },
- // // <!--websocket 接收到服务器消息-->
- // wsMessage:function(msg) {
- // console.log('== websocket message ==', msg)
- // // <!--接受到消息,重置心跳-->
- // heartBeat.reset()
- // store.commit('SET_WS_MSG', msg.data)
- // },
- // // <!--websocket 发生错误-->
- // wsError: function(err){
- // console.log('== websocket error ==', err)
- // },
- // // <!--websocket 关闭连接-->
- // wsClose: function(event){
- // console.log('== websocket close ==', event)
- // }
- // }
- // // <!--webSocket 心跳-->
- // 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
|