吉安感知网项目-前端
shuishen
2026-02-26 ae0398be3a751fd928d327f40ea4e68395813f1d
uniapps/work-app/src/hooks/useGlobalWS.js
@@ -15,6 +15,18 @@
  // 存储铃声实例
  let ringtoneInstance = null
  // 监听WebView消息事件
  if (typeof uni !== 'undefined' && uni.$on) {
    uni.$on('webViewMessage', (data) => {
      console.log('📨 useGlobalWS 收到 WebView 消息:', data)
      // 处理挂断消息
      if (data?.type === 'hangupVoice') {
        console.log('📞 收到挂断消息')
        initWS()
      }
    });
  }
  // 设置默认用户ID为3
  const defaultUserId = '2021474815063486465';
  // WebSocket基础URL
@@ -165,6 +177,7 @@
      return
    }
    recoverTimer = setInterval(() => {
      // console.log('shouldRecoverWS()',shouldRecoverWS(),'----------',websocketService.getConnected())
      if (shouldRecoverWS() && !websocketService.getConnected()) {
        initWS()
      }
@@ -172,6 +185,7 @@
  }
  function initWS() {
    websocketService.close()
    const userStore = useUserStore()
    accessToken.value =userStore?.userInfo.access_token
    if (!accessToken.value || isVoiceCallDetailActive()) {