| | |
| | | /** ✅ 你的 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('2011686857615683585') |
| | | const peerUid = ref('1') |
| | | // 联系人名称 |
| | | const contactName = ref('张三') |
| | | |
| | | const connected = ref(false) |
| | | const state = ref('idle') // idle | calling | ringing | in-call |
| | | const logText = ref('') |
| | | const remoteAudio = ref(null) |
| | | // 通话结束相关 |
| | | const callEnded = ref(false) |
| | | const endMessage = ref('对方已挂断') |
| | | const endTimer = ref(null) |
| | | // token 存储 |
| | | const accessToken = ref('') |
| | | |
| | | let ws = null |
| | | let pc = null |
| | | let localStream = null |
| | | const pendingCandidates = [] |
| | | |
| | | // 来电暂存 |
| | | let incomingFrom = null |
| | | let acceptedByMe = false // 我是否已经点了接听 |
| | | let offeredByPeer = false // 是否已收到对方 offer(用于流程判断) |
| | | |
| | | // 计时 |
| | | let timer = null |
| | | const seconds = ref(0) |
| | | const durationText = computed(() => { |
| | | const m = String(Math.floor(seconds.value / 60)).padStart(2, '0') |
| | | const s = String(seconds.value % 60).padStart(2, '0') |
| | | return `${m}:${s}` |
| | | }) |
| | | function startTimer() { |
| | | stopTimer() |
| | | seconds.value = 0 |
| | | timer = setInterval(() => seconds.value++, 1000) |
| | | } |
| | | function stopTimer() { |
| | | if (timer) clearInterval(timer) |
| | | timer = null |
| | | } |
| | | // 解析URL参数 |
| | | const parseUrlParams = () => { |
| | | // 1. 优先从route.query.voiceparams获取参数 |
| | |
| | | if (userId) { |
| | | return userId |
| | | } |
| | | return '3' // 默认值 |
| | | } |
| | | |
| | | const uid = ref('3') |
| | | const peerUid = ref('2') |
| | | // 联系人名称 |
| | | const contactName = ref('张三') |
| | | |
| | | const connected = ref(false) |
| | | const state = ref('idle') // idle | calling | ringing | in-call |
| | | const logText = ref('') |
| | | const remoteAudio = ref(null) |
| | | // 通话结束相关 |
| | | const callEnded = ref(false) |
| | | const endMessage = ref('对方已挂断') |
| | | const endTimer = ref(null) |
| | | // token 存储 |
| | | const accessToken = ref('') |
| | | |
| | | let ws = null |
| | | let pc = null |
| | | let localStream = null |
| | | const pendingCandidates = [] |
| | | |
| | | // 来电暂存 |
| | | let incomingFrom = null |
| | | let acceptedByMe = false // 我是否已经点了接听 |
| | | let offeredByPeer = false // 是否已收到对方 offer(用于流程判断) |
| | | |
| | | // 计时 |
| | | let timer = null |
| | | const seconds = ref(0) |
| | | const durationText = computed(() => { |
| | | const m = String(Math.floor(seconds.value / 60)).padStart(2, '0') |
| | | const s = String(seconds.value % 60).padStart(2, '0') |
| | | return `${m}:${s}` |
| | | }) |
| | | function startTimer() { |
| | | stopTimer() |
| | | seconds.value = 0 |
| | | timer = setInterval(() => seconds.value++, 1000) |
| | | } |
| | | function stopTimer() { |
| | | if (timer) clearInterval(timer) |
| | | timer = null |
| | | return '2011686857615683585' // 默认值 |
| | | } |
| | | |
| | | // 心跳 |