吉安感知网项目-前端
张含笑
2026-02-26 da1046b20b988f751038c8021b6e64c770e5c076
feat:去掉铃声
3 files modified
108 ■■■■ changed files
applications/mobile-web-view/src/appPages/voiceCallDetail/index.vue 12 ●●●● patch | view | raw | blame | history
uniapps/work-app/src/hooks/useGlobalWS.js 90 ●●●● patch | view | raw | blame | history
uniapps/work-app/src/subPackages/voiceCallDetail/index.vue 6 ●●●● patch | view | raw | blame | history
applications/mobile-web-view/src/appPages/voiceCallDetail/index.vue
@@ -449,8 +449,8 @@
    log('✅ 已点击接听,发送 accept 给', incomingFrom)
    // 停止铃声
    const transmitData = { data: { type: 'stopVoice' } }
uni.postMessage(transmitData)
//     const transmitData = { data: { type: 'stopVoice' } }
// uni.postMessage(transmitData)
    state.value = 'calling'
    // 如果 offer 已经提前到达(我们暂存了),立刻 answer
@@ -468,8 +468,8 @@
    log('❌ 已拒绝来电,发送 busy 给', incomingFrom)
    // 停止铃声
    const transmitData = { data: { type: 'stopVoice' } }
uni.postMessage(transmitData)
//     const transmitData = { data: { type: 'stopVoice' } }
// uni.postMessage(transmitData)
    incomingFrom = null
    acceptedByMe = false
@@ -522,8 +522,8 @@
function hangup() {
    // 停止铃声
    const transmitData = { data: { type: 'stopVoice' } }
uni.postMessage(transmitData)
//     const transmitData = { data: { type: 'stopVoice' } }
// uni.postMessage(transmitData)
    cleanup(true)
}
uniapps/work-app/src/hooks/useGlobalWS.js
@@ -1,8 +1,9 @@
import { useUserStore } from "@/store/index.js";
import useAppStore from "../store/modules/app/index.js";
import websocketService from "@/utils/websocket.js";
// #ifdef APP-PLUS
import { openDialog, allowFloat, getBatteryCapacity } from '@/uni_modules/lgh-dialog'
// #endif
export function useGlobalWS() {
    const userStore = useUserStore();
  const appStore = useAppStore();
@@ -27,7 +28,7 @@
    if (t === 'call') {
      console.log('📞 全局收到来电 call,来自', payload.from)
      // 播放铃声
      playRingtone();
      // playRingtone();
      // 触发震动
      triggerVibration();
      // 构建来电参数
@@ -36,8 +37,9 @@
        from: payload.from,
        type: 'incoming'
      };
// #ifdef APP-PLUS
            openDialog()
      // #endif
      // 转义参数以便在URL中传递
      const encodedParams = encodeURIComponent(JSON.stringify(callParams));
@@ -58,21 +60,21 @@
  }
  // 播放来电铃声 - 定义在 messageHandler 外部
  function playRingtone() {
    try {
      if (typeof uni !== 'undefined' && uni.createInnerAudioContext) {
        const ringtone = uni.createInnerAudioContext();
        // 使用默认铃声,注意路径写法
        ringtone.src = '/static/audio/ringtone.mp3';
        ringtone.loop = true;
        ringtone.volume = 0.8;
        ringtone.play();
        // 存储铃声实例
        ringtoneInstance = ringtone; // 使用局部变量而不是window
      }
    } catch (error) {
    }
  }
  // function playRingtone() {
  //   try {
  //     if (typeof uni !== 'undefined' && uni.createInnerAudioContext) {
  //       const ringtone = uni.createInnerAudioContext();
  //       // 使用默认铃声,注意路径写法
  //       ringtone.src = '/static/audio/ringtone.mp3';
  //       ringtone.loop = true;
  //       ringtone.volume = 0.8;
  //       ringtone.play();
  //       // 存储铃声实例
  //       ringtoneInstance = ringtone; // 使用局部变量而不是window
  //     }
  //   } catch (error) {
  //   }
  // }
  // 触发震动
  function triggerVibration() {
@@ -113,32 +115,32 @@
  }
  // 停止铃声
  function stopRingtone() {
    try {
      if (ringtoneInstance) {
        ringtoneInstance.stop();
        ringtoneInstance.destroy();
        ringtoneInstance = null;
      }
    } catch (error) {
      // 即使出错也重置实例
      ringtoneInstance = null;
    }
  }
  // 监听停止铃声事件
  if (typeof uni !== 'undefined' && uni.$on) {
    uni.$on('stopRingtone', stopRingtone);
    // 监听WebView消息事件
    uni.$on('webViewMessage', (data) => {
      // 检查是否是停止铃声消息
      if (data?.type === 'stopVoice') {
        stopRingtone();
        console.log('📳 收到WebView停止铃声消息,已停止铃声');
      }
    });
  }
  // function stopRingtone() {
  //   try {
  //     if (ringtoneInstance) {
  //       ringtoneInstance.stop();
  //       ringtoneInstance.destroy();
  //       ringtoneInstance = null;
  //     }
  //   } catch (error) {
  //     // 即使出错也重置实例
  //     ringtoneInstance = null;
  //   }
  // }
  //
  // // 监听停止铃声事件
  // if (typeof uni !== 'undefined' && uni.$on) {
  //   uni.$on('stopRingtone', stopRingtone);
  //   // 监听WebView消息事件
  //   uni.$on('webViewMessage', (data) => {
  //     // 检查是否是停止铃声消息
  //     if (data?.type === 'stopVoice') {
  //       stopRingtone();
  //       console.log('📳 收到WebView停止铃声消息,已停止铃声');
  //
  //     }
  //   });
  // }
  // 初始化WebSocket连接
  function initWS() {
uniapps/work-app/src/subPackages/voiceCallDetail/index.vue
@@ -79,9 +79,9 @@
function onPostMessage(data) {
    // 将WebView消息传递给全局WebSocket处理
    if (typeof uni !== 'undefined' && uni.$emit) {
        uni.$emit('webViewMessage', data);
    }
    // if (typeof uni !== 'undefined' && uni.$emit) {
    //     uni.$emit('webViewMessage', data);
    // }
}
</script>