| | |
| | | import defaultAvatar from '@/appDataSource/appwork/defaultAvatar.svg' |
| | | const route = useRoute() |
| | | /** ✅ 你的 WS 地址前缀(后面拼 userId) */ |
| | | const WS_BASE = 'wss://wrj.shuixiongit.com/ws/chat?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 (userId) { |
| | | return userId |
| | | } |
| | | return '8' // 默认值 |
| | | return '3' // 默认值 |
| | | } |
| | | |
| | | const uid = ref('8') |
| | | const peerUid = ref('7') |
| | | const uid = ref('3') |
| | | const peerUid = ref('2') |
| | | // 联系人名称 |
| | | const contactName = ref('张三') |
| | | |
| | |
| | | const callEnded = ref(false) |
| | | const endMessage = ref('对方已挂断') |
| | | const endTimer = ref(null) |
| | | // token 存储 |
| | | const accessToken = ref('') |
| | | |
| | | let ws = null |
| | | let pc = null |
| | |
| | | } |
| | | |
| | | try { |
| | | localStream = await navigator.mediaDevices.getUserMedia({ audio: true }) |
| | | localStream = await navigator.mediaDevices.getUserMedia({ |
| | | audio: { |
| | | echoCancellation: true, |
| | | noiseSuppression: true, |
| | | autoGainControl: true, |
| | | // 移动端特定配置 |
| | | channelCount: 1, |
| | | sampleRate: 16000, |
| | | sampleSize: 16 |
| | | } |
| | | }) |
| | | log('✅ 已获取本地麦克风') |
| | | return localStream |
| | | } catch (e) { |
| | |
| | | |
| | | if (ws) ws.close() |
| | | |
| | | ws = new WebSocket(WS_BASE + encodeURIComponent(uid.value)) |
| | | |
| | | // 使用从参数中获取的token或默认token |
| | | const token = accessToken.value |
| | | // ws = new WebSocket(WS_BASE + encodeURIComponent(uid.value)) |
| | | ws = new WebSocket(WS_BASE, token) |
| | | ws.onopen = () => { |
| | | connected.value = true |
| | | log('WS 已连接 userId=', uid.value) |
| | |
| | | |
| | | onMounted(() => { |
| | | console.log('收拾收拾',route.query.voiceparams); |
| | | console.log('接收参数', JSON.parse(decodeURIComponent(receiveParameters.value))) |
| | | |
| | | console.log('接收参数', receiveParameters) |
| | | if (route.query && route.query.params) { |
| | | try { |
| | | const params = JSON.parse(decodeURIComponent(route.query.params)); |
| | | // 获取token |
| | | if (params.access_token) { |
| | | accessToken.value = params.access_token; |
| | | log('🔗 从params获取access_token:', accessToken.value); |
| | | } |
| | | } catch (e) { |
| | | log('❌ 解析params参数失败:', String(e)); |
| | | } |
| | | } |
| | | // 解析并使用contact参数 |
| | | if (receiveParameters.value) { |
| | | try { |