吉安感知网项目-前端
chenyao
3 days ago a53ece5036c1fa61a63fe5f9e0cd3519210ab928
uniapps/work-app/src/utils/websocket.js
@@ -50,7 +50,7 @@
      this.socketTask.onOpen(() => {
        this.connected = true
        // console.log('WebSocket已连接,userId:', this.userId)
        this.startPing()
        // this.startPing()
        if (this.onOpenCallback) {
          this.onOpenCallback()
        }
@@ -114,8 +114,8 @@
    this.socketTask.send({
      data: JSON.stringify(message),
      success: () => {
        // console.log('WebSocket消息发送成功:', message)
        useGlobalWS();
        console.log('WebSocket消息发送成功:', message)
        // useGlobalWS();
      },
      fail: (error) => {
        // console.error('WebSocket消息发送失败:', error)
@@ -124,15 +124,15 @@
  }
  // 开始心跳检测
  startPing() {
    this.stopPing()
    // 每25秒发送一次心跳
    this.pingTimer = setInterval(() => {
      if (this.connected) {
        this.send('ping', 'system')
      }
    }, 25000)
  }
  // startPing() {
  //   this.stopPing()
  //   // 每25秒发送一次心跳
  //   this.pingTimer = setInterval(() => {
  //     if (this.connected) {
  //       this.send('ping', 'system')
  //     }
  //   }, 25000)
  // }
  // 停止心跳检测
  stopPing() {