Merge commit 'a3df920503cc34606777e77b1bc87016b68b2a7b'

This commit is contained in:
cbb
2026-02-07 14:14:58 +08:00
5 changed files with 628 additions and 448 deletions

117
App.vue
View File

@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
// #ifdef APP-PLUS // #ifdef APP-PLUS
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem' import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index" // import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
// #endif // #endif
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app' import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { reLaunch } from './utils/router' import { reLaunch } from './utils/router'
@@ -42,7 +42,7 @@
// #ifdef APP-PLUS // #ifdef APP-PLUS
setSdkLanguageFromSystem() setSdkLanguageFromSystem()
onAllListeners() // onAllListeners()
// #endif // #endif
}) })
@@ -61,120 +61,7 @@
console.log('App Hide333') console.log('App Hide333')
}) })
function onAllListeners () {
call.onCallReceived( (res)=> {
console.log(res)
console.log("Engine:OnCallReceived=>"+"监听通话呼入, 目标id=>", res.data.targetId);
if (res.data.targetId) {
// let url = res.data.mediaType == 0 ? "" : "/pages/room/room"
uni.setStorageSync('room-parameters', {
callType: 'in',
mediaType: res.data.mediaType === 0 ? 'audio' : 'video'
});
uni.showToast({
title:"有通话呼入该跳转了"+res.data.targetId,
duration:3000
})
navigateTo("/pages/room/incom", {
type: res.data.extra,
callType: 'in',
mediaType: res.data.mediaType == 0 ? "audio" : "video",
userID: res.data.mine.userId // 对方的用户id
})
}
});
call.onCallDisconnected((res)=>{
console.log(res)
console.log("Engine:OnCallDisconnected=>"+"通话挂断/拒绝, 挂断原因=>", res.data.reason);
// 重新渲染视频视图
// uni.$emit('OnCallDisconnected');
uni.showToast({
title:reasonDeal(res.data.reason),
error:"error",
icon:'none',
duration:2000
})
goback()
});
call.onCallConnected((res)=>{
console.log(res)
console.log("Engine:OnCallConnected=>"+"已建立通话通话接通时,通过回调 onCallConnected 通知当前 call 的详细信息", res);
});
call.onRemoteUserInvited((res)=>{
console.log("Engine:OnRemoteUserInvited=>"+"通话中的某一个参与者,邀请好友加入通话 ,远端Id为=>", res.data.userId);
uni.$emit('OnCallConnected');
})
call.onRemoteUserJoined((res)=>{
console.log("Engine:OnRemoteUserJoined=>"+"主叫端拨出电话被叫端收到请求后加入通话对端Id为=>", res.data.userId);
uni.$emit('OnCallConnected');
})
call.onRemoteUserLeft((res)=>{
console.log("Engine:OnRemoteUserLeft=>"+"远端用户挂断(群聊触发)远端Id为=>", res.data.reason);
uni.$emit('OnCallConnected');
uni.showToast({
title:reasonDeal(res.data.reason),
error:"error",
icon:'none',
duration:2000
})
})
call.onCallOutgoing((res)=>{
console.log('电话已拨出 主叫端拨出电话后,通过回调 onCallOutgoing 通知当前 call 的详细信息')
})
call.onRemoteUserRinging((res)=>{
console.log('被叫端正在振铃,主叫端拨出电话,被叫端收到请求,发出振铃响应时,回调 onRemoteUserRingin,对端Id为=>', res.data.userId)
})
call.onError((res)=>{
console.log('通话过程中,发生异常')
uni.showToast({
title:errorDeal(res.data.reason),
error:"error",
icon:'none',
duration:2000
});
goback()
})
call.onRemoteUserMediaTypeChanged((res)=>{
console.log('当通话中的某一个参与者切换通话类型,例如由 audio 切换至 video回调 onMediaTypeChanged,切换媒体类型的Id为=>',res.data.user.userId);
})
}
function goback () {
const pages = getCurrentPages()
console.log('pages: ',pages);
if (pages.length > 1) {
console.log("走返回");
uni.showToast({
title:"走返回",
duration:3000
})
uni.navigateBack({
delta: 1
})
const currentPage = pages[pages.length - 1]
const prevPage = pages[pages.length - 2]
// 判断上一页是否是 tabBar 页面
// const isPrevPageTabBar = isTabBarPage(currentPage.route)
// if(!isPrevPageTabBar){
// }
}
}
// 判断页面是否是 tabBar 页面
function isTabBarPage(route) {
// 这里根据你的 pages.json 配置来判断
const tabBarPages = [
'TUIKit/components/TUIConversation/index',
'TUIKit/components/TUIContact/index',
'pages/discover/discover',
'pages/my-index/my-index'
]
// 判断路由是否在 tabBar 页面列表中
return tabBarPages.includes(route)
}
function removeAllListeners(){ function removeAllListeners(){
call.unInit(); call.unInit();

View File

@@ -56,7 +56,8 @@
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>", "<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>", "<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>" "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
] ],
"debuggable" : true
}, },
/* ios */ /* ios */
"ios" : { "ios" : {

View File

@@ -1,379 +1,472 @@
<template> <template>
<!-- 来电接听界面 --> <!-- 来电接听界面 -->
<view class="incoming-call"> <view class="incoming-call">
<!-- 背景模糊层 --> <!-- 背景模糊层 -->
<view class="blur-background" v-if="callBackground"> <view class="blur-background" v-if="callBackground">
<image <image :src="callBackground" mode="aspectFill" class="bg-image"></image>
:src="callBackground" <view class="bg-overlay"></view>
mode="aspectFill" </view>
class="bg-image"
></image>
<view class="bg-overlay"></view>
</view>
<!-- 主内容区 --> <!-- 顶部栏 -->
<view class="caller-info"> <view class="top-bar">
<view class="caller-avatar-container"> <view class="top-left">
<view class="caller-avatar" :class="{ 'avatar-ring': isRinging }"> <!-- 通话时间显示 -->
<image <view v-if="callState === 'dialogue'" class="call-time-container">
v-if="callerInfo?.avatar" <uni-icons type="sound" size="16" color="#fff"></uni-icons>
:src="callerInfo?.avatar" <text class="call-time">{{ formattedTime }}</text>
class="avatar-image" </view>
></image> </view>
<uni-icons </view>
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>
<!-- 控制按钮 --> <!-- 主内容区 -->
<view class="incoming-controls"> <view class="caller-info">
<view class="incoming-control" @click="cutFn(false)"> <view class="caller-avatar-container">
<view <view class="caller-avatar" :class="{ 'avatar-ring': isRinging }">
class="call-btn decline-btn" <image v-if="callerInfo?.avatar" :src="callerInfo?.avatar" class="avatar-image"></image>
:class="{ 'btn-active': activeBtn === 'decline' }" <uni-icons v-else type="contact-filled" size="50" color="#fff"></uni-icons>
> </view>
<uni-icons type="closeempty" size="32" color="#fff"></uni-icons> </view>
</view> <text class="caller-name">
<text class="btn-text">{{ callState === 'call' || callState == 'dialogue' ? "挂断" : "拒绝" }}</text> {{ callerInfo?.nick || callerInfo?.userID }}
</view> </text>
<text class="call-type">
{{ callState === 'call' ? '呼叫中,等待对方接受邀请...' : callState === 'answer' ? '等待接听...' : '对话中...' }}
</text>
<text class="call-status">{{ mediaType === 'audio' ? "语音通话" : "视频通话" }}</text>
</view>
<view <!-- 控制按钮 -->
v-if="callState === 'answer'" <view class="incoming-controls">
class="incoming-control" <!-- 麦克风控制按钮仅在通话中显示 -->
@click="cutFn(true)" <view v-if="callState === 'dialogue'" class="incoming-control" @click="toggleMicrophone">
> <view class="call-btn mic-btn" :class="{ 'btn-active': activeBtn === 'mic', 'mic-muted': isMicMuted }">
<view <uni-icons v-if="!isMicMuted" type="mic" size="28" color="#fff"></uni-icons>
class="call-btn accept-btn" <uni-icons v-else type="micoff" size="28" color="#fff"></uni-icons>
:class="{ 'btn-active': activeBtn === 'accept' }" </view>
> <text class="btn-text">{{ isMicMuted ? '开启' : '静音' }}</text>
<uni-icons </view>
type="checkmarkempty"
size="28" <!-- 挂断/拒绝按钮 -->
color="#fff" <view class="incoming-control" @click="cutFn(false)">
></uni-icons> <view class="call-btn decline-btn" :class="{ 'btn-active': activeBtn === 'decline' }">
</view> <uni-icons type="closeempty" size="32" color="#fff"></uni-icons>
<text class="btn-text">接听</text> </view>
</view> <text class="btn-text">{{ callState === 'call' || callState == 'dialogue' ? "挂断" : "拒绝" }}</text>
</view> </view>
</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 v-if="callState === 'dialogue'" class="incoming-control" @click="toggleSpeaker">
<view class="call-btn speaker-btn" :class="{ 'btn-active': activeBtn === 'speaker', 'speaker-on': isSpeakerOn }">
<uni-icons v-if="!isSpeakerOn" type="sound" size="28" color="#fff"></uni-icons>
<uni-icons v-else type="sound-filled" size="28" color="#fff"></uni-icons>
</view>
<text class="btn-text">扬声器</text>
</view>
</view>
</view>
</template> </template>
<script setup> <script setup>
import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index' import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
import { ref, watch } from 'vue' import {
import { onLoad, onUnload, onHide } from '@dcloudio/uni-app' ref,
import { TUIUserService } from '@tencentcloud/chat-uikit-engine-lite' watch,
import { useUI } from '../../utils/use-ui' onUnmounted
import { navigateBack } from '../../utils/router' } 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'
const { showLoading, hideLoading } = useUI() const {
const callBackground = ref('/static/images/public/random2.png') showLoading,
/** 呼叫用户信息 */ hideLoading
const callerInfo = ref({}) } = useUI()
/** 通话状态 */ const callBackground = ref('/static/images/public/random2.png')
const isRinging = ref(true) /** 呼叫用户信息 */
/** 控制按钮状态 */ const callerInfo = ref({})
const activeBtn = ref(null) /** 通话状态 */
/** const isRinging = ref(true)
* 拨打状态 /** 控制按钮状态 */
* call: 发起呼叫 const activeBtn = ref(null)
* answer: 接听 /** 麦克风是否静音 */
* dialogue: 对话中 const isMicMuted = ref(false)
*/ /** 扬声器是否开启 */
const callState = ref('') const isSpeakerOn = ref(false)
CallLib.onRemoteUserJoined(res => { /** 通话计时器 */
console.log( const timer = ref(null)
'Engine:OnRemoteUserJoined=>' + /** 通话时长(秒) */
'主叫端拨出电话被叫端收到请求后加入通话被叫端Id为=>', const callDuration = ref(0)
res.data.userId /** 格式化后的时间 */
) const formattedTime = ref('00:00')
callState.value = 'dialogue'
})
/**
* 拨打状态
* call: 发起呼叫
* answer: 接听
* dialogue: 对话中
*/
const callState = ref('')
CallLib.onRemoteUserJoined(res => {
console.log(
'Engine:OnRemoteUserJoined=>' +
'主叫端拨出电话被叫端收到请求后加入通话被叫端Id为=>',
res.data.userId
)
callState.value = 'dialogue'
// 开始计时
startTimer()
})
// CallLib.onRemoteUserRinging(res => { // CallLib.onRemoteUserRinging(res => {
// console.log( // console.log(
// '主叫端拨出电话被叫端收到请求发出振铃响应时触发对端Id为=>', // '主叫端拨出电话被叫端收到请求发出振铃响应时触发对端Id为=>',
// res.data.userId // res.data.userId
// ) // )
// }) // })
// CallLib.onError(res => { // CallLib.onError(res => {
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason) // console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
// }) // })
/** 按钮状态 */ /** 开始通话计时 */
const cutFn = show => { const startTimer = () => {
if (show) { stopTimer() // 先停止之前的计时器
// 接听电话 dialogue timer.value = setInterval(() => {
if(mediaType.value === 'audio'){ callDuration.value++
CallLib.enableMicrophone(true) formatTime()
} }, 1000)
CallLib.accept() }
callState.value = 'dialogue'
if(mediaType.value === 'video'){
uni.redirectTo({
url: "/pages/room/room"
})
}
} else {
//取消接听,返回上一页
CallLib.hangup()
// navigateBack()
}
}
const mediaType= ref("audio") /** 停止通话计时 */
const stopTimer = () => {
if (timer.value) {
clearInterval(timer.value)
timer.value = null
}
}
onLoad(async e => { /** 格式化时间显示 */
callState.value = e.type const formatTime = () => {
mediaType.value = e.mediaType const minutes = Math.floor(callDuration.value / 60)
console.log(e) const seconds = callDuration.value % 60
showLoading() formattedTime.value = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
const res = await TUIUserService.getUserProfile({ }
userIDList: [e.userID]
})
hideLoading()
callerInfo.value = res.data[0]
if (e.type === 'call') {
CallLib.enableMicrophone(true)
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
}
if(e.callType == "in"){
// 接听语音通话
callState.value = 'answer'
}
console.log('callState.value: ',callState.value);
console.log('===好友信息', res)
})
/** 切换麦克风状态 */
const toggleMicrophone = () => {
isMicMuted.value = !isMicMuted.value
// 调用融云SDK的麦克风控制
CallLib.enableMicrophone(!isMicMuted.value)
activeBtn.value = 'mic'
setTimeout(() => activeBtn.value = null, 200)
}
/** 切换扬声器状态 */
const toggleSpeaker = () => {
isSpeakerOn.value = !isSpeakerOn.value
// 调用融云SDK的扬声器控制
CallLib.enableSpeaker(isSpeakerOn.value)
activeBtn.value = 'speaker'
setTimeout(() => activeBtn.value = null, 200)
}
/** 按钮状态 */
const cutFn = show => {
if (show) {
// 接听电话 dialogue
if (mediaType.value === 'audio') {
CallLib.enableMicrophone(true)
}
CallLib.accept()
callState.value = 'dialogue'
// 开始计时
startTimer()
if (mediaType.value === 'video') {
uni.redirectTo({
url: "/pages/room/room"
})
}
} else {
// 停止计时
stopTimer()
// 取消接听,返回上一页
CallLib.hangup()
// navigateBack()
}
}
const mediaType = ref("audio")
onLoad(async e => {
callState.value = e.type
mediaType.value = e.mediaType
console.log(e)
showLoading()
const res = await TUIUserService.getUserProfile({
userIDList: [e.userID]
})
hideLoading()
callerInfo.value = res.data[0]
if (e.type === 'call') {
CallLib.enableMicrophone(true)
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
}
if (e.callType == "in") {
// 接听语音通话
callState.value = 'answer'
}
console.log('callState.value: ', callState.value);
console.log('===好友信息', res)
})
// 组件卸载时清理计时器
onUnload(() => {
stopTimer()
})
onUnmounted(() => {
stopTimer()
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.incoming-call { .incoming-call {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
z-index: 9999; z-index: 9999;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
background-color: #000; background-color: #000;
.blur-background { /* 顶部栏样式 */
position: absolute; .top-bar {
top: 0; position: absolute;
left: 0; top: 0;
width: 100%; left: 0;
height: 100%; width: 100%;
z-index: 0; height: 120rpx;
display: flex;
align-items: center;
padding: 0 40rpx;
z-index: 2;
box-sizing: border-box;
padding-top: env(safe-area-inset-top);
.bg-image { .top-left {
width: 100%; .call-time-container {
height: 100%; display: flex;
filter: blur(20px); align-items: center;
opacity: 0.6; background: rgba(255, 255, 255, 0.15);
} padding: 8rpx 20rpx;
border-radius: 30rpx;
backdrop-filter: blur(10px);
.bg-overlay { .call-time {
position: absolute; font-size: 28rpx;
top: 0; color: #fff;
left: 0; font-weight: 500;
width: 100%; margin-left: 10rpx;
height: 100%; }
background: rgba(0, 0, 0, 0.5); }
} }
} }
.caller-info { .blur-background {
flex: 1; position: absolute;
display: flex; top: 0;
flex-direction: column; left: 0;
align-items: center; width: 100%;
justify-content: center; height: 100%;
padding-top: 100rpx; z-index: 0;
z-index: 1;
.caller-avatar-container { .bg-image {
position: relative; width: 100%;
margin-bottom: 40rpx; height: 100%;
filter: blur(20px);
opacity: 0.6;
}
.caller-avatar { .bg-overlay {
width: 180rpx; position: absolute;
height: 180rpx; top: 0;
border-radius: 50%; left: 0;
background: linear-gradient(135deg, #1aad19, #129611); width: 100%;
display: flex; height: 100%;
align-items: center; background: rgba(0, 0, 0, 0.5);
justify-content: center; }
overflow: hidden; }
.avatar-image { .caller-info {
width: 100%; flex: 1;
height: 100%; display: flex;
} flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 100rpx;
z-index: 1;
&.avatar-ring { .caller-avatar-container {
animation: ringPulse 1.5s infinite; position: relative;
} margin-bottom: 40rpx;
}
}
.caller-name { .caller-avatar {
font-size: 48rpx; width: 180rpx;
color: #fff; height: 180rpx;
font-weight: 500; border-radius: 50%;
margin-bottom: 20rpx; background: linear-gradient(135deg, #1aad19, #129611);
} display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
.call-type { .avatar-image {
font-size: 32rpx; width: 100%;
color: rgba(255, 255, 255, 0.9); height: 100%;
margin-bottom: 10rpx; }
}
.call-status { &.avatar-ring {
font-size: 28rpx; animation: ringPulse 1.5s infinite;
color: rgba(255, 255, 255, 0.7); }
} }
}
.call-timer { .caller-name {
margin-top: 30rpx; font-size: 48rpx;
padding: 10rpx 30rpx; color: #fff;
background: rgba(255, 255, 255, 0.1); font-weight: 500;
border-radius: 30rpx; margin-bottom: 20rpx;
}
.timer-text { .call-type {
font-size: 32rpx; font-size: 32rpx;
color: #fff; color: rgba(255, 255, 255, 0.9);
font-weight: 500; margin-bottom: 10rpx;
} }
}
}
.incoming-controls { .call-status {
display: flex; font-size: 28rpx;
justify-content: space-around; color: rgba(255, 255, 255, 0.7);
padding: 80rpx 100rpx 120rpx; }
z-index: 1; }
.incoming-control { .incoming-controls {
display: flex; display: flex;
flex-direction: column; justify-content: space-around;
align-items: center; padding: 80rpx 40rpx 120rpx;
z-index: 1;
.call-btn { .incoming-control {
width: 120rpx; display: flex;
height: 120rpx; flex-direction: column;
border-radius: 50%; align-items: center;
display: flex; min-width: 120rpx;
align-items: center;
justify-content: center;
margin-bottom: 20rpx;
transition: all 0.2s;
&.decline-btn { .call-btn {
background-color: #f43f3b; width: 120rpx;
height: 120rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20rpx;
transition: all 0.2s;
&.btn-active { &.decline-btn {
transform: scale(0.9); background-color: #f43f3b;
background-color: #d93632;
}
}
&.accept-btn { &.btn-active {
background-color: #07c160; transform: scale(0.9);
background-color: #d93632;
}
}
&.btn-active { &.accept-btn {
transform: scale(0.9); background-color: #07c160;
background-color: #06ad56;
}
}
}
.btn-text { &.btn-active {
font-size: 28rpx; transform: scale(0.9);
color: #fff; background-color: #06ad56;
} }
} }
}
.action-bar { &.mic-btn {
position: absolute; background-color: rgba(255, 255, 255, 0.2);
bottom: 60rpx;
left: 0;
width: 100%;
display: flex;
justify-content: space-around;
padding: 0 60rpx;
z-index: 1;
.action-item { &.mic-muted {
display: flex; background-color: rgba(255, 255, 255, 0.1);
flex-direction: column; }
align-items: center;
.action-icon { &.btn-active {
width: 100rpx; transform: scale(0.9);
height: 100rpx; background-color: rgba(255, 255, 255, 0.3);
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 { &.speaker-btn {
background-color: rgba(255, 255, 255, 0.4); background-color: rgba(255, 255, 255, 0.2);
}
}
.action-text { &.speaker-on {
font-size: 24rpx; background-color: rgba(255, 255, 255, 0.3);
color: #fff; }
}
}
}
}
@keyframes ringPulse { &.btn-active {
0% { transform: scale(0.9);
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0.4); background-color: rgba(255, 255, 255, 0.3);
} }
}
}
70% { .btn-text {
box-shadow: 0 0 0 30rpx rgba(26, 173, 25, 0); font-size: 24rpx;
} color: #fff;
text-align: center;
}
}
}
}
100% { @keyframes ringPulse {
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0); 0% {
} box-shadow: 0 0 0 0 rgba(26, 173, 25, 0.4);
} }
/* 响应式调整 */ 70% {
@media (max-height: 600px) { box-shadow: 0 0 0 30rpx rgba(26, 173, 25, 0);
.incoming-controls { }
padding: 40rpx 100rpx 80rpx !important;
}
.action-bar { 100% {
bottom: 40rpx !important; box-shadow: 0 0 0 0 rgba(26, 173, 25, 0);
} }
} }
</style>
/* 响应式调整 */
@media (max-height: 600px) {
.incoming-controls {
padding: 40rpx 30rpx 80rpx !important;
}
}
</style>

View File

@@ -1,5 +1,15 @@
<template> <template>
<view class="content"> <view class="content">
<!-- 顶部栏 -->
<view class="top-bar">
<view class="top-left">
<!-- 通话时间显示 -->
<view v-if="callState === 'dialogue'" class="call-time-container">
<uni-icons type="sound" size="16" color="#fff"></uni-icons>
<text class="call-time">{{ formattedTime }}</text>
</view>
</view>
</view>
<!-- 单人视频 --> <!-- 单人视频 -->
<view v-if="users.length <= 2"> <view v-if="users.length <= 2">
<RongCloud-Call-RCUniCallView <RongCloud-Call-RCUniCallView
@@ -12,7 +22,7 @@
></RongCloud-Call-RCUniCallView> ></RongCloud-Call-RCUniCallView>
<RongCloud-Call-RCUniCallView <RongCloud-Call-RCUniCallView
class="smallVideoView" class="smallVideoView"
:style="{ width: 200 + 'upx', height: 200 + 'upx' }" :style="{ width: 400 + 'upx', height: 400 + 'upx' }"
ref="smallVideoView" ref="smallVideoView"
></RongCloud-Call-RCUniCallView> ></RongCloud-Call-RCUniCallView>
</view> </view>
@@ -111,7 +121,11 @@
ruddyVal: 0, ruddyVal: 0,
buffingVal: 0, buffingVal: 0,
brightnessVal: 5, brightnessVal: 5,
isChecked: false isChecked: false,
formattedTime: "00:00",
callState: "123",
callDuration: 0,
timer: null
} }
}, },
onLoad: function () { onLoad: function () {
@@ -150,6 +164,7 @@
}, },
onUnload() { onUnload() {
call.hangup() call.hangup()
this.stopTimer()
}, },
onHide() { onHide() {
const session = call.getCurrentCallSession() const session = call.getCurrentCallSession()
@@ -158,8 +173,31 @@
} }
uni.$off('OnCallDisconnected') uni.$off('OnCallDisconnected')
uni.$off('OnCallConnected') uni.$off('OnCallConnected')
this.stopTimer()
}, },
methods: { methods: {
/** 开始通话计时 */
startTimer(){
this.stopTimer() // 先停止之前的计时器
this.timer = setInterval(() => {
this.callDuration++
this.formatTime()
}, 1000)
},
/** 停止通话计时 */
stopTimer(){
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
},
/** 格式化时间显示 */
formatTime(){
const minutes = Math.floor(this.callDuration / 60)
const seconds = this.callDuration % 60
this.formattedTime = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
},
changeMediaType() { changeMediaType() {
if (this.mediaTypeCur == 'video') { if (this.mediaTypeCur == 'video') {
this.mediaTypeCur = 'audio' this.mediaTypeCur = 'audio'
@@ -369,6 +407,8 @@
}, },
processCallSession(){ processCallSession(){
this.callState = "dialogue"
this.startTimer()
// call.enableSpeaker(true) // call.enableSpeaker(true)
this.mediaTypeCur = this.mediaType this.mediaTypeCur = this.mediaType
this.currentCallSession = call.getCurrentCallSession() this.currentCallSession = call.getCurrentCallSession()
@@ -473,7 +513,49 @@
} }
</script> </script>
<style scoped> <style scoped lang="scss">
.top-bar {
position: fixed;
top: 30rpx;
left: 0;
width: 750rpx;
height: 120rpx;
flex-direction: row;
align-items: left;
padding-left: 40rpx;
padding-right: 40rpx;
padding-top: var(--safe-area-inset-top, 0);
z-index: 99;
box-sizing: border-box;
.top-left {
width: 140rpx;
height: 120rpx;
justify-content: center;
align-items: left;
.call-time-container {
flex-direction: row;
align-items: center;
justify-content: center;
background-color: rgba(255, 255, 255, 0.15);
padding-left: 20rpx;
padding-right: 20rpx;
padding-top: 8rpx;
padding-bottom: 8rpx;
border-radius: 30rpx;
/* nvue不支持backdrop-filter可以改用透明度或移除 */
/* backdrop-filter: blur(10px); */
}
.call-time {
font-size: 28rpx;
color: #ffffff;
font-weight: 500;
margin-left: 10rpx;
}
}
}
.nav-box { .nav-box {
position: fixed; position: fixed;
left: 0; left: 0;

View File

@@ -68,6 +68,7 @@ import {
getRongYunLoginInfo getRongYunLoginInfo
} from '../api' } from '../api'
import permision from "@/js_sdk/wa-permission/permission.js" import permision from "@/js_sdk/wa-permission/permission.js"
import { navigateTo } from '@/utils/router'
export const useUserStore = defineStore('user', () => { export const useUserStore = defineStore('user', () => {
const { const {
@@ -198,6 +199,7 @@ export const useUserStore = defineStore('user', () => {
permision.requestAndroidPermission('android.permission.CAMERA'); permision.requestAndroidPermission('android.permission.CAMERA');
permision.requestAndroidPermission('android.permission.RECORD_AUDIO'); permision.requestAndroidPermission('android.permission.RECORD_AUDIO');
} }
onAllListeners()
}); });
let code = await imEngine.value.connect(tencentUserSig.value.ryToken, 10) let code = await imEngine.value.connect(tencentUserSig.value.ryToken, 10)
if (code != 0) { if (code != 0) {
@@ -208,6 +210,121 @@ export const useUserStore = defineStore('user', () => {
}) })
} }
} }
function onAllListeners () {
CallLib.onCallReceived( (res)=> {
console.log(res)
console.log("Engine:OnCallReceived=>"+"监听通话呼入, 目标id=>", res.data.targetId);
if (res.data.targetId) {
// let url = res.data.mediaType == 0 ? "" : "/pages/room/room"
uni.setStorageSync('room-parameters', {
callType: 'in',
mediaType: res.data.mediaType === 0 ? 'audio' : 'video'
});
uni.showToast({
title:"有通话呼入该跳转了"+res.data.targetId,
duration:3000
})
navigateTo("/pages/room/incom", {
type: res.data.extra,
callType: 'in',
mediaType: res.data.mediaType == 0 ? "audio" : "video",
userID: res.data.mine.userId // 对方的用户id
})
}
});
CallLib.onCallDisconnected((res)=>{
console.log(res)
console.log("Engine:OnCallDisconnected=>"+"通话挂断/拒绝, 挂断原因=>", res.data.reason);
// 重新渲染视频视图
// uni.$emit('OnCallDisconnected');
uni.showToast({
title:reasonDeal(res.data.reason),
error:"error",
icon:'none',
duration:2000
})
goback()
});
CallLib.onCallConnected((res)=>{
console.log(res)
console.log("Engine:OnCallConnected=>"+"已建立通话通话接通时,通过回调 onCallConnected 通知当前 call 的详细信息", res);
});
CallLib.onRemoteUserInvited((res)=>{
console.log("Engine:OnRemoteUserInvited=>"+"通话中的某一个参与者,邀请好友加入通话 ,远端Id为=>", res.data.userId);
uni.$emit('OnCallConnected');
})
CallLib.onRemoteUserJoined((res)=>{
console.log("Engine:OnRemoteUserJoined=>"+"主叫端拨出电话被叫端收到请求后加入通话对端Id为=>", res.data.userId);
uni.$emit('OnCallConnected');
})
CallLib.onRemoteUserLeft((res)=>{
console.log("Engine:OnRemoteUserLeft=>"+"远端用户挂断(群聊触发)远端Id为=>", res.data.reason);
uni.$emit('OnCallConnected');
uni.showToast({
title:reasonDeal(res.data.reason),
error:"error",
icon:'none',
duration:2000
})
})
CallLib.onCallOutgoing((res)=>{
console.log('电话已拨出 主叫端拨出电话后,通过回调 onCallOutgoing 通知当前 call 的详细信息')
})
CallLib.onRemoteUserRinging((res)=>{
console.log('被叫端正在振铃,主叫端拨出电话,被叫端收到请求,发出振铃响应时,回调 onRemoteUserRingin,对端Id为=>', res.data.userId)
})
CallLib.onError((res)=>{
console.log('通话过程中,发生异常')
uni.showToast({
title:errorDeal(res.data.reason),
error:"error",
icon:'none',
duration:2000
});
goback()
})
CallLib.onRemoteUserMediaTypeChanged((res)=>{
console.log('当通话中的某一个参与者切换通话类型,例如由 audio 切换至 video回调 onMediaTypeChanged,切换媒体类型的Id为=>',res.data.user.userId);
})
}
function goback () {
const pages = getCurrentPages()
console.log('pages: ',pages);
if (pages.length > 1) {
console.log("走返回");
uni.showToast({
title:"走返回",
duration:3000
})
uni.navigateBack({
delta: 1
})
const currentPage = pages[pages.length - 1]
const prevPage = pages[pages.length - 2]
// 判断上一页是否是 tabBar 页面
// const isPrevPageTabBar = isTabBarPage(currentPage.route)
// if(!isPrevPageTabBar){
// }
}
}
// 判断页面是否是 tabBar 页面
function isTabBarPage(route) {
// 这里根据你的 pages.json 配置来判断
const tabBarPages = [
'TUIKit/components/TUIConversation/index',
'TUIKit/components/TUIContact/index',
'pages/discover/discover',
'pages/my-index/my-index'
]
// 判断路由是否在 tabBar 页面列表中
return tabBarPages.includes(route)
}
/** /**
* 清除用户信息(退出登录) * 清除用户信息(退出登录)