Merge remote-tracking branch 'origin/test-audio'
This commit is contained in:
@@ -1,395 +1,379 @@
|
||||
<template>
|
||||
<!-- 来电接听界面 -->
|
||||
<view class="incoming-call">
|
||||
<!-- 背景模糊层 -->
|
||||
<view class="blur-background" v-if="callBackground">
|
||||
<image
|
||||
:src="callBackground"
|
||||
mode="aspectFill"
|
||||
class="bg-image"
|
||||
></image>
|
||||
<view class="bg-overlay"></view>
|
||||
</view>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<view class="caller-info">
|
||||
<view class="caller-avatar-container">
|
||||
<view class="caller-avatar" :class="{ 'avatar-ring': isRinging }">
|
||||
<image
|
||||
v-if="callerInfo?.avatar"
|
||||
:src="callerInfo?.avatar"
|
||||
class="avatar-image"
|
||||
></image>
|
||||
<uni-icons
|
||||
v-else
|
||||
type="contact-filled"
|
||||
size="50"
|
||||
color="#fff"
|
||||
></uni-icons>
|
||||
<view class="incoming-call">
|
||||
<!-- 背景模糊层 -->
|
||||
<view class="blur-background" v-if="callBackground">
|
||||
<image
|
||||
:src="callBackground"
|
||||
mode="aspectFill"
|
||||
class="bg-image"
|
||||
></image>
|
||||
<view class="bg-overlay"></view>
|
||||
</view>
|
||||
</view>
|
||||
<text class="caller-name">
|
||||
{{ callerInfo?.nick || callerInfo?.userID }}
|
||||
</text>
|
||||
<text class="call-type">
|
||||
{{ callState === 'call' ? '呼叫中,等待对方接受邀请...' : '对话中...' }}
|
||||
</text>
|
||||
<text class="call-status">{{ mediaType === 'audio' ? "语音通话" : "视频通话" }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 控制按钮 -->
|
||||
<view class="incoming-controls">
|
||||
<view class="incoming-control" @click="cutFn(false)">
|
||||
<view
|
||||
class="call-btn decline-btn"
|
||||
:class="{ 'btn-active': activeBtn === 'decline' }"
|
||||
>
|
||||
<uni-icons type="closeempty" size="32" color="#fff"></uni-icons>
|
||||
<!-- 主内容区 -->
|
||||
<view class="caller-info">
|
||||
<view class="caller-avatar-container">
|
||||
<view class="caller-avatar" :class="{ 'avatar-ring': isRinging }">
|
||||
<image
|
||||
v-if="callerInfo?.avatar"
|
||||
:src="callerInfo?.avatar"
|
||||
class="avatar-image"
|
||||
></image>
|
||||
<uni-icons
|
||||
v-else
|
||||
type="contact-filled"
|
||||
size="50"
|
||||
color="#fff"
|
||||
></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
<text class="caller-name">
|
||||
{{ callerInfo?.nick || callerInfo?.userID }}
|
||||
</text>
|
||||
<text class="call-type">
|
||||
{{ callState === 'call' ? '呼叫中,等待对方接受邀请...' : '对话中...' }}
|
||||
</text>
|
||||
<text class="call-status">{{ mediaType === 'audio' ? "语音通话" : "视频通话" }}</text>
|
||||
</view>
|
||||
<text class="btn-text">{{ callState === 'call' || callState == 'dialogue' ? "挂断" : "拒绝" }}</text>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-if="callState === 'answer'"
|
||||
class="incoming-control"
|
||||
@click="cutFn(true)"
|
||||
>
|
||||
<view
|
||||
class="call-btn accept-btn"
|
||||
:class="{ 'btn-active': activeBtn === 'accept' }"
|
||||
>
|
||||
<uni-icons
|
||||
type="checkmarkempty"
|
||||
size="28"
|
||||
color="#fff"
|
||||
></uni-icons>
|
||||
<!-- 控制按钮 -->
|
||||
<view class="incoming-controls">
|
||||
<view class="incoming-control" @click="cutFn(false)">
|
||||
<view
|
||||
class="call-btn decline-btn"
|
||||
:class="{ 'btn-active': activeBtn === 'decline' }"
|
||||
>
|
||||
<uni-icons type="closeempty" size="32" color="#fff"></uni-icons>
|
||||
</view>
|
||||
<text class="btn-text">{{ callState === 'call' || callState == 'dialogue' ? "挂断" : "拒绝" }}</text>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-if="callState === 'answer'"
|
||||
class="incoming-control"
|
||||
@click="cutFn(true)"
|
||||
>
|
||||
<view
|
||||
class="call-btn accept-btn"
|
||||
:class="{ 'btn-active': activeBtn === 'accept' }"
|
||||
>
|
||||
<uni-icons
|
||||
type="checkmarkempty"
|
||||
size="28"
|
||||
color="#fff"
|
||||
></uni-icons>
|
||||
</view>
|
||||
<text class="btn-text">接听</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="btn-text">接听</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
|
||||
import { ref, watch } from 'vue'
|
||||
import { onLoad, onUnload, onHide } from '@dcloudio/uni-app'
|
||||
import { TUIUserService } from '@tencentcloud/chat-uikit-engine-lite'
|
||||
import { useUI } from '../../utils/use-ui'
|
||||
import { navigateBack } from '../../utils/router'
|
||||
import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
|
||||
import { ref, watch } from 'vue'
|
||||
import { onLoad, onUnload, onHide } from '@dcloudio/uni-app'
|
||||
import { TUIUserService } from '@tencentcloud/chat-uikit-engine-lite'
|
||||
import { useUI } from '../../utils/use-ui'
|
||||
import { navigateBack } from '../../utils/router'
|
||||
|
||||
CallLib.init({})
|
||||
const { showLoading, hideLoading } = useUI()
|
||||
const callBackground = ref('/static/images/public/random2.png')
|
||||
/** 呼叫用户信息 */
|
||||
const callerInfo = ref({})
|
||||
/** 通话状态 */
|
||||
const isRinging = ref(true)
|
||||
/** 控制按钮状态 */
|
||||
const activeBtn = ref(null)
|
||||
/**
|
||||
* 拨打状态
|
||||
* call: 发起呼叫
|
||||
* answer: 接听
|
||||
* dialogue: 对话中
|
||||
*/
|
||||
const callState = ref('')
|
||||
CallLib.onRemoteUserJoined(res => {
|
||||
|
||||
const { showLoading, hideLoading } = useUI()
|
||||
const callBackground = ref('/static/images/public/random2.png')
|
||||
/** 呼叫用户信息 */
|
||||
const callerInfo = ref({})
|
||||
/** 通话状态 */
|
||||
const isRinging = ref(true)
|
||||
/** 控制按钮状态 */
|
||||
const activeBtn = ref(null)
|
||||
/**
|
||||
* 拨打状态
|
||||
* call: 发起呼叫
|
||||
* answer: 接听
|
||||
* dialogue: 对话中
|
||||
*/
|
||||
const callState = ref('')
|
||||
CallLib.onRemoteUserJoined(res => {
|
||||
console.log(
|
||||
'Engine:OnRemoteUserJoined=>' +
|
||||
'Engine:OnRemoteUserJoined=>' +
|
||||
'主叫端拨出电话,被叫端收到请求后,加入通话,被叫端Id为=>',
|
||||
res.data.userId
|
||||
res.data.userId
|
||||
)
|
||||
callState.value = 'dialogue'
|
||||
})
|
||||
callState.value = 'dialogue'
|
||||
})
|
||||
|
||||
|
||||
// CallLib.onRemoteUserRinging(res => {
|
||||
// console.log(
|
||||
// '主叫端拨出电话,被叫端收到请求,发出振铃响应时触发,对端Id为=>',
|
||||
// res.data.userId
|
||||
// )
|
||||
// })
|
||||
|
||||
// CallLib.onError(res => {
|
||||
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
||||
// })
|
||||
// CallLib.onRemoteUserRinging(res => {
|
||||
// console.log(
|
||||
// '主叫端拨出电话,被叫端收到请求,发出振铃响应时触发,对端Id为=>',
|
||||
// res.data.userId
|
||||
// )
|
||||
// })
|
||||
|
||||
/** 按钮状态 */
|
||||
const cutFn = show => {
|
||||
// CallLib.onError(res => {
|
||||
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
||||
// })
|
||||
|
||||
/** 按钮状态 */
|
||||
const cutFn = show => {
|
||||
if (show) {
|
||||
// 接听电话 dialogue
|
||||
if(mediaType.value === 'audio'){
|
||||
CallLib.enableMicrophone(true)
|
||||
}
|
||||
CallLib.accept()
|
||||
callState.value = 'dialogue'
|
||||
if(mediaType.value === 'video'){
|
||||
uni.redirectTo({
|
||||
url: "/pages/room/room"
|
||||
})
|
||||
}
|
||||
// 接听电话 dialogue
|
||||
if(mediaType.value === 'audio'){
|
||||
CallLib.enableMicrophone(true)
|
||||
}
|
||||
CallLib.accept()
|
||||
callState.value = 'dialogue'
|
||||
if(mediaType.value === 'video'){
|
||||
uni.redirectTo({
|
||||
url: "/pages/room/room"
|
||||
})
|
||||
}
|
||||
} else {
|
||||
//取消接听,返回上一页
|
||||
CallLib.hangup()
|
||||
navigateBack()
|
||||
//取消接听,返回上一页
|
||||
CallLib.hangup()
|
||||
// navigateBack()
|
||||
}
|
||||
}
|
||||
|
||||
const mediaType= ref("audio")
|
||||
|
||||
onLoad(async e => {
|
||||
}
|
||||
|
||||
const mediaType= ref("audio")
|
||||
|
||||
onLoad(async e => {
|
||||
callState.value = e.type
|
||||
mediaType.value = e.mediaType
|
||||
mediaType.value = e.mediaType
|
||||
console.log(e)
|
||||
showLoading()
|
||||
const res = await TUIUserService.getUserProfile({
|
||||
userIDList: [e.userID]
|
||||
userIDList: [e.userID]
|
||||
})
|
||||
hideLoading()
|
||||
callerInfo.value = res.data[0]
|
||||
if (e.type === 'call') {
|
||||
CallLib.enableMicrophone(true)
|
||||
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
|
||||
CallLib.enableMicrophone(true)
|
||||
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
|
||||
}
|
||||
if(e.callType == "in"){
|
||||
// 接听语音通话
|
||||
callState.value = 'answer'
|
||||
}
|
||||
console.log('callState.value: ',callState.value);
|
||||
if(e.callType == "in"){
|
||||
// 接听语音通话
|
||||
callState.value = 'answer'
|
||||
}
|
||||
console.log('callState.value: ',callState.value);
|
||||
console.log('===好友信息', res)
|
||||
})
|
||||
|
||||
// onUnload( ()=>{
|
||||
// removeAllListeners()
|
||||
// })
|
||||
|
||||
// onHide( ()=>{
|
||||
// removeAllListeners()
|
||||
// })
|
||||
|
||||
function removeAllListeners(){
|
||||
//移除监听-接收到通话呼入
|
||||
CallLib.removeRemoteUserJoinedListener();
|
||||
// 移除监听-通话已结束
|
||||
CallLib.removeCallDisconnectedListener();
|
||||
// 移除监听-通话出现错误的回调
|
||||
CallLib.removeErrorListener();
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.incoming-call {
|
||||
position: fixed;
|
||||
.incoming-call {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
background-color: #000;
|
||||
|
||||
.blur-background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
background-color: #000;
|
||||
z-index: 0;
|
||||
|
||||
.blur-background {
|
||||
.bg-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
filter: blur(20px);
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.bg-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.bg-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
filter: blur(20px);
|
||||
opacity: 0.6;
|
||||
}
|
||||
.caller-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding-top: 100rpx;
|
||||
z-index: 1;
|
||||
|
||||
.bg-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
.caller-avatar-container {
|
||||
position: relative;
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
.caller-avatar {
|
||||
width: 180rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #1aad19, #129611);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
|
||||
.avatar-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
&.avatar-ring {
|
||||
animation: ringPulse 1.5s infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.caller-info {
|
||||
flex: 1;
|
||||
.caller-name {
|
||||
font-size: 48rpx;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.call-type {
|
||||
font-size: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.call-status {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
.call-timer {
|
||||
margin-top: 30rpx;
|
||||
padding: 10rpx 30rpx;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 30rpx;
|
||||
|
||||
.timer-text {
|
||||
font-size: 32rpx;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.incoming-controls {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding: 80rpx 100rpx 120rpx;
|
||||
z-index: 1;
|
||||
|
||||
.incoming-control {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding-top: 100rpx;
|
||||
z-index: 1;
|
||||
|
||||
.caller-avatar-container {
|
||||
position: relative;
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
.caller-avatar {
|
||||
width: 180rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #1aad19, #129611);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
|
||||
.avatar-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
&.avatar-ring {
|
||||
animation: ringPulse 1.5s infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.caller-name {
|
||||
font-size: 48rpx;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
.call-btn {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20rpx;
|
||||
transition: all 0.2s;
|
||||
|
||||
&.decline-btn {
|
||||
background-color: #f43f3b;
|
||||
|
||||
&.btn-active {
|
||||
transform: scale(0.9);
|
||||
background-color: #d93632;
|
||||
}
|
||||
}
|
||||
|
||||
&.accept-btn {
|
||||
background-color: #07c160;
|
||||
|
||||
&.btn-active {
|
||||
transform: scale(0.9);
|
||||
background-color: #06ad56;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.call-type {
|
||||
font-size: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.call-status {
|
||||
.btn-text {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
.call-timer {
|
||||
margin-top: 30rpx;
|
||||
padding: 10rpx 30rpx;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 30rpx;
|
||||
|
||||
.timer-text {
|
||||
font-size: 32rpx;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
}
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.incoming-controls {
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
bottom: 60rpx;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding: 0 60rpx;
|
||||
z-index: 1;
|
||||
|
||||
.action-item {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding: 80rpx 100rpx 120rpx;
|
||||
z-index: 1;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
.incoming-control {
|
||||
.action-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20rpx;
|
||||
transition: all 0.3s;
|
||||
|
||||
.call-btn {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20rpx;
|
||||
transition: all 0.2s;
|
||||
|
||||
&.decline-btn {
|
||||
background-color: #f43f3b;
|
||||
|
||||
&.btn-active {
|
||||
transform: scale(0.9);
|
||||
background-color: #d93632;
|
||||
}
|
||||
}
|
||||
|
||||
&.accept-btn {
|
||||
background-color: #07c160;
|
||||
|
||||
&.btn-active {
|
||||
transform: scale(0.9);
|
||||
background-color: #06ad56;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
&.active {
|
||||
background-color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
bottom: 60rpx;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding: 0 60rpx;
|
||||
z-index: 1;
|
||||
|
||||
.action-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
.action-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20rpx;
|
||||
transition: all 0.3s;
|
||||
|
||||
&.active {
|
||||
background-color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
}
|
||||
|
||||
.action-text {
|
||||
font-size: 24rpx;
|
||||
color: #fff;
|
||||
}
|
||||
.action-text {
|
||||
font-size: 24rpx;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes ringPulse {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0.4);
|
||||
}
|
||||
|
||||
70% {
|
||||
box-shadow: 0 0 0 30rpx rgba(26, 173, 25, 0);
|
||||
}
|
||||
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0);
|
||||
}
|
||||
@keyframes ringPulse {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0.4);
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media (max-height: 600px) {
|
||||
.incoming-controls {
|
||||
padding: 40rpx 100rpx 80rpx !important;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
bottom: 40rpx !important;
|
||||
}
|
||||
70% {
|
||||
box-shadow: 0 0 0 30rpx rgba(26, 173, 25, 0);
|
||||
}
|
||||
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media (max-height: 600px) {
|
||||
.incoming-controls {
|
||||
padding: 40rpx 100rpx 80rpx !important;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
bottom: 40rpx !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -150,24 +150,16 @@
|
||||
},
|
||||
onUnload() {
|
||||
call.hangup()
|
||||
// this.removeAllListeners()
|
||||
},
|
||||
onHide() {
|
||||
const session = call.getCurrentCallSession()
|
||||
if (session) {
|
||||
call.hangup()
|
||||
}
|
||||
// this.removeAllListeners()
|
||||
uni.$off('OnCallDisconnected')
|
||||
uni.$off('OnCallConnected')
|
||||
},
|
||||
methods: {
|
||||
removeAllListeners(){
|
||||
//移除监听-接收到通话呼入
|
||||
call.removeRemoteUserJoinedListener();
|
||||
// 移除监听-通话已结束
|
||||
call.removeCallDisconnectedListener();
|
||||
// 移除监听-通话出现错误的回调
|
||||
call.removeErrorListener();
|
||||
},
|
||||
changeMediaType() {
|
||||
if (this.mediaTypeCur == 'video') {
|
||||
this.mediaTypeCur = 'audio'
|
||||
@@ -284,9 +276,9 @@
|
||||
hangup() {
|
||||
this.isSelf = true
|
||||
call.hangup()
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
// uni.navigateBack({
|
||||
// delta: 1
|
||||
// })
|
||||
},
|
||||
accept() {
|
||||
call.accept()
|
||||
@@ -324,12 +316,61 @@
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
onCallConnected() {
|
||||
let context = this
|
||||
console.log('oncallconnected接收了')
|
||||
console.log('call: ',call);
|
||||
// 使用 Promise 确保 call 对象完全初始化
|
||||
this.initializeCall(call)
|
||||
.then(() => {
|
||||
this.processCallSession()
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('初始化通话失败:', error)
|
||||
})
|
||||
},
|
||||
async initializeCall(callObj) {
|
||||
// 等待 call 对象就绪
|
||||
await this.waitForCallReady(callObj)
|
||||
|
||||
// 设置扬声器
|
||||
if (callObj.enableSpeaker && typeof callObj.enableSpeaker === 'function') {
|
||||
try {
|
||||
callObj.enableSpeaker(true)
|
||||
} catch (error) {
|
||||
console.warn('设置扬声器失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return callObj
|
||||
},
|
||||
|
||||
waitForCallReady(callObj, timeout = 2000) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const startTime = Date.now()
|
||||
|
||||
const check = () => {
|
||||
const now = Date.now()
|
||||
|
||||
if (callObj &&
|
||||
callObj.enableSpeaker &&
|
||||
callObj.getCurrentCallSession &&
|
||||
typeof callObj.getCurrentCallSession === 'function') {
|
||||
resolve(callObj)
|
||||
} else if (now - startTime > timeout) {
|
||||
reject(new Error('call 对象初始化超时'))
|
||||
} else {
|
||||
setTimeout(check, 50)
|
||||
}
|
||||
}
|
||||
|
||||
check()
|
||||
})
|
||||
},
|
||||
|
||||
processCallSession(){
|
||||
// call.enableSpeaker(true)
|
||||
this.mediaTypeCur = this.mediaType
|
||||
call.enableSpeaker(true)
|
||||
this.currentCallSession = call.getCurrentCallSession()
|
||||
this.callWay = this.currentCallSession.callType
|
||||
this.users = this.currentCallSession.users
|
||||
@@ -347,6 +388,7 @@
|
||||
) {
|
||||
//视频是两个的时候
|
||||
if (this.currentCallSession.users.length <= 2) {
|
||||
console.log("视频是两个的时候");
|
||||
setTimeout(() => {
|
||||
this.systemInfoSync(
|
||||
this.currentCallSession.mine.userId,
|
||||
@@ -397,6 +439,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
systemInfoSync(userId, ref, isZOrderOnTop) {
|
||||
switch (uni.getSystemInfoSync().platform) {
|
||||
case 'android':
|
||||
|
||||
Reference in New Issue
Block a user