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