| | |
| | | // 你后端没有 reject,用 busy 表示拒绝/不可接听 |
| | | send('busy', incomingFrom, null) |
| | | log('❌ 已拒绝来电,发送 busy 给', incomingFrom) |
| | | |
| | | const transmitData = { data: { type: 'hangupVoice' } } |
| | | uni.postMessage(transmitData) |
| | | // 停止铃声 |
| | | // const transmitData = { data: { type: 'stopVoice' } } |
| | | // uni.postMessage(transmitData) |
| | |
| | | } else { |
| | | log('❌ uni对象不存在,无法返回上一页') |
| | | } |
| | | const transmitData = { data: { type: 'hangupVoice' } } |
| | | uni.postMessage(transmitData) |
| | | } else { |
| | | // 对方挂断:显示提示,延迟10秒跳转 |
| | | callEnded.value = true |
| | |
| | | } else { |
| | | log('❌ uni对象不存在,无法返回上一页') |
| | | } |
| | | const transmitData = { data: { type: 'hangupVoice' } } |
| | | uni.postMessage(transmitData) |
| | | // 重置通话结束状态 |
| | | callEnded.value = false |
| | | }, 3000) |
| | |
| | | // 存储铃声实例 |
| | | let ringtoneInstance = null |
| | | |
| | | // 监听WebView消息事件 |
| | | if (typeof uni !== 'undefined' && uni.$on) { |
| | | uni.$on('webViewMessage', (data) => { |
| | | console.log('📨 useGlobalWS 收到 WebView 消息:', data) |
| | | // 处理挂断消息 |
| | | if (data?.type === 'hangupVoice') { |
| | | console.log('📞 收到挂断消息') |
| | | initWS() |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 设置默认用户ID为3 |
| | | const defaultUserId = '2021474815063486465'; |
| | | // WebSocket基础URL |
| | |
| | | return |
| | | } |
| | | recoverTimer = setInterval(() => { |
| | | // console.log('shouldRecoverWS()',shouldRecoverWS(),'----------',websocketService.getConnected()) |
| | | if (shouldRecoverWS() && !websocketService.getConnected()) { |
| | | initWS() |
| | | } |
| | |
| | | } |
| | | |
| | | function initWS() { |
| | | websocketService.close() |
| | | const userStore = useUserStore() |
| | | accessToken.value =userStore?.userInfo.access_token |
| | | if (!accessToken.value || isVoiceCallDetailActive()) { |
| | |
| | | |
| | | function onPostMessage(data) { |
| | | // 将WebView消息传递给全局WebSocket处理 |
| | | // if (typeof uni !== 'undefined' && uni.$emit) { |
| | | // uni.$emit('webViewMessage', data); |
| | | // } |
| | | if (typeof uni !== 'undefined' && uni.$emit) { |
| | | uni.$emit('webViewMessage', data); |
| | | } |
| | | } |
| | | |
| | | </script> |
| | |
| | | this.socketTask.send({ |
| | | data: JSON.stringify(message), |
| | | success: () => { |
| | | // console.log('WebSocket消息发送成功:', message) |
| | | useGlobalWS(); |
| | | console.log('WebSocket消息发送成功:', message) |
| | | // useGlobalWS(); |
| | | }, |
| | | fail: (error) => { |
| | | // console.error('WebSocket消息发送失败:', error) |
| | |
| | | } |
| | | |
| | | // 开始心跳检测 |
| | | startPing() { |
| | | this.stopPing() |
| | | // 每25秒发送一次心跳 |
| | | this.pingTimer = setInterval(() => { |
| | | if (this.connected) { |
| | | this.send('ping', 'system') |
| | | } |
| | | }, 25000) |
| | | } |
| | | // startPing() { |
| | | // this.stopPing() |
| | | // // 每25秒发送一次心跳 |
| | | // this.pingTimer = setInterval(() => { |
| | | // if (this.connected) { |
| | | // this.send('ping', 'system') |
| | | // } |
| | | // }, 25000) |
| | | // } |
| | | |
| | | // 停止心跳检测 |
| | | stopPing() { |