吉安感知网项目-前端
张含笑
2026-02-11 ff37f8f678124db7c2db38e65d2da8443a465e44
feat:token
1 files modified
45 ■■■■ changed files
applications/mobile-web-view/src/appPages/voiceCallDetail/index.vue 45 ●●●● patch | view | raw | blame | history
applications/mobile-web-view/src/appPages/voiceCallDetail/index.vue
@@ -41,8 +41,8 @@
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获取参数
@@ -105,11 +105,11 @@
    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('张三')
@@ -121,6 +121,8 @@
const callEnded = ref(false)
const endMessage = ref('对方已挂断')
const endTimer = ref(null)
// token 存储
const accessToken = ref('')
let ws = null
let pc = null
@@ -227,7 +229,17 @@
    }
    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) {
@@ -378,8 +390,10 @@
    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)
@@ -558,8 +572,19 @@
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 {