| | |
| | | /** ✅ 你的 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' |
| | | |
| | | const uid = ref('2021475329842999298') |
| | | const newUserInfo = ref(null) |
| | | const uid = ref('') |
| | | const peerUid = ref('2021474568497131521') |
| | | // 联系人名称 |
| | | const contactName = ref('张三') |
| | | const contactName = ref('') |
| | | |
| | | const connected = ref(false) |
| | | const state = ref('idle') // idle | calling | ringing | in-call |
| | |
| | | |
| | | // 从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) { |
| | | const userId = '2021474815063486465' |
| | | try { |
| | | const params = JSON.parse(decodeURIComponent(route.query.params)); |
| | | newUserInfo.value = params.new_userInfo |
| | | const userIdFromParams = params.new_userInfo?.userId |
| | | console.log('从url获取用户id', userIdFromParams) |
| | | return userIdFromParams || userId |
| | | } catch (error) { |
| | | return userId |
| | | } |
| | | return '2021475329842999298' // 默认值 |
| | | } |
| | | |
| | | // 心跳 |
| | |
| | | const receiveParameters = ref(route.query.contact || null); |
| | | |
| | | onMounted(() => { |
| | | console.log('收拾收拾',route.query.voiceparams); |
| | | console.log('接收参数', receiveParameters) |
| | | console.log('对方打给我的',route.query.voiceparams); |
| | | console.log('接收拨打电话:对方参数', receiveParameters) |
| | | if (route.query && route.query.params) { |
| | | try { |
| | | const params = JSON.parse(decodeURIComponent(route.query.params)); |
| | |
| | | if (receiveParameters.value) { |
| | | try { |
| | | const contact = JSON.parse(decodeURIComponent(receiveParameters.value)) |
| | | if (contact.friendId) { |
| | | peerUid.value = contact.friendId |
| | | contactName.value = contact.friendNickName || '未知联系人' |
| | | log('🔗 从contact参数获取peerUid:', contact.friendId) |
| | | log('👤 联系人名称:', contactName.value) |
| | | if (contact.userId) { |
| | | peerUid.value = contact.userId |
| | | contactName.value = contact.nickName || '未知联系人' |
| | | // log('🔗 从contact参数获取peerUid:', peerUid.value) |
| | | // log('👤 联系人名称:', contactName.value) |
| | | } |
| | | } catch (e) { |
| | | log('❌ 解析contact参数失败:', String(e)) |