WXL
2025-01-15 1cb1fbf80c955986385377b5f84e8915d1e655d6
src/websocket/websocket.js
@@ -16,7 +16,7 @@
 * 发起websocket连接
 * @param {Object} agentData 需要向后台传递的参数数据
 */
function websocketSend (agentData) {
export function websocketSend (agentData) {
  // 加延迟是为了尽量让ws连接状态变为OPEN   
  setTimeout(() => { 
    // 添加状态判断,当为OPEN时,发送消息
@@ -24,6 +24,7 @@
      // 发给后端的数据需要字符串化
      websock.send(JSON.stringify(agentData))
      console.log('连接成功');
    }
    if (websock.readyState === websock.CLOSED) { // websock.CLOSED = 3 
      console.log('websock.readyState=3')
@@ -55,7 +56,7 @@
}
// 建立ws连接
function websocketOpen (e) {
  // console.log('ws连接成功')
  console.log('ws连接成功')
}
 
// 初始化weosocket
@@ -70,10 +71,11 @@
//   const requstWsUrl = wsUrl + '?' + token
  const requstWsUrl = wsUrl
  websock = new WebSocket(requstWsUrl)
  websock.onmessage = function (e) {
    console.log('websocketonMessage');
    websocketonmessage(e)
  } 
  websock.onopen = function () {
    websocketOpen()
  }