liming 2 days ago
parent
commit
7d9efe539a

+ 5 - 10
src/App.vue

@@ -14,12 +14,12 @@
 </template>
 
 <script setup>
+import { LocalNotifications } from "@capacitor/local-notifications";
 import CallController from "@/views/im/components/CallController/index.vue";
 import { checkAndUpdate } from "@/updater/index";
 import { getNotchHeight } from "@/utils/statusBar";
 import { useWalletStore } from "@/stores/modules/walletStore";
-import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
-
+import { useWebSocketStore } from "@/stores/modules/webSocketStore.js"; 
 const route = useRoute();
 const router = useRouter();
 
@@ -69,10 +69,8 @@ onBeforeMount(async () => {
 });
 
 onMounted(() => {
-  // 0.5秒后执行
-  // setTimeout(() => {
-  //    setupNotifications(2);
-  // }, 500);
+  LocalNotifications.requestPermissions()
+  
   // setTimeout(() => {
   //    setupNotifications(3);
   // }, 500);
@@ -84,10 +82,7 @@ onMounted(() => {
   // }, 500);
   //  setTimeout(() => {
   //    setupNotifications(5);
-  // }, 2500);
-  //  setTimeout(() => {
-  //    setupNotifications(15);
-  // }, 1500);
+  // }, 2500); 
   // setupNotifications(5);
   // setupNotifications(6);
 });

+ 3 - 3
src/common/WebSocketService.js

@@ -6,9 +6,9 @@ export default  class WebSocketService {
     this.heartbeatTimer = null;
     this.heartbeatInterval = 30000; // 30秒
     // 重连次数
-    this.reconnectAttempts = 0;
-    this.maxReconnectAttempts = 5;
-    this.reconnectInterval = 5000; // 5
+    this.reconnectAttempts = 50; // 默认重连次数
+    this.maxReconnectAttempts = 100; // 最大重连次数
+    this.reconnectInterval = 2000; // 2
     // 存储回调函数
     this.onMessageCallback = null; // 存储回调函数
   }

+ 3 - 3
src/updater/update.json

@@ -1,7 +1,7 @@
 {
-  "version": "1.0.41",
-  "releaseDate": "2025-08-11 08:06:05",
-  "checksum": "feaf8a9f8ba436557a7acb7a417fcaf6f01a3f8267b59dcb5a958be9d8592c09",
+  "version": "1.0.47",
+  "releaseDate": "2025-08-11 09:09:18",
+  "checksum": "3475763e34117358d4f07a618ef7f36f9f70932584fb1332b834cb0b476beac5",
   "minBinaryVersion": "1.0.0",
   "mandatory": true,
   "upDataDescription": "✨修正一些錯誤。。。。!!!"

+ 13 - 11
src/utils/notifications.js

@@ -1,9 +1,11 @@
 import { LocalNotifications } from "@capacitor/local-notifications";
 import { App } from "@capacitor/app";
 import { Howl } from "howler";
+import txtNotify from "@/assets/mp3/im.mp3"
+import voiceNotify from "@/assets/mp3/voice.mp3"
 
 const soundIm = new Howl({
-  src: ["src/assets/mp3/im.mp3"],
+  src: [txtNotify],
   html5: false, // 强制使用HTML5 Audio
   format: ["mp3"], // 指定格式
   preload: true, // 预加载
@@ -14,24 +16,27 @@ const soundIm = new Howl({
   },
 });
 
-const soundVoice = new Howl({
-  src: ["src/assets/mp3/voice.mp3"],
+export const soundVoice = new Howl({
+  src: [voiceNotify],
   html5: false, // 强制使用HTML5 Audio
   format: ["mp3"], // 指定格式
   preload: true, // 预加载
   volume: 0.6, // 音量
-  pool: 16, // 可以同时播放3个实例
+  pool: 3, // 可以同时播放3个实例
+  loop: true,
   onloaderror: (id, error) => {
     console.error("加载失败:", error);
   },
 });
 let id = 1
 // 初始化通知监听
-export async function setupNotifications(msgType) {
+export async function setupNotifications() {
   // 检查权限
   const granted = await LocalNotifications.requestPermissions();
+  console.log('权限:', granted,msgType );
   if (!granted) return;
   id += 1
+  console.log('id:', id);
   await LocalNotifications.schedule({
     notifications: [
       {
@@ -42,13 +47,10 @@ export async function setupNotifications(msgType) {
       },
     ],
   }); 
-  if(msgType == 1){
-    return  soundIm.play();
-  }
-  if(msgType == 2){
-    return  soundVoice.play();
-  }
+  soundIm.play();
 }
+
+
 // App 状态变化时处理
 App.addListener("appStateChange", ({ isActive }) => {
   console.log("App active:", isActive);

+ 1 - 2
src/views/im/components/CallController/index.vue

@@ -51,8 +51,7 @@
   </div>
 </template>
 
-<script setup>
-import { ref, computed, onMounted, onBeforeUnmount, watch } from "vue";
+<script setup> 
 import { useWebSocketStore } from "@/stores/modules/webSocketStore";
 import { useWebRTCStore } from "@/stores/modules/webrtcStore";
 import * as Constant from "@/common/constant/Constant";

+ 6 - 1
src/views/im/hook/messagesHook.js

@@ -1,7 +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";
+import { setupNotifications, soundVoice } from "@/utils/notifications.js";
 
 // 发送消息处理
 export const setMessageHook = (message, state) => {
@@ -91,6 +91,7 @@ export const handleMessageHook = (message, state) => {
       fromUserUuid: message.from, 
       callAvatar: message.avatar
     };
+    soundVoice.play() 
     return
   }
   // 音频在线:取消
@@ -101,6 +102,7 @@ export const handleMessageHook = (message, state) => {
     console.log("音频在线:取消")
     const rtcStore = useWebRTCStore();
     rtcStore.imSate.videoCallModal = false; 
+    soundVoice.stop() 
     rtcStore.cleanup()
     return;
   }
@@ -110,8 +112,10 @@ export const handleMessageHook = (message, state) => {
     message.contentType === Constant.REJECT_VIDEO_ONLINE
   ) {
     console.log("音频在线:拒接")
+    soundVoice.stop() 
     const rtcStore = useWebRTCStore();
     rtcStore.imSate.videoCallModal = false;
+
     return;
   }
   // 音频在线:接听
@@ -120,6 +124,7 @@ export const handleMessageHook = (message, state) => {
     message.contentType === Constant.ACCEPT_AUDIO_ONLINE
   ) {
      console.log("音频在线:接听", message.contentType)
+    soundVoice.stop()
     const video = message.contentType == Constant.ACCEPT_AUDIO_ONLINE
     startAudioOnline(video, state);
     return;

+ 14 - 2
vite.config.js

@@ -57,14 +57,26 @@ export default defineConfig(({ mode }) => {
       // 警报门槛,限制大文件大小
       chunkSizeWarningLimit: 5000,
       rollupOptions: {
-        external: [], // 外部化处理那些你不想打包进库的依赖
-        // 静态资源分类打包
         output: {
           chunkFileNames: "static/js/[name]-[hash].js",
           entryFileNames: "static/js/[name]-[hash].js",
           assetFileNames: "static/[ext]/[name]-[hash].[ext]",
+          manualChunks: {
+            vue: ["vue", "vue-router", "pinia"],
+            ui: ["vant"], 
+            vendor: ["lodash", "axios", "dayjs"],
+          },
         },
       },
+      // rollupOptions: {
+      //   external: [], // 外部化处理那些你不想打包进库的依赖
+      //   // 静态资源分类打包
+      //   output: {
+      //     chunkFileNames: "static/js/[name]-[hash].js",
+      //     entryFileNames: "static/js/[name]-[hash].js",
+      //     assetFileNames: "static/[ext]/[name]-[hash].[ext]",
+      //   },
+      // },
     },
     server: {
       host: true,