import Config from '@/config'
import Store from '@/store'

export const webSocket = {
  methods: {
    connectWebSocket(userId) {
      let webSocket = new WebSocket(`ws://139.224.24.90:8885/api/report/api/ws/`+userId)
      Store.commit('SET_WEB_SOCKET', webSocket)
      webSocket.onopen = () => {
        console.log('WebSocket连接成功')
      }
      // webSocket.onmessage = async (e) => {
      //   console.log(e)
      // }
      webSocket.onerror = () => {
        console.log('WebSocket连接失败')
      }
      webSocket.onclose = () => {
        console.log('WebSocket连接关闭')
      }
    }
  }
}

