export default {
  webSocket: Object,
  endData: Object,
  data: Object,
  type: 'a',
  baseUrl: 'ws://localhost:1818',
  runmessage: function (event) {
  },
  start: function (returnMsgFun, error) {
    try {
      this.webSocket = new WebSocket(this.baseUrl)
      let _this = this
      this.webSocket.onmessage = function (event) {
        _this.data = event
        _this.runmessage(event)
        if (typeof returnMsgFun === 'function') {
          console.log('999999')
          returnMsgFun(event)
        }
      }
      this.webSocket.onerror = function (event) {
        if (typeof error === 'function') {
          error({ data: '没有发现设备' })
        }
      }
    } catch (e) {
      let _this = this
      console.log('4444444')
      this.webSocket.onmessage = function (event) {
        _this.data = event
        _this.runmessage(event)
      }
      if (typeof error === 'function') {
        error({ data: '没有发现设备' })
      }
    }
  },
  cat: function () {
    this.endData = this.data
    // this.sendMsg('bStopPlay')
  },
  sendMsg: function (msg) {
    try {
      this.webSocket.send(msg)
    } catch (e) {
      console.log(e, '999999')
    }
  },
  over: function () {
    this.webSocket.send('bStopPlay()')
  },
  close: function () {
    this.webSocket.send('bStopPlay()')
  }
}
