Merge remote-tracking branch 'origin/test-audio'

This commit is contained in:
cbb
2026-02-07 09:12:57 +08:00
7 changed files with 936 additions and 804 deletions

267
App.vue
View File

@@ -1,72 +1,219 @@
<script setup lang="ts">
// #ifdef APP-PLUS
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
// #endif
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { reLaunch } from './utils/router'
import { useAuthUser } from './composables/useAuthUser'
import { useUserStore } from './stores/user'
import { TUIChatKit } from './TUIKit'
import { getIpBlack } from './api'
// #ifdef APP-PLUS
import { setSdkLanguageFromSystem } from '@/uni_modules/tuikit-atomic-x/utils/setSdkLanguageFromSystem'
import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
// #endif
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { reLaunch } from './utils/router'
import { useAuthUser } from './composables/useAuthUser'
import { useUserStore } from './stores/user'
import { TUIChatKit } from './TUIKit'
import { getIpBlack } from './api'
import {reasonDeal,errorDeal,imCode} from '@/utils/code.js'
import { navigateTo } from '@/utils/router'
TUIChatKit.init()
TUIChatKit.init()
const { token, tencentUserSig } = useAuthUser()
const { loginTencentIM } = useUserStore()
/** 静默登录逻辑 */
const silentLogin = async (e: any) => {
if (token.value) {
loginTencentIM()
// reLaunch('/TUIKit/components/TUIConversation/index')
return
}
const { token, tencentUserSig } = useAuthUser()
const { loginTencentIM } = useUserStore()
/** 静默登录逻辑 */
const silentLogin = async (e : any) => {
if (token.value) {
loginTencentIM()
// reLaunch('/TUIKit/components/TUIConversation/index')
return
}
console.log(tencentUserSig, '=====222==')
if (e?.query?.invitationCode) {
reLaunch('/pages/login/phone-register/phone-register', {
invitationCode: e.query.invitationCode
})
} else {
// 没有token去登录页
reLaunch('/pages/login/login')
}
}
console.log(tencentUserSig, '=====222==')
if (e?.query?.invitationCode) {
reLaunch('/pages/login/phone-register/phone-register', {
invitationCode: e.query.invitationCode
})
} else {
// 没有token去登录页
reLaunch('/pages/login/login')
}
}
onLaunch((e: any) => {
// return
console.log('App Launch111')
silentLogin(e)
onLaunch((e : any) => {
// return
console.log('App Launch111')
silentLogin(e)
// #ifdef APP-PLUS
setSdkLanguageFromSystem()
// #endif
})
// #ifdef APP-PLUS
setSdkLanguageFromSystem()
onAllListeners()
// #endif
})
onShow(() => {
console.log('App Show222')
})
onShow(() => {
console.log('App Show222')
})
onHide(async () => {
if (token.value) {
const show = await getIpBlack(false)
console.log(show.data.data, '======')
}
console.log('App Hide333')
})
onHide(async () => {
if (token.value) {
const show = await getIpBlack(false)
console.log(show.data.data, '======')
}
// #ifdef APP-PLUS
removeAllListeners()
// #endif
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(){
call.unInit();
//移除监听-接收到通话呼入
call.removeCallReceivedListener();
// 移除监听-开始呼叫通话的回调
call.removeCallOutgoingListener();
// 移除监听-通话已接通
call.removeCallReceivedListener();
// 移除监听-通话已结束
call.removeCallDisconnectedListener();
// 移除监听-对端用户正在振铃
call.removeRemoteUserRingingListener();
// 移除监听-对端用户加入了通话
call.removeRemoteUserJoinedListener();
// 移除监听-有用户被邀请加入通话
call.removeRemoteUserInvited();
// 移除监听-对端用户挂断
call.removeRemoteUserLeftListener();
// 移除监听-对端用户切换了媒体类型
call.removeRemoteUserMediaTypeChangedListener();
// 移除监听-通话出现错误的回调
call.removeErrorListener();
}
</script>
<style lang="scss">
/*每个页面公共css */
@import './styles/global.scss';
/*每个页面公共css */
@import './styles/global.scss';
/* common css for page */
// uni-page-body,
// html,
// body,
// page {
// width: 100% !important;
// height: 100% !important;
// overflow: hidden;
// }
</style>
/* common css for page */
// uni-page-body,
// html,
// body,
// page {
// width: 100% !important;
// height: 100% !important;
// overflow: hidden;
// }
</style>

View File

@@ -1,106 +1,102 @@
<script setup lang="ts">
import ToolbarItemContainer from '../toolbar-item-container/index.vue'
import custom from '../../../../assets/icon/telephone-icon.svg'
import videoIcon from '../../../../assets/icon/video-icon.svg'
import { isUniFrameWork } from '../../../../utils/env'
import { computed, ref } from 'vue'
import { type IConversationModel } from '@tencentcloud/chat-uikit-engine-lite'
import { navigateTo } from '../../../../../utils/router'
import TUIChatEngine, {
TUIConversationService,
TUIFriendService,
TUIChatService
} from '@tencentcloud/chat-uikit-engine-lite'
import ToolbarItemContainer from '../toolbar-item-container/index.vue'
import custom from '../../../../assets/icon/telephone-icon.svg'
import videoIcon from '../../../../assets/icon/video-icon.svg'
import { isUniFrameWork } from '../../../../utils/env'
import { computed, ref } from 'vue'
import { type IConversationModel } from '@tencentcloud/chat-uikit-engine-lite'
import { navigateTo } from '../../../../../utils/router'
import TUIChatEngine, {
TUIConversationService,
TUIFriendService,
TUIChatService
} from '@tencentcloud/chat-uikit-engine-lite'
const props = withDefaults(
defineProps<{
/** 通话状态: 0 语音 1 视频 */
type?: '0' | '1'
/** 信息数据 */
currentConversation?: IConversationModel
}>(),
{
type: '0',
currentConversation: () => ({} as IConversationModel)
}
)
/** 语音通话状态 */
const isType = computed(() => props.type === '0')
const evaluateIcon = isType.value ? custom : videoIcon
const emits = defineEmits(['onDialogPopupShowOrHide'])
const container = ref()
const closeDialog = () => {
container?.value?.toggleDialogDisplay(false)
}
const onDialogShow = () => {
console.log('弹出窗口', props.currentConversation)
const data = props.currentConversation.userProfile
emits('onDialogPopupShowOrHide', true)
if (isType.value) {
let params ={
to: props.currentConversation.conversationID,
conversationType: TUIChatEngine.TYPES.CONV_C2C,
payload: {
text: "拨打语音"
}
const props = withDefaults(
defineProps<{
/** 通话状态: 0 语音 1 视频 */
type ?: '0' | '1'
/** 信息数据 */
currentConversation ?: IConversationModel
}>(),
{
type: '0',
currentConversation: () => ({} as IConversationModel)
}
console.log('params: ',params);
// TUIChatService.sendTextMessage(params)
navigateTo('/pages/room/incom', {
type: 'call',
userID: data.userID
})
} else {
let params ={
to: props.currentConversation.conversationID,
conversationType: TUIChatEngine.TYPES.CONV_C2C,
payload: {
text: "拨打视频"
)
/** 语音通话状态 */
const isType = computed(() => props.type === '0')
const evaluateIcon = isType.value ? custom : videoIcon
const emits = defineEmits(['onDialogPopupShowOrHide'])
const container = ref()
const closeDialog = () => {
container?.value?.toggleDialogDisplay(false)
}
const onDialogShow = () => {
console.log('弹出窗口', props.currentConversation)
const data = props.currentConversation.userProfile
emits('onDialogPopupShowOrHide', true)
if (isType.value) {
let params = {
to: props.currentConversation.conversationID,
conversationType: TUIChatEngine.TYPES.CONV_C2C,
payload: {
text: "拨打语音"
}
}
console.log('params: ', params);
// TUIChatService.sendTextMessage(params)
navigateTo('/pages/room/incom', {
type: 'call',
userID: data.userID,
mediaType: 'audio',
callType: 'out',
})
} else {
let params = {
to: props.currentConversation.conversationID,
conversationType: TUIChatEngine.TYPES.CONV_C2C,
payload: {
text: "拨打视频"
}
}
// TUIChatService.sendTextMessage(params)
uni.setStorageSync('room-parameters', {
callType: 'out',
mediaType: 'video',
targetId: data.userID,
callSelect: 'single',
});
navigateTo('/pages/room/room')
}
// TUIChatService.sendTextMessage(params)
uni.setStorageSync('room-parameters', {
callType: 'out',
mediaType: 'video',
targetId: data.userID,
callSelect: 'single',
});
navigateTo('/pages/room/room')
}
}
}
const onDialogClose = () => {
console.log('关闭窗口')
emits('onDialogPopupShowOrHide', false)
}
const onDialogClose = () => {
console.log('关闭窗口')
emits('onDialogPopupShowOrHide', false)
}
const onDial = () => {
const data = props.currentConversation.userProfile
// data.userID
// CallLib.enableMicrophone(true)
// CallLib.startSingleCall(data.userID, 0, '邀请您进行语音通话')
}
const onDial = () => {
const data = props.currentConversation.userProfile
// data.userID
// CallLib.enableMicrophone(true)
// CallLib.startSingleCall(data.userID, 0, '邀请您进行语音通话')
}
</script>
<template>
<!-- needBottomPopup -->
<ToolbarItemContainer
ref="container"
:iconFile="evaluateIcon"
:iconWidth="isUniFrameWork ? '34px' : '20px'"
:iconHeight="isUniFrameWork ? '34px' : '20px'"
:title="isType ? '语音通话' : '视频通话'"
@onDialogShow="onDialogShow"
@onDialogClose="onDialogClose"
>
<!-- <view class="box-index">
<!-- needBottomPopup -->
<ToolbarItemContainer ref="container" :iconFile="evaluateIcon" :iconWidth="isUniFrameWork ? '34px' : '20px'"
:iconHeight="isUniFrameWork ? '34px' : '20px'" :title="isType ? '语音通话' : '视频通话'" @onDialogShow="onDialogShow"
@onDialogClose="onDialogClose">
<!-- <view class="box-index">
<view class="top-icon">
<uni-icons
type="back"
@@ -134,7 +130,7 @@
挂点
</button>
</view> -->
</ToolbarItemContainer>
</ToolbarItemContainer>
</template>
<style scoped lang="scss" src="./style/index.scss"></style>
<style scoped lang="scss" src="./style/index.scss"></style>

View File

@@ -1,6 +1,6 @@
{
"name" : "密谈IM",
"appid" : "__UNI__D40A151",
"appid" : "__UNI__BE00EFC",
"description" : "",
"versionName" : "1.1.3",
"versionCode" : 112,
@@ -112,27 +112,13 @@
}
},
"nativePlugins" : {
"RongCloud-Beauty" : {
"__plugin_info__" : {
"name" : "RCUniBeauty",
"description" : "融云基础版美颜插件,服务于 RCUniRtc 或 RCUniCall",
"platforms" : "Android,iOS",
"url" : "https://ext.dcloud.net.cn/plugin?id=7982",
"android_package_name" : "",
"ios_bundle_id" : "",
"isCloud" : true,
"bought" : 1,
"pid" : "7982",
"parameters" : {}
}
},
"RongCloud-Call" : {
"__plugin_info__" : {
"name" : "RCUniCall",
"description" : "融云实时音视频 SDK uni 原生插件",
"platforms" : "Android,iOS",
"url" : "https://ext.dcloud.net.cn/plugin?id=6372",
"android_package_name" : "uni.app.UNI9EFDC69WWCC",
"android_package_name" : "uni.app.UNI9EFDC69",
"ios_bundle_id" : "",
"isCloud" : true,
"bought" : 1,
@@ -146,7 +132,7 @@
"description" : "融云即时通讯 SDK uni 原生插件V2",
"platforms" : "Android,iOS",
"url" : "https://ext.dcloud.net.cn/plugin?id=9227",
"android_package_name" : "uni.app.UNI9EFDC69WWCC",
"android_package_name" : "uni.app.UNI9EFDC69",
"ios_bundle_id" : "",
"isCloud" : true,
"bought" : 1,

View File

@@ -444,14 +444,14 @@
{
"path": "pages/room/room",
"style": {
"navigationBarTitleText": "拨打电话",
"navigationBarTitleText": "拨打视频",
"navigationStyle": "custom"
}
},
{
"path": "pages/room/incom",
"style": {
"navigationBarTitleText": "拨打视频",
"navigationBarTitleText": "拨打电话",
"navigationStyle": "custom"
}
},

View File

@@ -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>

View File

@@ -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':

View File

@@ -1,326 +1,302 @@
import { defineStore } from 'pinia'
import {
getToken,
getUserInfoData,
setUserInfoData,
removeUserInfoData,
getSig,
setSig,
removeSig,
getFontSize,
setFontSize,
removeFontSize
defineStore
} from 'pinia'
import {
getToken,
getUserInfoData,
setUserInfoData,
removeUserInfoData,
getSig,
setSig,
removeSig,
getFontSize,
setFontSize,
removeFontSize
} from '@/utils/storage'
// #ifdef APP-PLUS
import { useLoginState } from '@/uni_modules/tuikit-atomic-x/state/LoginState'
import {
useLoginState
} from '@/uni_modules/tuikit-atomic-x/state/LoginState'
import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
import RCIMIWEngine from '@/uni_modules/RongCloud-IMWrapper-V2/js_sdk/RCIMEngine'
import { reasonDeal, errorDeal, imCode } from '@/utils/code.js'
import {
reasonDeal,
errorDeal,
imCode
} from '@/utils/code.js'
// #endif
// #ifdef H5
import { useLoginState } from 'tuikit-atomicx-vue3'
import {
useLoginState
} from 'tuikit-atomicx-vue3'
// #endif
import { useTokenStore } from './token'
import { getUserData, userLogout, updateUserData } from '@/api'
import { ref } from 'vue'
import { useUI } from '@/utils/use-ui'
import { reLaunch } from '@/utils/router'
import { getTencentUserSig } from '@/api'
import { TUILogin } from '@tencentcloud/tui-core-lite'
import { TUIChatEngine } from '@tencentcloud/chat-uikit-engine-lite'
import { getUserIntegral } from '@/api/my-index'
import { removeFriendList, removeGroupList } from '../utils/storage'
import { getRongYunLoginInfo } from '../api'
import {
useTokenStore
} from './token'
import {
getUserData,
userLogout,
updateUserData
} from '@/api'
import {
ref
} from 'vue'
import {
useUI
} from '@/utils/use-ui'
import {
reLaunch
} from '@/utils/router'
import {
getTencentUserSig
} from '@/api'
import {
TUILogin
} from '@tencentcloud/tui-core-lite'
import {
TUIChatEngine
} from '@tencentcloud/chat-uikit-engine-lite'
import {
getUserIntegral
} from '@/api/my-index'
import {
removeFriendList,
removeGroupList
} from '../utils/storage'
import {
getRongYunLoginInfo
} from '../api'
import permision from "@/js_sdk/wa-permission/permission.js"
export const useUserStore = defineStore('user', () => {
const { clearToken } = useTokenStore()
const { showDialog, showToast } = useUI()
const {
clearToken
} = useTokenStore()
const {
showDialog,
showToast
} = useUI()
const userInfo = ref(
getUserInfoData() ? JSON?.parse(getUserInfoData()) : {}
)
/** 用户字体大小 */
const fontSizeData = ref(getFontSize())
const userInfo = ref(
getUserInfoData() ? JSON?.parse(getUserInfoData()) : {}
)
/** 用户字体大小 */
const fontSizeData = ref(getFontSize())
/** 腾讯 IM 存储数据 */
const tencentUserSig = ref(getSig() ? JSON?.parse(getSig()) : {})
/** 腾讯 IM 存储数据 */
const tencentUserSig = ref(getSig() ? JSON?.parse(getSig()) : {})
/** 用户积分数 */
const integralData = ref(0)
/** 融云 IM 引擎 */
const imEngine = ref(null)
/** 用户积分数 */
const integralData = ref(0)
/** 融云 IM 引擎 */
const imEngine = ref(null)
/**
* 获取用户信息(可从缓存或接口)
*/
const fetchUserInfo = async () => {
// 尝试从本地缓存读取
const cachedToken = getToken()
const cachedUserInfo = getUserInfoData()
const cachedSig = getSig()
/**
* 获取用户信息(可从缓存或接口)
*/
const fetchUserInfo = async () => {
// 尝试从本地缓存读取
const cachedToken = getToken()
const cachedUserInfo = getUserInfoData()
const cachedSig = getSig()
if (cachedToken && cachedUserInfo) {
userInfo.value = JSON.parse(cachedUserInfo)
tencentUserSig.value = JSON.parse(cachedSig)
loginTencentIM()
return
}
await getIntegral()
const res = await getUserData()
await setUserInfo(res.data)
loginTencentIM()
return
}
if (cachedToken && cachedUserInfo) {
userInfo.value = JSON.parse(cachedUserInfo)
tencentUserSig.value = JSON.parse(cachedSig)
loginTencentIM()
return
}
await getIntegral()
const res = await getUserData()
await setUserInfo(res.data)
loginTencentIM()
return
}
/**
* 设置用户信息
*/
const setUserInfo = async data => {
const res = await getTencentUserSig()
const ryData = await getRongYunLoginInfo()
const IM_DATA = {
...res.data,
...ryData.data
}
tencentUserSig.value = IM_DATA
userInfo.value = data
setUserInfoData(data)
setSig(IM_DATA)
}
/**
* 设置用户信息
*/
const setUserInfo = async data => {
const res = await getTencentUserSig()
const ryData = await getRongYunLoginInfo()
const IM_DATA = {
...res.data,
...ryData.data
}
tencentUserSig.value = IM_DATA
userInfo.value = data
setUserInfoData(data)
setSig(IM_DATA)
}
/** 获取用户积分 */
const getIntegral = async () => {
const res = await getUserIntegral()
integralData.value = res.data.availablePoints
}
/** 获取用户积分 */
const getIntegral = async () => {
const res = await getUserIntegral()
integralData.value = res.data.availablePoints
}
/**
* 登录腾讯 IM
*/
const loginTencentIM = async () => {
await refreshUserInfo()
await TUILogin.login({
SDKAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig,
framework: `vue3`
})
/**
* 登录腾讯 IM
*/
const loginTencentIM = async () => {
await refreshUserInfo()
await TUILogin.login({
SDKAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig,
framework: `vue3`
})
await TUIChatEngine.login({
SDKAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig,
useUploadPlugin: true // 使用文件上传插件
})
// #ifdef H5
await useLoginState().login({
SDKAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig
})
// #endif
await TUIChatEngine.login({
SDKAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig,
useUploadPlugin: true // 使用文件上传插件
})
// #ifdef H5
await useLoginState().login({
SDKAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig
})
// #endif
// #ifdef APP-PLUS
await useLoginState().login({
sdkAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig
})
console.log(tencentUserSig.value.appKey, '====')
await connectIM()
// #endif
// #ifdef APP-PLUS
// CallLib.init({})
CallLib.onCallReceived(res => {
console.log(
'Engine:OnCallReceived=>' + '监听通话呼入, 目标id=>',
res.data
)
console.log('res: ',res.data);
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'
// #ifdef APP-PLUS
await useLoginState().login({
sdkAppID: tencentUserSig.value.sdkappID,
userID: tencentUserSig.value.userId,
userSig: tencentUserSig.value.userSig
})
console.log(tencentUserSig.value.appKey, '====')
await connectIM()
// #endif
}
//连接融云IM
const connectIM = async () => {
let options = {}
imEngine.value = await RCIMIWEngine.create(tencentUserSig.value.appKey, options)
imEngine.value.setOnConnectedListener((res) => {
if (res.code != 0) {
uni.hideLoading();
// uni.showToast({
// title: 'OnCon:' + res.code,
// icon: 'error'
// })
console.log("连接已存在");
// return
}
//连接成功
CallLib.init({});
console.log('call.init')
uni.hideLoading();
uni.showToast({
title: res.userId
});
uni.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(
'Engine:OnCallDisconnected=>' + '挂断成功, 挂断原因=>',
res.data.reason
)
uni.navigateBack()
})
CallLib.onError(res => {
console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
uni.navigateBack()
})
// #endif
}
if (uni.getSystemInfoSync().platform === 'android') {
permision.requestAndroidPermission('android.permission.CAMERA');
permision.requestAndroidPermission('android.permission.RECORD_AUDIO');
}
});
let code = await imEngine.value.connect(tencentUserSig.value.ryToken, 10)
if (code != 0) {
uni.hideLoading();
uni.showToast({
title: 'connect:' + code,
icon: 'error'
})
}
}
//连接融云IM
const connectIM = async () => {
const options = {
naviServer: ''
}
imEngine.value = await RCIMIWEngine.create(
tencentUserSig.value.appKey,
options
)
imEngine.value.setOnConnectedListener(res => {
if (res.code != 0) {
uni.hideLoading()
uni.showToast({
title: 'OnCon:' + res.code,
icon: 'error'
})
return
}
//连接成功
CallLib.init({})
console.log('call.init')
// this.libPage = true;
// this.loginUserId = res.userId;
uni.hideLoading()
console.log('登录成功')
})
const callback = {
onDatabaseOpened: res => {
console.log('数据库打开')
},
onConnected: res => {
console.log(res)
if (res.code === 0) {
// uni.showToast({
// title: '连接成功',
// icon: 'none'
// })
console.log('连接成功')
} else if (res.code === 34001) {
// uni.showToast({
// title: '连接已存在,不需要再连接',
// icon: 'none'
// })
console.log('连接已存在,不需要再连接')
}
}
}
let code = await imEngine.value.connect(
tencentUserSig.value.ryToken,
10,
callback
)
if (code != 0) {
uni.hideLoading()
uni.showToast({
title: 'connect:' + code,
icon: 'error'
})
}
}
/**
* 清除用户信息(退出登录)
*/
const clearUserInfo = async () => {
const show = await showDialog('提示', '确定要退出登录吗?')
if (show) {
await logout()
}
}
/**
* 清除用户信息(退出登录)
*/
const clearUserInfo = async () => {
const show = await showDialog('提示', '确定要退出登录吗?')
if (show) {
await logout()
}
}
/**
* 退出登录(不带提示
*/
const logout = async () => {
if (!userInfo.value) return
try {
userInfo.value = null
/**
* 退出登录(不带提示)
*/
const logout = async () => {
if (!userInfo.value) return
try {
userInfo.value = null
await userLogout()
await TUILogin.logout()
await TUIChatEngine.logout()
// #ifdef APP-PLUS
removeFriendList()
removeGroupList()
await useLoginState().logout()
// #endif
// #ifdef H5
await useLoginState().logout()
// #endif
clearAllUserInfo()
await showToast('退出登录成功', 'success')
reLaunch('/pages/login/login')
} catch (error) {
clearAllUserInfo()
await showToast('退出登录成功', 'success')
reLaunch('/pages/login/login')
}
}
await userLogout()
await TUILogin.logout()
await TUIChatEngine.logout()
// #ifdef APP-PLUS
removeFriendList()
removeGroupList()
await useLoginState().logout()
// #endif
// #ifdef H5
await useLoginState().logout()
// #endif
clearAllUserInfo()
await showToast('退出登录成功', 'success')
reLaunch('/pages/login/login')
} catch (error) {
clearAllUserInfo()
await showToast('退出登录成功', 'success')
reLaunch('/pages/login/login')
}
}
/** 清空所有用户缓存 */
const clearAllUserInfo = async () => {
userInfo.value = null
tencentUserSig.value = null
fontSizeData.value = 26
clearToken()
removeUserInfoData()
removeSig()
removeFontSize()
}
/** 清空所有用户缓存 */
const clearAllUserInfo = async () => {
userInfo.value = null
tencentUserSig.value = null
fontSizeData.value = 26
clearToken()
removeUserInfoData()
removeSig()
removeFontSize()
}
/** 刷新用户信息(如用户信息被修改) */
const refreshUserInfo = async () => {
const res = await getUserData()
await getIntegral()
await setUserInfoData(res.data)
userInfo.value = res.data
}
/** 刷新用户信息(如用户信息被修改) */
const refreshUserInfo = async () => {
const res = await getUserData()
await getIntegral()
await setUserInfoData(res.data)
userInfo.value = res.data
}
/**
* 更新部分用户信息(例如昵称、头像)
*/
const updateUserInfo = async partialData => {
if (!userInfo.value) return
await updateUserData(partialData)
await refreshUserInfo()
}
/**
* 更新部分用户信息(例如昵称、头像)
*/
const updateUserInfo = async partialData => {
if (!userInfo.value) return
await updateUserData(partialData)
await refreshUserInfo()
}
/** 更新字体大小 */
const updateFontSize = async fontSize => {
fontSizeData.value = fontSize
setFontSize(fontSize)
}
/** 更新字体大小 */
const updateFontSize = async fontSize => {
fontSizeData.value = fontSize
setFontSize(fontSize)
}
return {
imEngine,
userInfo,
integralData,
tencentUserSig,
fontSizeData,
getIntegral,
clearAllUserInfo,
updateFontSize,
logout,
refreshUserInfo,
fetchUserInfo,
loginTencentIM,
setUserInfo,
clearUserInfo,
updateUserInfo
}
})
return {
imEngine,
userInfo,
integralData,
tencentUserSig,
fontSizeData,
getIntegral,
clearAllUserInfo,
updateFontSize,
logout,
refreshUserInfo,
fetchUserInfo,
loginTencentIM,
setUserInfo,
clearUserInfo,
updateUserInfo
}
})