Ver Fonte

Merge branch 'master' of https://git.nanodreamtech.com/wkw/wallet_app

wkw há 4 dias atrás
pai
commit
128f4f5a50
3 ficheiros alterados com 16 adições e 5 exclusões
  1. 0 1
      src/App.vue
  2. 9 4
      src/utils/notifications.js
  3. 7 0
      src/views/im/hook/messagesHook.js

+ 0 - 1
src/App.vue

@@ -17,7 +17,6 @@
 import CallController from "@/views/im/components/CallController/index.vue";
 import { checkAndUpdate } from "@/updater/index";
 import { getNotchHeight } from "@/utils/statusBar";
-import { setupNotifications } from "@/utils/notifications.js";
 import { useWalletStore } from "@/stores/modules/walletStore";
 import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
 

+ 9 - 4
src/utils/notifications.js

@@ -25,12 +25,13 @@ const soundVoice = new Howl({
     console.error("加载失败:", error);
   },
 });
+let id = 1
 // 初始化通知监听
-export async function setupNotifications(id) {
+export async function setupNotifications(msgType) {
   // 检查权限
   const granted = await LocalNotifications.requestPermissions();
   if (!granted) return;
-
+  id += 1
   await LocalNotifications.schedule({
     notifications: [
       {
@@ -41,8 +42,12 @@ export async function setupNotifications(id) {
       },
     ],
   }); 
-  // 播放自定义声音
-  soundIm.play();
+  if(msgType == 1){
+    return  soundIm.play();
+  }
+  if(msgType == 2){
+    return  soundVoice.play();
+  }
 }
 // App 状态变化时处理
 App.addListener("appStateChange", ({ isActive }) => {

+ 7 - 0
src/views/im/hook/messagesHook.js

@@ -1,6 +1,7 @@
 import { useWebRTCStore } from "@/stores/modules/webrtcStore";
 import { MSG_TYPE, MSG_TYPE_MAP } from "@/common/constant/msgType";
 import * as Constant from "@/common/constant/Constant";
+import { setupNotifications } from "@/utils/notifications.js";
 
 // 发送消息处理
 export const setMessageHook = (message, state) => {
@@ -45,6 +46,8 @@ export const handleMessageHook = (message, state) => {
       ...message,
       toUsername: message.to,
     });
+    setupNotifications(1)
+    return
   }
   // 音频消息
   if (message.contentType === MSG_TYPE.AUDIO) {
@@ -58,6 +61,8 @@ export const handleMessageHook = (message, state) => {
       file: audioUrl,
       toUsername: message.to,
     });
+    setupNotifications(1)
+    return
   }
 
   // 图片
@@ -69,6 +74,8 @@ export const handleMessageHook = (message, state) => {
       file: url,
       toUsername: message.to,
     });
+    setupNotifications(1)
+    return
   }
   // 音频在线:拨号
   if (