| | |
| | | /** ✅ 你的 WS 地址前缀(后面拼 userId) */ |
| | | // const WS_BASE = 'ws://218.202.104.82:38201/ws/chat?userId=' |
| | | const WS_BASE = 'ws://218.202.104.82:38201/ws/chat' |
| | | // 解析URL参数 |
| | | const parseUrlParams = () => { |
| | | // 1. 优先从route.query.voiceparams获取参数 |
| | | if (route.query && route.query.voiceparams) { |
| | | console.log('从route.query.voiceparams获取参数:', route.query.voiceparams); |
| | | try { |
| | | // 解码并解析voiceparams参数 |
| | | const params = JSON.parse(decodeURIComponent(route.query.voiceparams)); |
| | | console.log('解析后的voiceparams:', params); |
| | | |
| | | if (params.peerUid) { |
| | | peerUid.value = String(params.peerUid); |
| | | log('🔗 从voiceparams获取peerUid:', params.peerUid); |
| | | } |
| | | |
| | | // 如果是来电类型,直接触发来电状态 |
| | | if (params.type === 'incoming') { |
| | | log('📞 voiceparams检测到来电,直接进入来电状态'); |
| | | incomingFrom = String(params.from); |
| | | peerUid.value = incomingFrom; |
| | | acceptedByMe = false; |
| | | offeredByPeer = false; |
| | | |
| | | state.value = 'ringing'; |
| | | log('📞 收到来电 call,来自', incomingFrom); |
| | | |
| | | // 开始来电提示(铃声和震动) |
| | | playRingtone(); |
| | | startVibration(); |
| | | } |
| | | } catch (e) { |
| | | log('❌ 解析voiceparams参数失败:', String(e)); |
| | | } |
| | | } |
| | | |
| | | // 2. 同时保留原有的URL参数解析逻辑,作为备选 |
| | | const url = new URL(window.location.href); |
| | | const paramsStr = url.searchParams.get('params'); |
| | | if (paramsStr) { |
| | | try { |
| | | const params = JSON.parse(decodeURIComponent(paramsStr)); |
| | | if (params.peerUid) { |
| | | peerUid.value = String(params.peerUid); |
| | | log('🔗 从URL参数获取peerUid:', params.peerUid); |
| | | } |
| | | } catch (e) { |
| | | log('❌ 解析URL参数失败:', String(e)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 从URL参数或本地存储获取用户ID |
| | | const getUserIdFromStorage = () => { |
| | | // 从url获取用户id |
| | | const contact = JSON.parse(decodeURIComponent(receiveParameters.value)) |
| | | console.log('从url获取用户id',contact?.userId) |
| | | // 从本地获取用户id |
| | | const userId = localStorage.getItem('userId') || sessionStorage.getItem('userId') |
| | | console.log('从本地存储获取userId:', userId) |
| | | if (userId) { |
| | | return userId |
| | | } |
| | | return '3' // 默认值 |
| | | } |
| | | |
| | | const uid = ref('3') |
| | | const peerUid = ref('2') |
| | | const uid = ref('2011686857615683585') |
| | | const peerUid = ref('1') |
| | | // 联系人名称 |
| | | const contactName = ref('张三') |
| | | |
| | |
| | | if (timer) clearInterval(timer) |
| | | timer = null |
| | | } |
| | | // 解析URL参数 |
| | | const parseUrlParams = () => { |
| | | // 1. 优先从route.query.voiceparams获取参数 |
| | | if (route.query && route.query.voiceparams) { |
| | | console.log('从route.query.voiceparams获取参数:', route.query.voiceparams); |
| | | try { |
| | | // 解码并解析voiceparams参数 |
| | | const params = JSON.parse(decodeURIComponent(route.query.voiceparams)); |
| | | console.log('解析后的voiceparams:', params); |
| | | |
| | | if (params.peerUid) { |
| | | peerUid.value = String(params.peerUid); |
| | | log('🔗 从voiceparams获取peerUid:', params.peerUid); |
| | | } |
| | | |
| | | // 如果是来电类型,直接触发来电状态 |
| | | if (params.type === 'incoming') { |
| | | log('📞 voiceparams检测到来电,直接进入来电状态'); |
| | | incomingFrom = String(params.from); |
| | | peerUid.value = incomingFrom; |
| | | acceptedByMe = false; |
| | | offeredByPeer = false; |
| | | |
| | | state.value = 'ringing'; |
| | | log('📞 收到来电 call,来自', incomingFrom); |
| | | |
| | | // 开始来电提示(铃声和震动) |
| | | playRingtone(); |
| | | startVibration(); |
| | | } |
| | | } catch (e) { |
| | | log('❌ 解析voiceparams参数失败:', String(e)); |
| | | } |
| | | } |
| | | |
| | | // 2. 同时保留原有的URL参数解析逻辑,作为备选 |
| | | const url = new URL(window.location.href); |
| | | const paramsStr = url.searchParams.get('params'); |
| | | if (paramsStr) { |
| | | try { |
| | | const params = JSON.parse(decodeURIComponent(paramsStr)); |
| | | if (params.peerUid) { |
| | | peerUid.value = String(params.peerUid); |
| | | log('🔗 从URL参数获取peerUid:', params.peerUid); |
| | | } |
| | | } catch (e) { |
| | | log('❌ 解析URL参数失败:', String(e)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 从URL参数或本地存储获取用户ID |
| | | const getUserIdFromStorage = () => { |
| | | // 从url获取用户id |
| | | const contact = JSON.parse(decodeURIComponent(receiveParameters.value)) |
| | | console.log('从url获取用户id',contact?.userId) |
| | | // 从本地获取用户id |
| | | const userId = localStorage.getItem('userId') || sessionStorage.getItem('userId') |
| | | console.log('从本地存储获取userId:', userId) |
| | | if (userId) { |
| | | return userId |
| | | } |
| | | return '2011686857615683585' // 默认值 |
| | | } |
| | | |
| | | // 心跳 |
| | | let pingTimer = null |