| | |
| | | import { ref, computed, onBeforeUnmount } from 'vue' |
| | | |
| | | /** ✅ 你的 WS 地址前缀(后面拼 userId) */ |
| | | const WS_BASE = 'wss://wrj.shuixiongit.com/ws/chat?userId=' |
| | | const WS_BASE = 'wss://域名/ws/chat?userId=' |
| | | |
| | | const uid = ref('2') |
| | | const peerUid = ref('3') |
| | |
| | | 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 |
| | |
| | | |
| | | // 心跳 |
| | | let pingTimer = null |
| | | |
| | | function startPing() { |
| | | stopPing() |
| | | // 每 25 秒发一次 ping(你后端有 PING/PONG) |
| | |
| | | if (connected.value) send('ping', 'system', null) |
| | | }, 25000) |
| | | } |
| | | |
| | | function stopPing() { |
| | | if (pingTimer) clearInterval(pingTimer) |
| | | pingTimer = null |
| | |
| | | const stream = e.streams[0] |
| | | if (remoteAudio.value) { |
| | | remoteAudio.value.srcObject = stream |
| | | remoteAudio.value.play().catch(() => { |
| | | }) |
| | | remoteAudio.value.play().catch(() => {}) |
| | | } |
| | | } |
| | | |
| | |
| | | function cleanup(sendToPeer) { |
| | | try { |
| | | if (sendToPeer) send('hangup', peerUid.value, null) |
| | | } catch { |
| | | } |
| | | } catch {} |
| | | |
| | | stopTimer() |
| | | |