liming 5 dienas atpakaļ
vecāks
revīzija
173e51248e

+ 3 - 3
.env

@@ -11,9 +11,9 @@ VITE_PRO_PATH='https://wallet.angeltokens.io'
 # VITE_PRO_IM_PATH='https://nim.angeltokens.io'
 # VITE_DEV_IM_PATH='https://nim.angeltokens.io'#https://nim.angeltokens.io
 
-VITE_PRO_IM_PATH='https://192.168.0.59:8888'
-VITE_DEV_IM_PATH='https://192.168.0.59:8888'
+VITE_PRO_IM_PATH='http://192.168.0.59:8888'
+VITE_DEV_IM_PATH='http://192.168.0.59:8888'
 
-VITE_IM_PATH_FIlE ='https://192.168.0.59:8888/api/v1/file/'
+VITE_IM_PATH_FIlE ='http://192.168.0.59:8888/api/v1/file/'
 
 VITE_PRO_BACKEND_PATH='https://backend.angeltoken.net'

+ 1 - 1
src/stores/modules/webSocketStore.js

@@ -141,7 +141,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
 
       this.peer = new RTCPeerConnection();
       this.socket = new WebSocket(
-        `wss://192.168.0.59:8888/api/v1/socket.io?user=${userUuid}`
+        `ws://192.168.0.59:8888/api/v1/socket.io?user=${userUuid}`
       );
       // 连接成功
       this.socket.onopen = () => {

+ 11 - 64
src/views/im/chat/index.vue

@@ -168,17 +168,16 @@
       </div>
     </div>
 
-
     <!-- 来电弹窗 -->
-    <div v-if="imState.videoCallModal && !inCall" class="call-modal">
-      <p>{{ imState.callName }} 正在呼叫你</p>
+    <div v-if="rtcStore.imSate.videoCallModal && !inCall" class="call-modal">
+      <p>{{ rtcStore.imSate.callName }} 正在呼叫你</p>
       <button @click="acceptCall">接听</button>
       <button @click="rejectCall">拒接</button>
     </div>
 
     <!-- 通话中显示挂断按钮 -->
     <div v-if="inCall" class="call-modal">
-      <p>与 {{ imState.callName }} 通话中...</p>
+      <p>与 {{ rtcStore.imSate.callName }} 通话中...</p>
       <button @click="hangupCall">挂断</button>
     </div>
   </div>
@@ -216,7 +215,6 @@ const appBoxHeight = ref(210);
 const chatListRef = ref(null);
 const emojiRef = ref(null);
 const toolsRef = ref(null);
-const imState = reactive(rtcStore.imSate); // 来电弹窗显示,callName,fromUserUuid
 const inCall = ref(false); // 是否处于通话中
 
 // 示例用户
@@ -436,85 +434,34 @@ const beforeRead = (file) => {
 //  创建呼叫:开启语音电话: 调试用,正式逻辑读src/views/im/hook/messagesHook.js
 // ==== 1. 发起语音通话 ====
 const startAudioOnline = async () => {
-  try {
-    rtcStore.initConnection(true); // 主叫
-    const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
-    await rtcStore.addLocalStream(stream);
-
-    const offer = await rtcStore.createOffer();
-
-    wsStore.sendMessage({
-      contentType: Constant.DIAL_AUDIO_ONLINE,
-      content: JSON.stringify(offer),
-      type: Constant.MESSAGE_TRANS_TYPE,
-      to: imState.fromUserUuid || "对方用户ID", // 实际传对方ID
-    });
-
-    imState.videoCallModal = true;
-    imState.callName = "对方昵称"; // 实际昵称
-    inCall.value = true;
-  } catch (error) {
-    console.error("发起语音通话失败", error);
-  }
+  inCall.value = true
+  wsStore.sendMessage({
+    messageType: MESSAGE_TYPE_USER, // 单聊消息
+    contentType: Constant.DIAL_AUDIO_ONLINE,
+    type: Constant.MESSAGE_TRANS_TYPE,
+  });
 };
 // ==== 2. 接听来电 ====
-async function acceptCall() {
-  try {
-    rtcStore.initConnection(false); // 被叫
-    const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
-    await rtcStore.addLocalStream(stream);
-
-    // 远端offer SDP,存在imState.offerContent,messagesHook里收到后需保存offerContent
-    const offerSDP = JSON.parse(imState.offerContent);
-    await rtcStore.setRemoteDescription(new RTCSessionDescription(offerSDP));
-
-    const answer = await rtcStore.createAnswer();
-
-    wsStore.sendMessage({
-      contentType: Constant.ACCEPT_AUDIO_ONLINE,
-      content: JSON.stringify(answer),
-      type: Constant.MESSAGE_TRANS_TYPE,
-      to: imState.fromUserUuid,
-    });
-
-    inCall.value = true;
-    imState.videoCallModal = true;
-  } catch (error) {
-    console.error("接听失败", error);
-  }
-}
+async function acceptCall() {}
 
 // ==== 3. 拒接来电 ====
 function rejectCall() {
   wsStore.sendMessage({
+    messageType: MESSAGE_TYPE_USER, // 单聊消息
     contentType: Constant.REJECT_AUDIO_ONLINE,
-    content: "",
     type: Constant.MESSAGE_TRANS_TYPE,
-    to: imState.fromUserUuid,
   });
-
-  rtcStore.videoCallModal = false;
-  inCall.value = false;
 }
 
 // ==== 4. 挂断通话 ====
 function hangupCall() {
   rtcStore.cleanup();
-  wsStore.sendMessage({
-    contentType: Constant.CANCELL_AUDIO_ONLINE,
-    content: "",
-    type: Constant.MESSAGE_TRANS_TYPE,
-    to: imState.fromUserUuid,
-  });
-  rtcStore.videoCallModal = false;
-  inCall.value = false;
 }
 
 // ==== 5. 监听信令消息 ====
 // 建议你在 useWebSocketStore 里实现 onMessage 订阅信令消息
 // 这里模拟简易监听,示范关键流程
 
-
 // 时间格式化
 const formatTime = (timestamp) => {
   const date = new Date(timestamp);

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

@@ -75,18 +75,21 @@ export const handleMessageHook = (message, state) => {
     message.contentType === Constant.DIAL_AUDIO_ONLINE ||
     message.contentType === Constant.DIAL_VIDEO_ONLINE
   ) {
+    console.log("收到播号")
     const rtcStore = useWebRTCStore();
     rtcStore.imSate = {
       videoCallModal: true,
       callName: message.fromUsername,
       fromUserUuid: message.from,
     };
+    return
   }
   // 音频在线:取消
   if (
     message.contentType === Constant.CANCELL_AUDIO_ONLINE ||
     message.contentType === Constant.CANCELL_VIDEO_ONLINE
   ) {
+    console.log("音频在线:取消")
     const rtcStore = useWebRTCStore();
     rtcStore.videoCallModal = false;
     return;
@@ -96,6 +99,7 @@ export const handleMessageHook = (message, state) => {
     message.contentType === Constant.REJECT_AUDIO_ONLINE ||
     message.contentType === Constant.REJECT_VIDEO_ONLINE
   ) {
+    console.log("音频在线:拒接")
     const rtcStore = useWebRTCStore();
     rtcStore.videoCallModal = false;
     return;
@@ -105,6 +109,7 @@ export const handleMessageHook = (message, state) => {
     message.contentType === Constant.ACCEPT_VIDEO_ONLINE ||
     message.contentType === Constant.ACCEPT_AUDIO_ONLINE
   ) {
+     console.log("音频在线:接听")
     const video = message.contentType == ACCEPT_AUDIO_ONLINE
     startAudioOnline(video);
     return;
@@ -115,6 +120,7 @@ export const handleMessageHook = (message, state) => {
       message.contentType >= Constant.DIAL_MEDIA_START &&
       message.contentType <= Constant.DIAL_MEDIA_END
     ) {
+      console.log("音频通话")
       // 媒体通话处理
       // dealMediaCall(message);
       return;

+ 4 - 4
vite.config.js

@@ -72,10 +72,10 @@ export default defineConfig(({ mode }) => {
       open: true,
       cors: true,
       hmr: true,
-      https: {
-        key: fs.readFileSync('./certDev/key.pem'),
-        cert: fs.readFileSync('./certDev/cert.pem'),
-      },
+      // https: {
+      //   key: fs.readFileSync('./certDev/key.pem'),
+      //   cert: fs.readFileSync('./certDev/cert.pem'),
+      // },
       proxy: {
         "/api/v2": {
           target: env.VITE_PRO_BACKEND_PATH,