Merge remote-tracking branch 'origin/test-audio'
This commit is contained in:
267
App.vue
267
App.vue
@@ -1,72 +1,219 @@
|
|||||||
<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'
|
||||||
// #endif
|
import * as call from "@/uni_modules/RongCloud-CallWrapper/lib/index"
|
||||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
// #endif
|
||||||
import { reLaunch } from './utils/router'
|
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||||
import { useAuthUser } from './composables/useAuthUser'
|
import { reLaunch } from './utils/router'
|
||||||
import { useUserStore } from './stores/user'
|
import { useAuthUser } from './composables/useAuthUser'
|
||||||
import { TUIChatKit } from './TUIKit'
|
import { useUserStore } from './stores/user'
|
||||||
import { getIpBlack } from './api'
|
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 { token, tencentUserSig } = useAuthUser()
|
||||||
const { loginTencentIM } = useUserStore()
|
const { loginTencentIM } = useUserStore()
|
||||||
/** 静默登录逻辑 */
|
/** 静默登录逻辑 */
|
||||||
const silentLogin = async (e: any) => {
|
const silentLogin = async (e : any) => {
|
||||||
if (token.value) {
|
if (token.value) {
|
||||||
loginTencentIM()
|
loginTencentIM()
|
||||||
// reLaunch('/TUIKit/components/TUIConversation/index')
|
// reLaunch('/TUIKit/components/TUIConversation/index')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(tencentUserSig, '=====222==')
|
console.log(tencentUserSig, '=====222==')
|
||||||
if (e?.query?.invitationCode) {
|
if (e?.query?.invitationCode) {
|
||||||
reLaunch('/pages/login/phone-register/phone-register', {
|
reLaunch('/pages/login/phone-register/phone-register', {
|
||||||
invitationCode: e.query.invitationCode
|
invitationCode: e.query.invitationCode
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// 没有token去登录页
|
// 没有token去登录页
|
||||||
reLaunch('/pages/login/login')
|
reLaunch('/pages/login/login')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onLaunch((e: any) => {
|
onLaunch((e : any) => {
|
||||||
// return
|
// return
|
||||||
console.log('App Launch111')
|
console.log('App Launch111')
|
||||||
silentLogin(e)
|
silentLogin(e)
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
setSdkLanguageFromSystem()
|
setSdkLanguageFromSystem()
|
||||||
// #endif
|
onAllListeners()
|
||||||
})
|
// #endif
|
||||||
|
})
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
console.log('App Show222')
|
console.log('App Show222')
|
||||||
})
|
})
|
||||||
|
|
||||||
onHide(async () => {
|
onHide(async () => {
|
||||||
if (token.value) {
|
if (token.value) {
|
||||||
const show = await getIpBlack(false)
|
const show = await getIpBlack(false)
|
||||||
console.log(show.data.data, '======')
|
console.log(show.data.data, '======')
|
||||||
}
|
}
|
||||||
|
// #ifdef APP-PLUS
|
||||||
console.log('App Hide333')
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
/*每个页面公共css */
|
/*每个页面公共css */
|
||||||
@import './styles/global.scss';
|
@import './styles/global.scss';
|
||||||
|
|
||||||
/* common css for page */
|
/* common css for page */
|
||||||
// uni-page-body,
|
// uni-page-body,
|
||||||
// html,
|
// html,
|
||||||
// body,
|
// body,
|
||||||
// page {
|
// page {
|
||||||
// width: 100% !important;
|
// width: 100% !important;
|
||||||
// height: 100% !important;
|
// height: 100% !important;
|
||||||
// overflow: hidden;
|
// overflow: hidden;
|
||||||
// }
|
// }
|
||||||
</style>
|
</style>
|
||||||
@@ -1,106 +1,102 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ToolbarItemContainer from '../toolbar-item-container/index.vue'
|
import ToolbarItemContainer from '../toolbar-item-container/index.vue'
|
||||||
import custom from '../../../../assets/icon/telephone-icon.svg'
|
import custom from '../../../../assets/icon/telephone-icon.svg'
|
||||||
import videoIcon from '../../../../assets/icon/video-icon.svg'
|
import videoIcon from '../../../../assets/icon/video-icon.svg'
|
||||||
import { isUniFrameWork } from '../../../../utils/env'
|
import { isUniFrameWork } from '../../../../utils/env'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { type IConversationModel } from '@tencentcloud/chat-uikit-engine-lite'
|
import { type IConversationModel } from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
import { navigateTo } from '../../../../../utils/router'
|
import { navigateTo } from '../../../../../utils/router'
|
||||||
import TUIChatEngine, {
|
import TUIChatEngine, {
|
||||||
TUIConversationService,
|
TUIConversationService,
|
||||||
TUIFriendService,
|
TUIFriendService,
|
||||||
TUIChatService
|
TUIChatService
|
||||||
} from '@tencentcloud/chat-uikit-engine-lite'
|
} from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
/** 通话状态: 0 语音 1 视频 */
|
/** 通话状态: 0 语音 1 视频 */
|
||||||
type?: '0' | '1'
|
type ?: '0' | '1'
|
||||||
/** 信息数据 */
|
/** 信息数据 */
|
||||||
currentConversation?: IConversationModel
|
currentConversation ?: IConversationModel
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
type: '0',
|
type: '0',
|
||||||
currentConversation: () => ({} as IConversationModel)
|
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: "拨打语音"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log('params: ',params);
|
)
|
||||||
// TUIChatService.sendTextMessage(params)
|
|
||||||
navigateTo('/pages/room/incom', {
|
/** 语音通话状态 */
|
||||||
type: 'call',
|
const isType = computed(() => props.type === '0')
|
||||||
userID: data.userID
|
|
||||||
})
|
const evaluateIcon = isType.value ? custom : videoIcon
|
||||||
} else {
|
|
||||||
let params ={
|
const emits = defineEmits(['onDialogPopupShowOrHide'])
|
||||||
to: props.currentConversation.conversationID,
|
|
||||||
conversationType: TUIChatEngine.TYPES.CONV_C2C,
|
const container = ref()
|
||||||
payload: {
|
const closeDialog = () => {
|
||||||
text: "拨打视频"
|
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 = () => {
|
const onDialogClose = () => {
|
||||||
console.log('关闭窗口')
|
console.log('关闭窗口')
|
||||||
emits('onDialogPopupShowOrHide', false)
|
emits('onDialogPopupShowOrHide', false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDial = () => {
|
const onDial = () => {
|
||||||
const data = props.currentConversation.userProfile
|
const data = props.currentConversation.userProfile
|
||||||
// data.userID
|
// data.userID
|
||||||
// CallLib.enableMicrophone(true)
|
// CallLib.enableMicrophone(true)
|
||||||
// CallLib.startSingleCall(data.userID, 0, '邀请您进行语音通话')
|
// CallLib.startSingleCall(data.userID, 0, '邀请您进行语音通话')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- needBottomPopup -->
|
<!-- needBottomPopup -->
|
||||||
<ToolbarItemContainer
|
<ToolbarItemContainer ref="container" :iconFile="evaluateIcon" :iconWidth="isUniFrameWork ? '34px' : '20px'"
|
||||||
ref="container"
|
:iconHeight="isUniFrameWork ? '34px' : '20px'" :title="isType ? '语音通话' : '视频通话'" @onDialogShow="onDialogShow"
|
||||||
:iconFile="evaluateIcon"
|
@onDialogClose="onDialogClose">
|
||||||
:iconWidth="isUniFrameWork ? '34px' : '20px'"
|
<!-- <view class="box-index">
|
||||||
:iconHeight="isUniFrameWork ? '34px' : '20px'"
|
|
||||||
:title="isType ? '语音通话' : '视频通话'"
|
|
||||||
@onDialogShow="onDialogShow"
|
|
||||||
@onDialogClose="onDialogClose"
|
|
||||||
>
|
|
||||||
<!-- <view class="box-index">
|
|
||||||
<view class="top-icon">
|
<view class="top-icon">
|
||||||
<uni-icons
|
<uni-icons
|
||||||
type="back"
|
type="back"
|
||||||
@@ -134,7 +130,7 @@
|
|||||||
挂点
|
挂点
|
||||||
</button>
|
</button>
|
||||||
</view> -->
|
</view> -->
|
||||||
</ToolbarItemContainer>
|
</ToolbarItemContainer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss" src="./style/index.scss"></style>
|
<style scoped lang="scss" src="./style/index.scss"></style>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "密谈IM",
|
"name" : "密谈IM",
|
||||||
"appid" : "__UNI__D40A151",
|
"appid" : "__UNI__BE00EFC",
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"versionName" : "1.1.3",
|
"versionName" : "1.1.3",
|
||||||
"versionCode" : 112,
|
"versionCode" : 112,
|
||||||
@@ -112,27 +112,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nativePlugins" : {
|
"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" : {
|
"RongCloud-Call" : {
|
||||||
"__plugin_info__" : {
|
"__plugin_info__" : {
|
||||||
"name" : "RCUniCall",
|
"name" : "RCUniCall",
|
||||||
"description" : "融云实时音视频 SDK uni 原生插件",
|
"description" : "融云实时音视频 SDK uni 原生插件",
|
||||||
"platforms" : "Android,iOS",
|
"platforms" : "Android,iOS",
|
||||||
"url" : "https://ext.dcloud.net.cn/plugin?id=6372",
|
"url" : "https://ext.dcloud.net.cn/plugin?id=6372",
|
||||||
"android_package_name" : "uni.app.UNI9EFDC69WWCC",
|
"android_package_name" : "uni.app.UNI9EFDC69",
|
||||||
"ios_bundle_id" : "",
|
"ios_bundle_id" : "",
|
||||||
"isCloud" : true,
|
"isCloud" : true,
|
||||||
"bought" : 1,
|
"bought" : 1,
|
||||||
@@ -146,7 +132,7 @@
|
|||||||
"description" : "融云即时通讯 SDK uni 原生插件V2",
|
"description" : "融云即时通讯 SDK uni 原生插件V2",
|
||||||
"platforms" : "Android,iOS",
|
"platforms" : "Android,iOS",
|
||||||
"url" : "https://ext.dcloud.net.cn/plugin?id=9227",
|
"url" : "https://ext.dcloud.net.cn/plugin?id=9227",
|
||||||
"android_package_name" : "uni.app.UNI9EFDC69WWCC",
|
"android_package_name" : "uni.app.UNI9EFDC69",
|
||||||
"ios_bundle_id" : "",
|
"ios_bundle_id" : "",
|
||||||
"isCloud" : true,
|
"isCloud" : true,
|
||||||
"bought" : 1,
|
"bought" : 1,
|
||||||
|
|||||||
@@ -444,14 +444,14 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/room/room",
|
"path": "pages/room/room",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "拨打电话",
|
"navigationBarTitleText": "拨打视频",
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/room/incom",
|
"path": "pages/room/incom",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "拨打视频",
|
"navigationBarTitleText": "拨打电话",
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,395 +1,379 @@
|
|||||||
<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"
|
:src="callBackground"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
class="bg-image"
|
class="bg-image"
|
||||||
></image>
|
></image>
|
||||||
<view class="bg-overlay"></view>
|
<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>
|
</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
|
||||||
:class="{ 'btn-active': activeBtn === 'decline' }"
|
v-if="callerInfo?.avatar"
|
||||||
>
|
:src="callerInfo?.avatar"
|
||||||
<uni-icons type="closeempty" size="32" color="#fff"></uni-icons>
|
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>
|
</view>
|
||||||
<text class="btn-text">{{ callState === 'call' || callState == 'dialogue' ? "挂断" : "拒绝" }}</text>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<view
|
<!-- 控制按钮 -->
|
||||||
v-if="callState === 'answer'"
|
<view class="incoming-controls">
|
||||||
class="incoming-control"
|
<view class="incoming-control" @click="cutFn(false)">
|
||||||
@click="cutFn(true)"
|
<view
|
||||||
>
|
class="call-btn decline-btn"
|
||||||
<view
|
:class="{ 'btn-active': activeBtn === 'decline' }"
|
||||||
class="call-btn accept-btn"
|
>
|
||||||
:class="{ 'btn-active': activeBtn === 'accept' }"
|
<uni-icons type="closeempty" size="32" color="#fff"></uni-icons>
|
||||||
>
|
</view>
|
||||||
<uni-icons
|
<text class="btn-text">{{ callState === 'call' || callState == 'dialogue' ? "挂断" : "拒绝" }}</text>
|
||||||
type="checkmarkempty"
|
</view>
|
||||||
size="28"
|
|
||||||
color="#fff"
|
<view
|
||||||
></uni-icons>
|
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>
|
</view>
|
||||||
<text class="btn-text">接听</text>
|
|
||||||
</view>
|
|
||||||
</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 { ref, watch } from 'vue'
|
||||||
import { onLoad, onUnload, onHide } from '@dcloudio/uni-app'
|
import { onLoad, onUnload, onHide } from '@dcloudio/uni-app'
|
||||||
import { TUIUserService } from '@tencentcloud/chat-uikit-engine-lite'
|
import { TUIUserService } from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
import { useUI } from '../../utils/use-ui'
|
import { useUI } from '../../utils/use-ui'
|
||||||
import { navigateBack } from '../../utils/router'
|
import { navigateBack } from '../../utils/router'
|
||||||
|
|
||||||
CallLib.init({})
|
|
||||||
const { showLoading, hideLoading } = useUI()
|
const { showLoading, hideLoading } = useUI()
|
||||||
const callBackground = ref('/static/images/public/random2.png')
|
const callBackground = ref('/static/images/public/random2.png')
|
||||||
/** 呼叫用户信息 */
|
/** 呼叫用户信息 */
|
||||||
const callerInfo = ref({})
|
const callerInfo = ref({})
|
||||||
/** 通话状态 */
|
/** 通话状态 */
|
||||||
const isRinging = ref(true)
|
const isRinging = ref(true)
|
||||||
/** 控制按钮状态 */
|
/** 控制按钮状态 */
|
||||||
const activeBtn = ref(null)
|
const activeBtn = ref(null)
|
||||||
/**
|
/**
|
||||||
* 拨打状态
|
* 拨打状态
|
||||||
* call: 发起呼叫
|
* call: 发起呼叫
|
||||||
* answer: 接听
|
* answer: 接听
|
||||||
* dialogue: 对话中
|
* dialogue: 对话中
|
||||||
*/
|
*/
|
||||||
const callState = ref('')
|
const callState = ref('')
|
||||||
CallLib.onRemoteUserJoined(res => {
|
CallLib.onRemoteUserJoined(res => {
|
||||||
console.log(
|
console.log(
|
||||||
'Engine:OnRemoteUserJoined=>' +
|
'Engine:OnRemoteUserJoined=>' +
|
||||||
'主叫端拨出电话,被叫端收到请求后,加入通话,被叫端Id为=>',
|
'主叫端拨出电话,被叫端收到请求后,加入通话,被叫端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 => {
|
// CallLib.onRemoteUserRinging(res => {
|
||||||
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
// console.log(
|
||||||
// })
|
// '主叫端拨出电话,被叫端收到请求,发出振铃响应时触发,对端Id为=>',
|
||||||
|
// res.data.userId
|
||||||
|
// )
|
||||||
|
// })
|
||||||
|
|
||||||
/** 按钮状态 */
|
// CallLib.onError(res => {
|
||||||
const cutFn = show => {
|
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
||||||
|
// })
|
||||||
|
|
||||||
|
/** 按钮状态 */
|
||||||
|
const cutFn = show => {
|
||||||
if (show) {
|
if (show) {
|
||||||
// 接听电话 dialogue
|
// 接听电话 dialogue
|
||||||
if(mediaType.value === 'audio'){
|
if(mediaType.value === 'audio'){
|
||||||
CallLib.enableMicrophone(true)
|
CallLib.enableMicrophone(true)
|
||||||
}
|
}
|
||||||
CallLib.accept()
|
CallLib.accept()
|
||||||
callState.value = 'dialogue'
|
callState.value = 'dialogue'
|
||||||
if(mediaType.value === 'video'){
|
if(mediaType.value === 'video'){
|
||||||
uni.redirectTo({
|
uni.redirectTo({
|
||||||
url: "/pages/room/room"
|
url: "/pages/room/room"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//取消接听,返回上一页
|
//取消接听,返回上一页
|
||||||
CallLib.hangup()
|
CallLib.hangup()
|
||||||
navigateBack()
|
// navigateBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaType= ref("audio")
|
const mediaType= ref("audio")
|
||||||
|
|
||||||
onLoad(async e => {
|
onLoad(async e => {
|
||||||
callState.value = e.type
|
callState.value = e.type
|
||||||
mediaType.value = e.mediaType
|
mediaType.value = e.mediaType
|
||||||
console.log(e)
|
console.log(e)
|
||||||
showLoading()
|
showLoading()
|
||||||
const res = await TUIUserService.getUserProfile({
|
const res = await TUIUserService.getUserProfile({
|
||||||
userIDList: [e.userID]
|
userIDList: [e.userID]
|
||||||
})
|
})
|
||||||
hideLoading()
|
hideLoading()
|
||||||
callerInfo.value = res.data[0]
|
callerInfo.value = res.data[0]
|
||||||
if (e.type === 'call') {
|
if (e.type === 'call') {
|
||||||
CallLib.enableMicrophone(true)
|
CallLib.enableMicrophone(true)
|
||||||
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
|
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
|
||||||
}
|
}
|
||||||
if(e.callType == "in"){
|
if(e.callType == "in"){
|
||||||
// 接听语音通话
|
// 接听语音通话
|
||||||
callState.value = 'answer'
|
callState.value = 'answer'
|
||||||
}
|
}
|
||||||
console.log('callState.value: ',callState.value);
|
console.log('callState.value: ',callState.value);
|
||||||
console.log('===好友信息', res)
|
console.log('===好友信息', res)
|
||||||
})
|
})
|
||||||
|
|
||||||
// onUnload( ()=>{
|
|
||||||
// removeAllListeners()
|
|
||||||
// })
|
|
||||||
|
|
||||||
// onHide( ()=>{
|
|
||||||
// removeAllListeners()
|
|
||||||
// })
|
|
||||||
|
|
||||||
function removeAllListeners(){
|
|
||||||
//移除监听-接收到通话呼入
|
|
||||||
CallLib.removeRemoteUserJoinedListener();
|
|
||||||
// 移除监听-通话已结束
|
|
||||||
CallLib.removeCallDisconnectedListener();
|
|
||||||
// 移除监听-通话出现错误的回调
|
|
||||||
CallLib.removeErrorListener();
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.incoming-call {
|
.incoming-call {
|
||||||
position: fixed;
|
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;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 9999;
|
z-index: 0;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-between;
|
|
||||||
background-color: #000;
|
|
||||||
|
|
||||||
.blur-background {
|
.bg-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
filter: blur(20px);
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bg-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 0;
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.bg-image {
|
.caller-info {
|
||||||
width: 100%;
|
flex: 1;
|
||||||
height: 100%;
|
display: flex;
|
||||||
filter: blur(20px);
|
flex-direction: column;
|
||||||
opacity: 0.6;
|
align-items: center;
|
||||||
}
|
justify-content: center;
|
||||||
|
padding-top: 100rpx;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
.bg-overlay {
|
.caller-avatar-container {
|
||||||
position: absolute;
|
position: relative;
|
||||||
top: 0;
|
margin-bottom: 40rpx;
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
.caller-avatar {
|
||||||
height: 100%;
|
width: 180rpx;
|
||||||
background: rgba(0, 0, 0, 0.5);
|
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 {
|
.caller-name {
|
||||||
flex: 1;
|
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;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
|
||||||
padding-top: 100rpx;
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
.caller-avatar-container {
|
.call-btn {
|
||||||
position: relative;
|
width: 120rpx;
|
||||||
margin-bottom: 40rpx;
|
height: 120rpx;
|
||||||
|
border-radius: 50%;
|
||||||
.caller-avatar {
|
display: flex;
|
||||||
width: 180rpx;
|
align-items: center;
|
||||||
height: 180rpx;
|
justify-content: center;
|
||||||
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;
|
|
||||||
margin-bottom: 20rpx;
|
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 {
|
.btn-text {
|
||||||
font-size: 32rpx;
|
|
||||||
color: rgba(255, 255, 255, 0.9);
|
|
||||||
margin-bottom: 10rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.call-status {
|
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: rgba(255, 255, 255, 0.7);
|
color: #fff;
|
||||||
}
|
|
||||||
|
|
||||||
.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 {
|
.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;
|
display: flex;
|
||||||
justify-content: space-around;
|
flex-direction: column;
|
||||||
padding: 80rpx 100rpx 120rpx;
|
align-items: center;
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
.incoming-control {
|
.action-icon {
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
.call-btn {
|
&.active {
|
||||||
width: 120rpx;
|
background-color: rgba(255, 255, 255, 0.4);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.action-bar {
|
.action-text {
|
||||||
position: absolute;
|
font-size: 24rpx;
|
||||||
bottom: 60rpx;
|
color: #fff;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes ringPulse {
|
@keyframes ringPulse {
|
||||||
0% {
|
0% {
|
||||||
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0.4);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 响应式调整 */
|
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 {
|
|
||||||
bottom: 40rpx !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
</style>
|
||||||
|
|||||||
@@ -150,24 +150,16 @@
|
|||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
call.hangup()
|
call.hangup()
|
||||||
// this.removeAllListeners()
|
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
const session = call.getCurrentCallSession()
|
const session = call.getCurrentCallSession()
|
||||||
if (session) {
|
if (session) {
|
||||||
call.hangup()
|
call.hangup()
|
||||||
}
|
}
|
||||||
// this.removeAllListeners()
|
uni.$off('OnCallDisconnected')
|
||||||
|
uni.$off('OnCallConnected')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
removeAllListeners(){
|
|
||||||
//移除监听-接收到通话呼入
|
|
||||||
call.removeRemoteUserJoinedListener();
|
|
||||||
// 移除监听-通话已结束
|
|
||||||
call.removeCallDisconnectedListener();
|
|
||||||
// 移除监听-通话出现错误的回调
|
|
||||||
call.removeErrorListener();
|
|
||||||
},
|
|
||||||
changeMediaType() {
|
changeMediaType() {
|
||||||
if (this.mediaTypeCur == 'video') {
|
if (this.mediaTypeCur == 'video') {
|
||||||
this.mediaTypeCur = 'audio'
|
this.mediaTypeCur = 'audio'
|
||||||
@@ -284,9 +276,9 @@
|
|||||||
hangup() {
|
hangup() {
|
||||||
this.isSelf = true
|
this.isSelf = true
|
||||||
call.hangup()
|
call.hangup()
|
||||||
uni.navigateBack({
|
// uni.navigateBack({
|
||||||
delta: 1
|
// delta: 1
|
||||||
})
|
// })
|
||||||
},
|
},
|
||||||
accept() {
|
accept() {
|
||||||
call.accept()
|
call.accept()
|
||||||
@@ -324,12 +316,61 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onCallConnected() {
|
onCallConnected() {
|
||||||
let context = this
|
let context = this
|
||||||
console.log('oncallconnected接收了')
|
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
|
this.mediaTypeCur = this.mediaType
|
||||||
call.enableSpeaker(true)
|
|
||||||
this.currentCallSession = call.getCurrentCallSession()
|
this.currentCallSession = call.getCurrentCallSession()
|
||||||
this.callWay = this.currentCallSession.callType
|
this.callWay = this.currentCallSession.callType
|
||||||
this.users = this.currentCallSession.users
|
this.users = this.currentCallSession.users
|
||||||
@@ -347,6 +388,7 @@
|
|||||||
) {
|
) {
|
||||||
//视频是两个的时候
|
//视频是两个的时候
|
||||||
if (this.currentCallSession.users.length <= 2) {
|
if (this.currentCallSession.users.length <= 2) {
|
||||||
|
console.log("视频是两个的时候");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.systemInfoSync(
|
this.systemInfoSync(
|
||||||
this.currentCallSession.mine.userId,
|
this.currentCallSession.mine.userId,
|
||||||
@@ -397,6 +439,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
systemInfoSync(userId, ref, isZOrderOnTop) {
|
systemInfoSync(userId, ref, isZOrderOnTop) {
|
||||||
switch (uni.getSystemInfoSync().platform) {
|
switch (uni.getSystemInfoSync().platform) {
|
||||||
case 'android':
|
case 'android':
|
||||||
|
|||||||
568
stores/user.js
568
stores/user.js
@@ -1,326 +1,302 @@
|
|||||||
import { defineStore } from 'pinia'
|
|
||||||
import {
|
import {
|
||||||
getToken,
|
defineStore
|
||||||
getUserInfoData,
|
} from 'pinia'
|
||||||
setUserInfoData,
|
import {
|
||||||
removeUserInfoData,
|
getToken,
|
||||||
getSig,
|
getUserInfoData,
|
||||||
setSig,
|
setUserInfoData,
|
||||||
removeSig,
|
removeUserInfoData,
|
||||||
getFontSize,
|
getSig,
|
||||||
setFontSize,
|
setSig,
|
||||||
removeFontSize
|
removeSig,
|
||||||
|
getFontSize,
|
||||||
|
setFontSize,
|
||||||
|
removeFontSize
|
||||||
} from '@/utils/storage'
|
} from '@/utils/storage'
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #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 * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
|
||||||
import RCIMIWEngine from '@/uni_modules/RongCloud-IMWrapper-V2/js_sdk/RCIMEngine'
|
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
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
import { useLoginState } from 'tuikit-atomicx-vue3'
|
import {
|
||||||
|
useLoginState
|
||||||
|
} from 'tuikit-atomicx-vue3'
|
||||||
// #endif
|
// #endif
|
||||||
import { useTokenStore } from './token'
|
import {
|
||||||
import { getUserData, userLogout, updateUserData } from '@/api'
|
useTokenStore
|
||||||
import { ref } from 'vue'
|
} from './token'
|
||||||
import { useUI } from '@/utils/use-ui'
|
import {
|
||||||
import { reLaunch } from '@/utils/router'
|
getUserData,
|
||||||
import { getTencentUserSig } from '@/api'
|
userLogout,
|
||||||
import { TUILogin } from '@tencentcloud/tui-core-lite'
|
updateUserData
|
||||||
import { TUIChatEngine } from '@tencentcloud/chat-uikit-engine-lite'
|
} from '@/api'
|
||||||
import { getUserIntegral } from '@/api/my-index'
|
import {
|
||||||
import { removeFriendList, removeGroupList } from '../utils/storage'
|
ref
|
||||||
import { getRongYunLoginInfo } from '../api'
|
} 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', () => {
|
export const useUserStore = defineStore('user', () => {
|
||||||
const { clearToken } = useTokenStore()
|
const {
|
||||||
const { showDialog, showToast } = useUI()
|
clearToken
|
||||||
|
} = useTokenStore()
|
||||||
|
const {
|
||||||
|
showDialog,
|
||||||
|
showToast
|
||||||
|
} = useUI()
|
||||||
|
|
||||||
const userInfo = ref(
|
const userInfo = ref(
|
||||||
getUserInfoData() ? JSON?.parse(getUserInfoData()) : {}
|
getUserInfoData() ? JSON?.parse(getUserInfoData()) : {}
|
||||||
)
|
)
|
||||||
/** 用户字体大小 */
|
/** 用户字体大小 */
|
||||||
const fontSizeData = ref(getFontSize())
|
const fontSizeData = ref(getFontSize())
|
||||||
|
|
||||||
/** 腾讯 IM 存储数据 */
|
/** 腾讯 IM 存储数据 */
|
||||||
const tencentUserSig = ref(getSig() ? JSON?.parse(getSig()) : {})
|
const tencentUserSig = ref(getSig() ? JSON?.parse(getSig()) : {})
|
||||||
|
|
||||||
/** 用户积分数 */
|
/** 用户积分数 */
|
||||||
const integralData = ref(0)
|
const integralData = ref(0)
|
||||||
/** 融云 IM 引擎 */
|
/** 融云 IM 引擎 */
|
||||||
const imEngine = ref(null)
|
const imEngine = ref(null)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息(可从缓存或接口)
|
* 获取用户信息(可从缓存或接口)
|
||||||
*/
|
*/
|
||||||
const fetchUserInfo = async () => {
|
const fetchUserInfo = async () => {
|
||||||
// 尝试从本地缓存读取
|
// 尝试从本地缓存读取
|
||||||
const cachedToken = getToken()
|
const cachedToken = getToken()
|
||||||
const cachedUserInfo = getUserInfoData()
|
const cachedUserInfo = getUserInfoData()
|
||||||
const cachedSig = getSig()
|
const cachedSig = getSig()
|
||||||
|
|
||||||
if (cachedToken && cachedUserInfo) {
|
if (cachedToken && cachedUserInfo) {
|
||||||
userInfo.value = JSON.parse(cachedUserInfo)
|
userInfo.value = JSON.parse(cachedUserInfo)
|
||||||
tencentUserSig.value = JSON.parse(cachedSig)
|
tencentUserSig.value = JSON.parse(cachedSig)
|
||||||
loginTencentIM()
|
loginTencentIM()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await getIntegral()
|
await getIntegral()
|
||||||
const res = await getUserData()
|
const res = await getUserData()
|
||||||
await setUserInfo(res.data)
|
await setUserInfo(res.data)
|
||||||
loginTencentIM()
|
loginTencentIM()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置用户信息
|
* 设置用户信息
|
||||||
*/
|
*/
|
||||||
const setUserInfo = async data => {
|
const setUserInfo = async data => {
|
||||||
const res = await getTencentUserSig()
|
const res = await getTencentUserSig()
|
||||||
const ryData = await getRongYunLoginInfo()
|
const ryData = await getRongYunLoginInfo()
|
||||||
const IM_DATA = {
|
const IM_DATA = {
|
||||||
...res.data,
|
...res.data,
|
||||||
...ryData.data
|
...ryData.data
|
||||||
}
|
}
|
||||||
tencentUserSig.value = IM_DATA
|
tencentUserSig.value = IM_DATA
|
||||||
userInfo.value = data
|
userInfo.value = data
|
||||||
setUserInfoData(data)
|
setUserInfoData(data)
|
||||||
setSig(IM_DATA)
|
setSig(IM_DATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取用户积分 */
|
/** 获取用户积分 */
|
||||||
const getIntegral = async () => {
|
const getIntegral = async () => {
|
||||||
const res = await getUserIntegral()
|
const res = await getUserIntegral()
|
||||||
integralData.value = res.data.availablePoints
|
integralData.value = res.data.availablePoints
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录腾讯 IM
|
* 登录腾讯 IM
|
||||||
*/
|
*/
|
||||||
const loginTencentIM = async () => {
|
const loginTencentIM = async () => {
|
||||||
await refreshUserInfo()
|
await refreshUserInfo()
|
||||||
await TUILogin.login({
|
await TUILogin.login({
|
||||||
SDKAppID: tencentUserSig.value.sdkappID,
|
SDKAppID: tencentUserSig.value.sdkappID,
|
||||||
userID: tencentUserSig.value.userId,
|
userID: tencentUserSig.value.userId,
|
||||||
userSig: tencentUserSig.value.userSig,
|
userSig: tencentUserSig.value.userSig,
|
||||||
framework: `vue3`
|
framework: `vue3`
|
||||||
})
|
})
|
||||||
|
|
||||||
await TUIChatEngine.login({
|
await TUIChatEngine.login({
|
||||||
SDKAppID: tencentUserSig.value.sdkappID,
|
SDKAppID: tencentUserSig.value.sdkappID,
|
||||||
userID: tencentUserSig.value.userId,
|
userID: tencentUserSig.value.userId,
|
||||||
userSig: tencentUserSig.value.userSig,
|
userSig: tencentUserSig.value.userSig,
|
||||||
useUploadPlugin: true // 使用文件上传插件
|
useUploadPlugin: true // 使用文件上传插件
|
||||||
})
|
})
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
await useLoginState().login({
|
await useLoginState().login({
|
||||||
SDKAppID: tencentUserSig.value.sdkappID,
|
SDKAppID: tencentUserSig.value.sdkappID,
|
||||||
userID: tencentUserSig.value.userId,
|
userID: tencentUserSig.value.userId,
|
||||||
userSig: tencentUserSig.value.userSig
|
userSig: tencentUserSig.value.userSig
|
||||||
})
|
})
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
await useLoginState().login({
|
await useLoginState().login({
|
||||||
sdkAppID: tencentUserSig.value.sdkappID,
|
sdkAppID: tencentUserSig.value.sdkappID,
|
||||||
userID: tencentUserSig.value.userId,
|
userID: tencentUserSig.value.userId,
|
||||||
userSig: tencentUserSig.value.userSig
|
userSig: tencentUserSig.value.userSig
|
||||||
})
|
})
|
||||||
console.log(tencentUserSig.value.appKey, '====')
|
console.log(tencentUserSig.value.appKey, '====')
|
||||||
await connectIM()
|
await connectIM()
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef APP-PLUS
|
}
|
||||||
// CallLib.init({})
|
|
||||||
CallLib.onCallReceived(res => {
|
//连接融云IM
|
||||||
console.log(
|
const connectIM = async () => {
|
||||||
'Engine:OnCallReceived=>' + '监听通话呼入, 目标id=>',
|
let options = {}
|
||||||
res.data
|
imEngine.value = await RCIMIWEngine.create(tencentUserSig.value.appKey, options)
|
||||||
)
|
imEngine.value.setOnConnectedListener((res) => {
|
||||||
console.log('res: ',res.data);
|
if (res.code != 0) {
|
||||||
if (res.data.targetId) {
|
uni.hideLoading();
|
||||||
// let url = res.data.mediaType == 0 ? "" : "/pages/room/room"
|
// uni.showToast({
|
||||||
uni.setStorageSync('room-parameters', {
|
// title: 'OnCon:' + res.code,
|
||||||
callType: 'in',
|
// icon: 'error'
|
||||||
mediaType: res.data.mediaType === 0 ? 'audio' : 'video'
|
// })
|
||||||
|
console.log("连接已存在");
|
||||||
|
// return
|
||||||
|
}
|
||||||
|
//连接成功
|
||||||
|
CallLib.init({});
|
||||||
|
console.log('call.init')
|
||||||
|
uni.hideLoading();
|
||||||
|
uni.showToast({
|
||||||
|
title: res.userId
|
||||||
});
|
});
|
||||||
uni.navigateTo("/pages/room/incom", {
|
if (uni.getSystemInfoSync().platform === 'android') {
|
||||||
type: res.data.extra,
|
permision.requestAndroidPermission('android.permission.CAMERA');
|
||||||
callType: 'in',
|
permision.requestAndroidPermission('android.permission.RECORD_AUDIO');
|
||||||
mediaType: res.data.mediaType == 0 ? "audio" : "video",
|
}
|
||||||
userID: res.data.mine.userId // 对方的用户id
|
});
|
||||||
})
|
let code = await imEngine.value.connect(tencentUserSig.value.ryToken, 10)
|
||||||
}
|
if (code != 0) {
|
||||||
})
|
uni.hideLoading();
|
||||||
|
uni.showToast({
|
||||||
/** 挂断电话 */
|
title: 'connect:' + code,
|
||||||
CallLib.onCallDisconnected(res => {
|
icon: 'error'
|
||||||
console.log(
|
})
|
||||||
'Engine:OnCallDisconnected=>' + '挂断成功, 挂断原因=>',
|
}
|
||||||
res.data.reason
|
}
|
||||||
)
|
|
||||||
uni.navigateBack()
|
|
||||||
})
|
|
||||||
|
|
||||||
CallLib.onError(res => {
|
|
||||||
console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
|
||||||
uni.navigateBack()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//连接融云IM
|
/**
|
||||||
const connectIM = async () => {
|
* 清除用户信息(退出登录)
|
||||||
const options = {
|
*/
|
||||||
naviServer: ''
|
const clearUserInfo = async () => {
|
||||||
}
|
const show = await showDialog('提示', '确定要退出登录吗?')
|
||||||
imEngine.value = await RCIMIWEngine.create(
|
if (show) {
|
||||||
tencentUserSig.value.appKey,
|
await logout()
|
||||||
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 logout = async () => {
|
||||||
const show = await showDialog('提示', '确定要退出登录吗?')
|
if (!userInfo.value) return
|
||||||
if (show) {
|
try {
|
||||||
await logout()
|
userInfo.value = null
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
await userLogout()
|
||||||
* 退出登录(不带提示)
|
await TUILogin.logout()
|
||||||
*/
|
await TUIChatEngine.logout()
|
||||||
const logout = async () => {
|
// #ifdef APP-PLUS
|
||||||
if (!userInfo.value) return
|
removeFriendList()
|
||||||
try {
|
removeGroupList()
|
||||||
userInfo.value = null
|
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()
|
const clearAllUserInfo = async () => {
|
||||||
await TUIChatEngine.logout()
|
userInfo.value = null
|
||||||
// #ifdef APP-PLUS
|
tencentUserSig.value = null
|
||||||
removeFriendList()
|
fontSizeData.value = 26
|
||||||
removeGroupList()
|
clearToken()
|
||||||
await useLoginState().logout()
|
removeUserInfoData()
|
||||||
// #endif
|
removeSig()
|
||||||
// #ifdef H5
|
removeFontSize()
|
||||||
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 () => {
|
const refreshUserInfo = async () => {
|
||||||
userInfo.value = null
|
const res = await getUserData()
|
||||||
tencentUserSig.value = null
|
await getIntegral()
|
||||||
fontSizeData.value = 26
|
await setUserInfoData(res.data)
|
||||||
clearToken()
|
userInfo.value = res.data
|
||||||
removeUserInfoData()
|
}
|
||||||
removeSig()
|
|
||||||
removeFontSize()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 刷新用户信息(如用户信息被修改) */
|
/**
|
||||||
const refreshUserInfo = async () => {
|
* 更新部分用户信息(例如昵称、头像)
|
||||||
const res = await getUserData()
|
*/
|
||||||
await getIntegral()
|
const updateUserInfo = async partialData => {
|
||||||
await setUserInfoData(res.data)
|
if (!userInfo.value) return
|
||||||
userInfo.value = res.data
|
await updateUserData(partialData)
|
||||||
}
|
await refreshUserInfo()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/** 更新字体大小 */
|
||||||
* 更新部分用户信息(例如昵称、头像)
|
const updateFontSize = async fontSize => {
|
||||||
*/
|
fontSizeData.value = fontSize
|
||||||
const updateUserInfo = async partialData => {
|
setFontSize(fontSize)
|
||||||
if (!userInfo.value) return
|
}
|
||||||
await updateUserData(partialData)
|
|
||||||
await refreshUserInfo()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 更新字体大小 */
|
return {
|
||||||
const updateFontSize = async fontSize => {
|
imEngine,
|
||||||
fontSizeData.value = fontSize
|
userInfo,
|
||||||
setFontSize(fontSize)
|
integralData,
|
||||||
}
|
tencentUserSig,
|
||||||
|
fontSizeData,
|
||||||
return {
|
getIntegral,
|
||||||
imEngine,
|
clearAllUserInfo,
|
||||||
userInfo,
|
updateFontSize,
|
||||||
integralData,
|
logout,
|
||||||
tencentUserSig,
|
refreshUserInfo,
|
||||||
fontSizeData,
|
fetchUserInfo,
|
||||||
getIntegral,
|
loginTencentIM,
|
||||||
clearAllUserInfo,
|
setUserInfo,
|
||||||
updateFontSize,
|
clearUserInfo,
|
||||||
logout,
|
updateUserInfo
|
||||||
refreshUserInfo,
|
}
|
||||||
fetchUserInfo,
|
})
|
||||||
loginTencentIM,
|
|
||||||
setUserInfo,
|
|
||||||
clearUserInfo,
|
|
||||||
updateUserInfo
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user