添加音视频发送信息
This commit is contained in:
@@ -1,102 +1,112 @@
|
|||||||
<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'
|
||||||
|
import { useUserStore } from '../../../../../stores/user'
|
||||||
|
|
||||||
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 { updateCallMode } = useUserStore()
|
||||||
const isType = computed(() => props.type === '0')
|
|
||||||
|
|
||||||
const evaluateIcon = isType.value ? custom : videoIcon
|
/** 语音通话状态 */
|
||||||
|
const isType = computed(() => props.type === '0')
|
||||||
|
|
||||||
const emits = defineEmits(['onDialogPopupShowOrHide'])
|
const evaluateIcon = isType.value ? custom : videoIcon
|
||||||
|
|
||||||
const container = ref()
|
const emits = defineEmits(['onDialogPopupShowOrHide'])
|
||||||
const closeDialog = () => {
|
|
||||||
container?.value?.toggleDialogDisplay(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const container = ref()
|
||||||
|
const closeDialog = () => {
|
||||||
|
container?.value?.toggleDialogDisplay(false)
|
||||||
|
}
|
||||||
|
|
||||||
const onDialogShow = () => {
|
const onDialogShow = () => {
|
||||||
console.log('弹出窗口', props.currentConversation)
|
console.log('弹出窗口', props.currentConversation)
|
||||||
const data = props.currentConversation.userProfile
|
const data = props.currentConversation.userProfile
|
||||||
emits('onDialogPopupShowOrHide', true)
|
emits('onDialogPopupShowOrHide', false)
|
||||||
|
|
||||||
if (isType.value) {
|
if (isType.value) {
|
||||||
let params = {
|
let params = {
|
||||||
to: props.currentConversation.conversationID,
|
to: props.currentConversation.conversationID,
|
||||||
conversationType: TUIChatEngine.TYPES.CONV_C2C,
|
conversationType: TUIChatEngine.TYPES.CONV_C2C,
|
||||||
payload: {
|
payload: {
|
||||||
text: "拨打语音"
|
text: '拨打语音'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('params: ', params);
|
updateCallMode('0')
|
||||||
// TUIChatService.sendTextMessage(params)
|
console.log('params: ', params)
|
||||||
navigateTo('/pages/room/incom', {
|
// TUIChatService.sendTextMessage(params)
|
||||||
type: 'call',
|
navigateTo('/pages/room/incom', {
|
||||||
userID: data.userID,
|
type: 'call',
|
||||||
mediaType: 'audio',
|
userID: data.userID,
|
||||||
callType: 'out',
|
mediaType: 'audio',
|
||||||
})
|
callType: 'out'
|
||||||
} else {
|
})
|
||||||
let params = {
|
} else {
|
||||||
to: props.currentConversation.conversationID,
|
let params = {
|
||||||
conversationType: TUIChatEngine.TYPES.CONV_C2C,
|
to: props.currentConversation.conversationID,
|
||||||
payload: {
|
conversationType: TUIChatEngine.TYPES.CONV_C2C,
|
||||||
text: "拨打视频"
|
payload: {
|
||||||
}
|
text: '拨打视频'
|
||||||
}
|
}
|
||||||
// TUIChatService.sendTextMessage(params)
|
}
|
||||||
uni.setStorageSync('room-parameters', {
|
// TUIChatService.sendTextMessage(params)
|
||||||
callType: 'out',
|
uni.setStorageSync('room-parameters', {
|
||||||
mediaType: 'video',
|
callType: 'out',
|
||||||
targetId: data.userID,
|
mediaType: 'video',
|
||||||
callSelect: 'single',
|
targetId: data.userID,
|
||||||
});
|
callSelect: 'single'
|
||||||
navigateTo('/pages/room/room')
|
})
|
||||||
}
|
updateCallMode('1')
|
||||||
}
|
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 ref="container" :iconFile="evaluateIcon" :iconWidth="isUniFrameWork ? '34px' : '20px'"
|
<ToolbarItemContainer
|
||||||
:iconHeight="isUniFrameWork ? '34px' : '20px'" :title="isType ? '语音通话' : '视频通话'" @onDialogShow="onDialogShow"
|
ref="container"
|
||||||
@onDialogClose="onDialogClose">
|
:iconFile="evaluateIcon"
|
||||||
<!-- <view class="box-index">
|
:iconWidth="isUniFrameWork ? '34px' : '20px'"
|
||||||
|
: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"
|
||||||
@@ -130,7 +140,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>
|
||||||
|
|||||||
@@ -151,6 +151,25 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
<!-- 音视频通话 -->
|
||||||
|
<template
|
||||||
|
v-else-if="
|
||||||
|
customData.businessID === CHAT_MSG_CUSTOM_TYPE.VOICE_CALL ||
|
||||||
|
customData.businessID === CHAT_MSG_CUSTOM_TYPE.VIDEO_CALL
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<view class="call-box" @click="onCall">
|
||||||
|
<text class="call-text">{{ goodsData.title }}</text>
|
||||||
|
<uni-icons
|
||||||
|
:type="
|
||||||
|
customData.businessID === CHAT_MSG_CUSTOM_TYPE.VOICE_CALL
|
||||||
|
? 'phone'
|
||||||
|
: 'videocam'
|
||||||
|
"
|
||||||
|
size="30rpx"
|
||||||
|
></uni-icons>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<span v-html="content.custom" />
|
<span v-html="content.custom" />
|
||||||
</template>
|
</template>
|
||||||
@@ -165,7 +184,7 @@
|
|||||||
computed,
|
computed,
|
||||||
reactive
|
reactive
|
||||||
} from '../../../../adapter-vue'
|
} from '../../../../adapter-vue'
|
||||||
import {
|
import TUIChatEngine, {
|
||||||
TUITranslateService,
|
TUITranslateService,
|
||||||
IMessageModel
|
IMessageModel
|
||||||
} from '@tencentcloud/chat-uikit-engine-lite'
|
} from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
@@ -177,6 +196,7 @@
|
|||||||
import unopenedEnvelope from '../../../../assets/icon/unopened-envelope.svg'
|
import unopenedEnvelope from '../../../../assets/icon/unopened-envelope.svg'
|
||||||
import kaiEnvelope from '../../../../assets/icon/kai-unopened-envelope.svg'
|
import kaiEnvelope from '../../../../assets/icon/kai-unopened-envelope.svg'
|
||||||
import { navigateTo } from '../../../../../utils/router'
|
import { navigateTo } from '../../../../../utils/router'
|
||||||
|
import { useUserStore } from '../../../../../stores/user'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
messageItem: IMessageModel
|
messageItem: IMessageModel
|
||||||
@@ -187,6 +207,8 @@
|
|||||||
(key: 'claim'): void
|
(key: 'claim'): void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { updateCallMode } = useUserStore()
|
||||||
|
|
||||||
const emits = defineEmits<IEmit>()
|
const emits = defineEmits<IEmit>()
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
@@ -230,6 +252,32 @@
|
|||||||
return JSON.parse(props.messageItem.payload.data)
|
return JSON.parse(props.messageItem.payload.data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 点击拨打音视频电话 */
|
||||||
|
const onCall = () => {
|
||||||
|
if (props.messageItem.flow === 'out') {
|
||||||
|
if (
|
||||||
|
goodsData.value.businessID === CHAT_MSG_CUSTOM_TYPE.VOICE_CALL
|
||||||
|
) {
|
||||||
|
updateCallMode('0')
|
||||||
|
navigateTo('/pages/room/incom', {
|
||||||
|
type: 'call',
|
||||||
|
userID: goodsData.value.userID,
|
||||||
|
mediaType: 'audio',
|
||||||
|
callType: 'out'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.setStorageSync('room-parameters', {
|
||||||
|
callType: 'out',
|
||||||
|
mediaType: 'video',
|
||||||
|
targetId: goodsData.value.userID,
|
||||||
|
callSelect: 'single'
|
||||||
|
})
|
||||||
|
updateCallMode('1')
|
||||||
|
navigateTo('/pages/room/room')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 点击商品详情 */
|
/** 点击商品详情 */
|
||||||
const onGoods = () => {
|
const onGoods = () => {
|
||||||
navigateTo('/pages/mall/detail', { productId: goodsData.value.id })
|
navigateTo('/pages/mall/detail', { productId: goodsData.value.id })
|
||||||
@@ -467,4 +515,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.call-box {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
.call-text {
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -404,6 +404,20 @@
|
|||||||
return `[直播信息]:${data.title}`
|
return `[直播信息]:${data.title}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data.businessID === CHAT_MSG_CUSTOM_TYPE.VOICE_CALL) {
|
||||||
|
if (isText) {
|
||||||
|
return `${text[0]}:[语音通话]`
|
||||||
|
} else {
|
||||||
|
return `[语音通话]`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data.businessID === CHAT_MSG_CUSTOM_TYPE.VIDEO_CALL) {
|
||||||
|
if (isText) {
|
||||||
|
return `${text[0]}:[视频通话]`
|
||||||
|
} else {
|
||||||
|
return `[视频通话]`
|
||||||
|
}
|
||||||
|
}
|
||||||
if (data.content === 'Create Group' && item.type === 'GROUP') {
|
if (data.content === 'Create Group' && item.type === 'GROUP') {
|
||||||
return `${item.getLastMessage('text')?.split(':')[0]}:创建群聊`
|
return `${item.getLastMessage('text')?.split(':')[0]}:创建群聊`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,11 @@ export const CHAT_MSG_CUSTOM_TYPE = {
|
|||||||
/** 商品详情 */
|
/** 商品详情 */
|
||||||
GOODS: "goods",
|
GOODS: "goods",
|
||||||
/** 直播 */
|
/** 直播 */
|
||||||
LIVE: "live"
|
LIVE: "live",
|
||||||
|
/** 语音通话 */
|
||||||
|
VOICE_CALL: "voiceCall",
|
||||||
|
/** 视频通话 */
|
||||||
|
VIDEO_CALL: "videoCall",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DIALOG_CONTENT = {
|
export const DIALOG_CONTENT = {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ export const useAuthUser = () => {
|
|||||||
|
|
||||||
// 响应式状态(state & getters)
|
// 响应式状态(state & getters)
|
||||||
const {
|
const {
|
||||||
|
callMode,
|
||||||
|
callUserId,
|
||||||
|
callDuration,
|
||||||
imEngine,
|
imEngine,
|
||||||
userInfo,
|
userInfo,
|
||||||
tencentUserSig,
|
tencentUserSig,
|
||||||
@@ -20,6 +23,9 @@ export const useAuthUser = () => {
|
|||||||
const { token } = storeToRefs(tokenStore)
|
const { token } = storeToRefs(tokenStore)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
callMode,
|
||||||
|
callUserId,
|
||||||
|
callDuration,
|
||||||
imEngine,
|
imEngine,
|
||||||
integralData,
|
integralData,
|
||||||
userInfo,
|
userInfo,
|
||||||
|
|||||||
@@ -1,472 +1,527 @@
|
|||||||
<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="top-bar">
|
|
||||||
<view class="top-left">
|
|
||||||
<!-- 通话时间显示 -->
|
|
||||||
<view v-if="callState === 'dialogue'" class="call-time-container">
|
|
||||||
<uni-icons type="sound" size="16" color="#fff"></uni-icons>
|
|
||||||
<text class="call-time">{{ formattedTime }}</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 主内容区 -->
|
|
||||||
<view 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' ? '呼叫中,等待对方接受邀请...' : callState === 'answer' ? '等待接听...' : '对话中...' }}
|
|
||||||
</text>
|
|
||||||
<text class="call-status">{{ mediaType === 'audio' ? "语音通话" : "视频通话" }}</text>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 控制按钮 -->
|
|
||||||
<view class="incoming-controls">
|
|
||||||
<!-- 麦克风控制按钮(仅在通话中显示) -->
|
|
||||||
<view v-if="callState === 'dialogue'" class="incoming-control" @click="toggleMicrophone">
|
|
||||||
<view class="call-btn mic-btn" :class="{ 'btn-active': activeBtn === 'mic', 'mic-muted': isMicMuted }">
|
|
||||||
<uni-icons v-if="!isMicMuted" type="mic" size="28" color="#fff"></uni-icons>
|
|
||||||
<uni-icons v-else type="micoff" size="28" color="#fff"></uni-icons>
|
|
||||||
</view>
|
|
||||||
<text class="btn-text">{{ isMicMuted ? '开启' : '静音' }}</text>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 挂断/拒绝按钮 -->
|
|
||||||
<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 v-if="callState === 'dialogue'" class="incoming-control" @click="toggleSpeaker">
|
|
||||||
<view class="call-btn speaker-btn" :class="{ 'btn-active': activeBtn === 'speaker', 'speaker-on': isSpeakerOn }">
|
|
||||||
<uni-icons v-if="!isSpeakerOn" type="sound" size="28" color="#fff"></uni-icons>
|
|
||||||
<uni-icons v-else type="sound-filled" size="28" color="#fff"></uni-icons>
|
|
||||||
</view>
|
|
||||||
<text class="btn-text">扬声器</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<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 {
|
import { ref, computed, onUnmounted } from 'vue'
|
||||||
ref,
|
import { onLoad, onUnload, onHide } from '@dcloudio/uni-app'
|
||||||
watch,
|
import { TUIUserService } from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
onUnmounted
|
import { useUI } from '../../utils/use-ui'
|
||||||
} from 'vue'
|
import { useAuthUser } from '../../composables/useAuthUser'
|
||||||
import {
|
import { useUserStore } from '../../stores/user'
|
||||||
onLoad,
|
|
||||||
onUnload,
|
|
||||||
onHide
|
|
||||||
} from '@dcloudio/uni-app'
|
|
||||||
import {
|
|
||||||
TUIUserService
|
|
||||||
} from '@tencentcloud/chat-uikit-engine-lite'
|
|
||||||
import {
|
|
||||||
useUI
|
|
||||||
} from '../../utils/use-ui'
|
|
||||||
import {
|
|
||||||
navigateBack
|
|
||||||
} from '../../utils/router'
|
|
||||||
|
|
||||||
|
const { callUserId, callDuration } = useAuthUser()
|
||||||
|
const { startTimer, stopTimer } = useUserStore()
|
||||||
|
const { showLoading, hideLoading } = useUI()
|
||||||
|
const callBackground = ref('/static/images/public/random2.png')
|
||||||
|
/** 呼叫用户信息 */
|
||||||
|
const callerInfo = ref({})
|
||||||
|
/** 通话状态 */
|
||||||
|
const isRinging = ref(true)
|
||||||
|
/** 控制按钮状态 */
|
||||||
|
const activeBtn = ref(null)
|
||||||
|
/** 麦克风是否静音 */
|
||||||
|
const isMicMuted = ref(false)
|
||||||
|
/** 扬声器是否开启 */
|
||||||
|
const isSpeakerOn = ref(false)
|
||||||
|
/** 通话计时器 */
|
||||||
|
const timer = ref(null)
|
||||||
|
/** 通话时长(秒) */
|
||||||
|
// const callDuration = ref(0)
|
||||||
|
/** 好友ID */
|
||||||
|
const friendID = ref('')
|
||||||
|
|
||||||
const {
|
/**
|
||||||
showLoading,
|
* 拨打状态
|
||||||
hideLoading
|
* call: 发起呼叫
|
||||||
} = useUI()
|
* answer: 接听
|
||||||
const callBackground = ref('/static/images/public/random2.png')
|
* dialogue: 对话中
|
||||||
/** 呼叫用户信息 */
|
*/
|
||||||
const callerInfo = ref({})
|
const callState = ref('')
|
||||||
/** 通话状态 */
|
CallLib.onRemoteUserJoined(res => {
|
||||||
const isRinging = ref(true)
|
console.log(
|
||||||
/** 控制按钮状态 */
|
'Engine:OnRemoteUserJoined=>' +
|
||||||
const activeBtn = ref(null)
|
'主叫端拨出电话,被叫端收到请求后,加入通话,被叫端Id为=>',
|
||||||
/** 麦克风是否静音 */
|
res.data.userId
|
||||||
const isMicMuted = ref(false)
|
)
|
||||||
/** 扬声器是否开启 */
|
callState.value = 'dialogue'
|
||||||
const isSpeakerOn = ref(false)
|
// 开始计时
|
||||||
/** 通话计时器 */
|
startTimer()
|
||||||
const timer = ref(null)
|
})
|
||||||
/** 通话时长(秒) */
|
|
||||||
const callDuration = ref(0)
|
|
||||||
/** 格式化后的时间 */
|
|
||||||
const formattedTime = ref('00:00')
|
|
||||||
|
|
||||||
/**
|
// CallLib.onRemoteUserRinging(res => {
|
||||||
* 拨打状态
|
// console.log(
|
||||||
* call: 发起呼叫
|
// '主叫端拨出电话,被叫端收到请求,发出振铃响应时触发,对端Id为=>',
|
||||||
* answer: 接听
|
// res.data.userId
|
||||||
* dialogue: 对话中
|
// )
|
||||||
*/
|
// })
|
||||||
const callState = ref('')
|
|
||||||
CallLib.onRemoteUserJoined(res => {
|
|
||||||
console.log(
|
|
||||||
'Engine:OnRemoteUserJoined=>' +
|
|
||||||
'主叫端拨出电话,被叫端收到请求后,加入通话,被叫端Id为=>',
|
|
||||||
res.data.userId
|
|
||||||
)
|
|
||||||
callState.value = 'dialogue'
|
|
||||||
// 开始计时
|
|
||||||
startTimer()
|
|
||||||
})
|
|
||||||
|
|
||||||
// CallLib.onRemoteUserRinging(res => {
|
// CallLib.onError(res => {
|
||||||
// console.log(
|
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
||||||
// '主叫端拨出电话,被叫端收到请求,发出振铃响应时触发,对端Id为=>',
|
// })
|
||||||
// res.data.userId
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
|
|
||||||
// CallLib.onError(res => {
|
/** 格式化时间显示 */
|
||||||
// console.log('通话过程中,发生异常,异常原因=>', res.data.reason)
|
const formattedTime = computed(() => {
|
||||||
// })
|
const minutes = Math.floor(callDuration.value / 60)
|
||||||
|
const seconds = callDuration.value % 60
|
||||||
|
return `${minutes.toString().padStart(2, '0')}:${seconds
|
||||||
|
.toString()
|
||||||
|
.padStart(2, '0')}`
|
||||||
|
})
|
||||||
|
|
||||||
/** 开始通话计时 */
|
/** 切换麦克风状态 */
|
||||||
const startTimer = () => {
|
const toggleMicrophone = () => {
|
||||||
stopTimer() // 先停止之前的计时器
|
isMicMuted.value = !isMicMuted.value
|
||||||
timer.value = setInterval(() => {
|
// 调用融云SDK的麦克风控制
|
||||||
callDuration.value++
|
CallLib.enableMicrophone(!isMicMuted.value)
|
||||||
formatTime()
|
activeBtn.value = 'mic'
|
||||||
}, 1000)
|
setTimeout(() => (activeBtn.value = null), 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 停止通话计时 */
|
/** 切换扬声器状态 */
|
||||||
const stopTimer = () => {
|
const toggleSpeaker = () => {
|
||||||
if (timer.value) {
|
isSpeakerOn.value = !isSpeakerOn.value
|
||||||
clearInterval(timer.value)
|
// 调用融云SDK的扬声器控制
|
||||||
timer.value = null
|
CallLib.enableSpeaker(isSpeakerOn.value)
|
||||||
}
|
activeBtn.value = 'speaker'
|
||||||
}
|
setTimeout(() => (activeBtn.value = null), 200)
|
||||||
|
}
|
||||||
|
|
||||||
/** 格式化时间显示 */
|
/**
|
||||||
const formatTime = () => {
|
* 按钮状态
|
||||||
const minutes = Math.floor(callDuration.value / 60)
|
* @param show true: 接听电话 false: 拒接/挂断电话
|
||||||
const seconds = callDuration.value % 60
|
*/
|
||||||
formattedTime.value = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
|
const cutFn = show => {
|
||||||
}
|
if (show) {
|
||||||
|
// 接听电话 dialogue
|
||||||
|
if (mediaType.value === 'audio') {
|
||||||
|
CallLib.enableMicrophone(true)
|
||||||
|
}
|
||||||
|
CallLib.accept()
|
||||||
|
callState.value = 'dialogue'
|
||||||
|
// 开始计时
|
||||||
|
startTimer()
|
||||||
|
if (mediaType.value === 'video') {
|
||||||
|
uni.redirectTo({
|
||||||
|
url: '/pages/room/room'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 停止计时
|
||||||
|
stopTimer()
|
||||||
|
// 取消接听,返回上一页
|
||||||
|
CallLib.hangup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 切换麦克风状态 */
|
const mediaType = ref('audio')
|
||||||
const toggleMicrophone = () => {
|
|
||||||
isMicMuted.value = !isMicMuted.value
|
|
||||||
// 调用融云SDK的麦克风控制
|
|
||||||
CallLib.enableMicrophone(!isMicMuted.value)
|
|
||||||
activeBtn.value = 'mic'
|
|
||||||
setTimeout(() => activeBtn.value = null, 200)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 切换扬声器状态 */
|
onLoad(async e => {
|
||||||
const toggleSpeaker = () => {
|
callState.value = e.type
|
||||||
isSpeakerOn.value = !isSpeakerOn.value
|
mediaType.value = e.mediaType
|
||||||
// 调用融云SDK的扬声器控制
|
friendID.value = e.userID
|
||||||
CallLib.enableSpeaker(isSpeakerOn.value)
|
callUserId.value = e.userID
|
||||||
activeBtn.value = 'speaker'
|
console.log(e)
|
||||||
setTimeout(() => activeBtn.value = null, 200)
|
showLoading()
|
||||||
}
|
const res = await TUIUserService.getUserProfile({
|
||||||
|
userIDList: [e.userID]
|
||||||
|
})
|
||||||
|
hideLoading()
|
||||||
|
callerInfo.value = res.data[0]
|
||||||
|
if (e.type === 'call') {
|
||||||
|
CallLib.enableMicrophone(true)
|
||||||
|
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
|
||||||
|
}
|
||||||
|
if (e.callType == 'in') {
|
||||||
|
// 接听语音通话
|
||||||
|
callState.value = 'answer'
|
||||||
|
}
|
||||||
|
console.log('callState.value: ', callState.value)
|
||||||
|
console.log('===好友信息', res)
|
||||||
|
})
|
||||||
|
|
||||||
/** 按钮状态 */
|
// 组件卸载时清理计时器
|
||||||
const cutFn = show => {
|
onUnload(() => {
|
||||||
if (show) {
|
stopTimer()
|
||||||
// 接听电话 dialogue
|
})
|
||||||
if (mediaType.value === 'audio') {
|
|
||||||
CallLib.enableMicrophone(true)
|
|
||||||
}
|
|
||||||
CallLib.accept()
|
|
||||||
callState.value = 'dialogue'
|
|
||||||
// 开始计时
|
|
||||||
startTimer()
|
|
||||||
if (mediaType.value === 'video') {
|
|
||||||
uni.redirectTo({
|
|
||||||
url: "/pages/room/room"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 停止计时
|
|
||||||
stopTimer()
|
|
||||||
// 取消接听,返回上一页
|
|
||||||
CallLib.hangup()
|
|
||||||
// navigateBack()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mediaType = ref("audio")
|
onUnmounted(() => {
|
||||||
|
stopTimer()
|
||||||
onLoad(async e => {
|
})
|
||||||
callState.value = e.type
|
|
||||||
mediaType.value = e.mediaType
|
|
||||||
console.log(e)
|
|
||||||
showLoading()
|
|
||||||
const res = await TUIUserService.getUserProfile({
|
|
||||||
userIDList: [e.userID]
|
|
||||||
})
|
|
||||||
hideLoading()
|
|
||||||
callerInfo.value = res.data[0]
|
|
||||||
if (e.type === 'call') {
|
|
||||||
CallLib.enableMicrophone(true)
|
|
||||||
CallLib.startSingleCall(callerInfo.value.userID, 0, 'answer')
|
|
||||||
}
|
|
||||||
if (e.callType == "in") {
|
|
||||||
// 接听语音通话
|
|
||||||
callState.value = 'answer'
|
|
||||||
}
|
|
||||||
console.log('callState.value: ', callState.value);
|
|
||||||
console.log('===好友信息', res)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 组件卸载时清理计时器
|
|
||||||
onUnload(() => {
|
|
||||||
stopTimer()
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
stopTimer()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<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="top-bar">
|
||||||
|
<view class="top-left">
|
||||||
|
<!-- 通话时间显示 -->
|
||||||
|
<view v-if="callState === 'dialogue'" class="call-time-container">
|
||||||
|
<uni-icons type="sound" size="16" color="#fff"></uni-icons>
|
||||||
|
<text class="call-time">{{ formattedTime }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 主内容区 -->
|
||||||
|
<view 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'
|
||||||
|
? '呼叫中,等待对方接受邀请...'
|
||||||
|
: callState === 'answer'
|
||||||
|
? '等待接听...'
|
||||||
|
: '对话中...'
|
||||||
|
}}
|
||||||
|
</text>
|
||||||
|
<text class="call-status">
|
||||||
|
{{ mediaType === 'audio' ? '语音通话' : '视频通话' }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 控制按钮 -->
|
||||||
|
<view class="incoming-controls">
|
||||||
|
<!-- 麦克风控制按钮(仅在通话中显示) -->
|
||||||
|
<view
|
||||||
|
v-if="callState === 'dialogue'"
|
||||||
|
class="incoming-control"
|
||||||
|
@click="toggleMicrophone"
|
||||||
|
>
|
||||||
|
<view
|
||||||
|
class="call-btn mic-btn"
|
||||||
|
:class="{
|
||||||
|
'btn-active': activeBtn === 'mic',
|
||||||
|
'mic-muted': isMicMuted
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<uni-icons
|
||||||
|
v-if="!isMicMuted"
|
||||||
|
type="mic"
|
||||||
|
size="28"
|
||||||
|
color="#fff"
|
||||||
|
></uni-icons>
|
||||||
|
<uni-icons
|
||||||
|
v-else
|
||||||
|
type="micoff"
|
||||||
|
size="28"
|
||||||
|
color="#fff"
|
||||||
|
></uni-icons>
|
||||||
|
</view>
|
||||||
|
<text class="btn-text">{{ isMicMuted ? '开启' : '静音' }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 挂断/拒绝按钮 -->
|
||||||
|
<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
|
||||||
|
v-if="callState === 'dialogue'"
|
||||||
|
class="incoming-control"
|
||||||
|
@click="toggleSpeaker"
|
||||||
|
>
|
||||||
|
<view
|
||||||
|
class="call-btn speaker-btn"
|
||||||
|
:class="{
|
||||||
|
'btn-active': activeBtn === 'speaker',
|
||||||
|
'speaker-on': isSpeakerOn
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<uni-icons
|
||||||
|
v-if="!isSpeakerOn"
|
||||||
|
type="sound"
|
||||||
|
size="28"
|
||||||
|
color="#fff"
|
||||||
|
></uni-icons>
|
||||||
|
<uni-icons
|
||||||
|
v-else
|
||||||
|
type="sound-filled"
|
||||||
|
size="28"
|
||||||
|
color="#fff"
|
||||||
|
></uni-icons>
|
||||||
|
</view>
|
||||||
|
<text class="btn-text">扬声器</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.incoming-call {
|
.incoming-call {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
background-color: #000;
|
background-color: #000;
|
||||||
|
|
||||||
/* 顶部栏样式 */
|
/* 顶部栏样式 */
|
||||||
.top-bar {
|
.top-bar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 120rpx;
|
height: 120rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 40rpx;
|
padding: 0 40rpx;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-top: env(safe-area-inset-top);
|
padding-top: env(safe-area-inset-top);
|
||||||
|
|
||||||
.top-left {
|
.top-left {
|
||||||
.call-time-container {
|
.call-time-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: rgba(255, 255, 255, 0.15);
|
background: rgba(255, 255, 255, 0.15);
|
||||||
padding: 8rpx 20rpx;
|
padding: 8rpx 20rpx;
|
||||||
border-radius: 30rpx;
|
border-radius: 30rpx;
|
||||||
backdrop-filter: blur(10px);
|
backdrop-filter: blur(10px);
|
||||||
|
|
||||||
.call-time {
|
.call-time {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
margin-left: 10rpx;
|
margin-left: 10rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.blur-background {
|
.blur-background {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
|
|
||||||
.bg-image {
|
.bg-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
filter: blur(20px);
|
filter: blur(20px);
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bg-overlay {
|
.bg-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: rgba(0, 0, 0, 0.5);
|
background: rgba(0, 0, 0, 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.caller-info {
|
.caller-info {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding-top: 100rpx;
|
padding-top: 100rpx;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
||||||
.caller-avatar-container {
|
.caller-avatar-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 40rpx;
|
margin-bottom: 40rpx;
|
||||||
|
|
||||||
.caller-avatar {
|
.caller-avatar {
|
||||||
width: 180rpx;
|
width: 180rpx;
|
||||||
height: 180rpx;
|
height: 180rpx;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: linear-gradient(135deg, #1aad19, #129611);
|
background: linear-gradient(135deg, #1aad19, #129611);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
.avatar-image {
|
.avatar-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.avatar-ring {
|
&.avatar-ring {
|
||||||
animation: ringPulse 1.5s infinite;
|
animation: ringPulse 1.5s infinite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.caller-name {
|
.caller-name {
|
||||||
font-size: 48rpx;
|
font-size: 48rpx;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.call-type {
|
.call-type {
|
||||||
font-size: 32rpx;
|
font-size: 32rpx;
|
||||||
color: rgba(255, 255, 255, 0.9);
|
color: rgba(255, 255, 255, 0.9);
|
||||||
margin-bottom: 10rpx;
|
margin-bottom: 10rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.call-status {
|
.call-status {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: rgba(255, 255, 255, 0.7);
|
color: rgba(255, 255, 255, 0.7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.incoming-controls {
|
.incoming-controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
padding: 80rpx 40rpx 120rpx;
|
padding: 80rpx 40rpx 120rpx;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
||||||
.incoming-control {
|
.incoming-control {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-width: 120rpx;
|
min-width: 120rpx;
|
||||||
|
|
||||||
.call-btn {
|
.call-btn {
|
||||||
width: 120rpx;
|
width: 120rpx;
|
||||||
height: 120rpx;
|
height: 120rpx;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
|
|
||||||
&.decline-btn {
|
&.decline-btn {
|
||||||
background-color: #f43f3b;
|
background-color: #f43f3b;
|
||||||
|
|
||||||
&.btn-active {
|
&.btn-active {
|
||||||
transform: scale(0.9);
|
transform: scale(0.9);
|
||||||
background-color: #d93632;
|
background-color: #d93632;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.accept-btn {
|
&.accept-btn {
|
||||||
background-color: #07c160;
|
background-color: #07c160;
|
||||||
|
|
||||||
&.btn-active {
|
&.btn-active {
|
||||||
transform: scale(0.9);
|
transform: scale(0.9);
|
||||||
background-color: #06ad56;
|
background-color: #06ad56;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.mic-btn {
|
&.mic-btn {
|
||||||
background-color: rgba(255, 255, 255, 0.2);
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
|
|
||||||
&.mic-muted {
|
&.mic-muted {
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.btn-active {
|
&.btn-active {
|
||||||
transform: scale(0.9);
|
transform: scale(0.9);
|
||||||
background-color: rgba(255, 255, 255, 0.3);
|
background-color: rgba(255, 255, 255, 0.3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.speaker-btn {
|
&.speaker-btn {
|
||||||
background-color: rgba(255, 255, 255, 0.2);
|
background-color: rgba(255, 255, 255, 0.2);
|
||||||
|
|
||||||
&.speaker-on {
|
&.speaker-on {
|
||||||
background-color: rgba(255, 255, 255, 0.3);
|
background-color: rgba(255, 255, 255, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.btn-active {
|
&.btn-active {
|
||||||
transform: scale(0.9);
|
transform: scale(0.9);
|
||||||
background-color: rgba(255, 255, 255, 0.3);
|
background-color: rgba(255, 255, 255, 0.3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-text {
|
.btn-text {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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% {
|
70% {
|
||||||
box-shadow: 0 0 0 30rpx rgba(26, 173, 25, 0);
|
box-shadow: 0 0 0 30rpx rgba(26, 173, 25, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0);
|
box-shadow: 0 0 0 0 rgba(26, 173, 25, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 响应式调整 */
|
/* 响应式调整 */
|
||||||
@media (max-height: 600px) {
|
@media (max-height: 600px) {
|
||||||
.incoming-controls {
|
.incoming-controls {
|
||||||
padding: 40rpx 30rpx 80rpx !important;
|
padding: 40rpx 30rpx 80rpx !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
818
stores/user.js
818
stores/user.js
@@ -1,419 +1,461 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
import {
|
import {
|
||||||
defineStore
|
getToken,
|
||||||
} from 'pinia'
|
getUserInfoData,
|
||||||
import {
|
setUserInfoData,
|
||||||
getToken,
|
removeUserInfoData,
|
||||||
getUserInfoData,
|
getSig,
|
||||||
setUserInfoData,
|
setSig,
|
||||||
removeUserInfoData,
|
removeSig,
|
||||||
getSig,
|
getFontSize,
|
||||||
setSig,
|
setFontSize,
|
||||||
removeSig,
|
removeFontSize
|
||||||
getFontSize,
|
|
||||||
setFontSize,
|
|
||||||
removeFontSize
|
|
||||||
} from '@/utils/storage'
|
} from '@/utils/storage'
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
import {
|
import { useLoginState } from '@/uni_modules/tuikit-atomic-x/state/LoginState'
|
||||||
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 {
|
import { reasonDeal, errorDeal, imCode } from '@/utils/code.js'
|
||||||
reasonDeal,
|
|
||||||
errorDeal,
|
|
||||||
imCode
|
|
||||||
} from '@/utils/code.js'
|
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
import {
|
import { useLoginState } from 'tuikit-atomicx-vue3'
|
||||||
useLoginState
|
|
||||||
} from 'tuikit-atomicx-vue3'
|
|
||||||
// #endif
|
// #endif
|
||||||
import {
|
import { useTokenStore } from './token'
|
||||||
useTokenStore
|
import { getUserData, userLogout, updateUserData } from '@/api'
|
||||||
} from './token'
|
import { ref } from 'vue'
|
||||||
import {
|
import { useUI } from '@/utils/use-ui'
|
||||||
getUserData,
|
import { reLaunch } from '@/utils/router'
|
||||||
userLogout,
|
import { getTencentUserSig } from '@/api'
|
||||||
updateUserData
|
import { TUILogin } from '@tencentcloud/tui-core-lite'
|
||||||
} from '@/api'
|
import { TUIChatEngine } from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
import {
|
import { getUserIntegral } from '@/api/my-index'
|
||||||
ref
|
import { removeFriendList, removeGroupList } from '../utils/storage'
|
||||||
} from 'vue'
|
import { getRongYunLoginInfo } from '../api'
|
||||||
import {
|
import permision from '@/js_sdk/wa-permission/permission.js'
|
||||||
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"
|
|
||||||
import { navigateTo } from '@/utils/router'
|
import { navigateTo } from '@/utils/router'
|
||||||
|
import { sendCallMsg } from '../utils/call-user'
|
||||||
|
|
||||||
export const useUserStore = defineStore('user', () => {
|
export const useUserStore = defineStore('user', () => {
|
||||||
const {
|
const { clearToken } = useTokenStore()
|
||||||
clearToken
|
const { showDialog, showToast } = useUI()
|
||||||
} = 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)
|
||||||
|
/** 发起通话用户id */
|
||||||
|
const callUserId = ref('')
|
||||||
|
/** 通话时长(秒) */
|
||||||
|
const callDuration = ref(0)
|
||||||
|
/** 通话模式 0:语音通话 1:视频通话 */
|
||||||
|
const callMode = ref('0')
|
||||||
|
/** 通话计时器 */
|
||||||
|
const timer = ref(null)
|
||||||
|
|
||||||
/**
|
/** 开始通话计时 */
|
||||||
* 获取用户信息(可从缓存或接口)
|
const startTimer = () => {
|
||||||
*/
|
stopTimer() // 先停止之前的计时器
|
||||||
const fetchUserInfo = async () => {
|
timer.value = setInterval(() => {
|
||||||
// 尝试从本地缓存读取
|
callDuration.value++
|
||||||
const cachedToken = getToken()
|
}, 1000)
|
||||||
const cachedUserInfo = getUserInfoData()
|
}
|
||||||
const cachedSig = getSig()
|
|
||||||
|
|
||||||
if (cachedToken && cachedUserInfo) {
|
/** 停止通话计时 */
|
||||||
userInfo.value = JSON.parse(cachedUserInfo)
|
const stopTimer = () => {
|
||||||
tencentUserSig.value = JSON.parse(cachedSig)
|
if (timer.value) {
|
||||||
loginTencentIM()
|
clearInterval(timer.value)
|
||||||
return
|
timer.value = null
|
||||||
}
|
}
|
||||||
await getIntegral()
|
}
|
||||||
const res = await getUserData()
|
|
||||||
await setUserInfo(res.data)
|
|
||||||
loginTencentIM()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** 重置时间 */
|
||||||
* 设置用户信息
|
const resetTime = () => {
|
||||||
*/
|
callDuration.value = 0
|
||||||
const setUserInfo = async data => {
|
}
|
||||||
const res = await getTencentUserSig()
|
/** 通话模式更新 */
|
||||||
const ryData = await getRongYunLoginInfo()
|
const updateCallMode = mode => {
|
||||||
const IM_DATA = {
|
callMode.value = mode
|
||||||
...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 fetchUserInfo = async () => {
|
||||||
}
|
// 尝试从本地缓存读取
|
||||||
|
const cachedToken = getToken()
|
||||||
|
const cachedUserInfo = getUserInfoData()
|
||||||
|
const cachedSig = getSig()
|
||||||
|
|
||||||
/**
|
if (cachedToken && cachedUserInfo) {
|
||||||
* 登录腾讯 IM
|
userInfo.value = JSON.parse(cachedUserInfo)
|
||||||
*/
|
tencentUserSig.value = JSON.parse(cachedSig)
|
||||||
const loginTencentIM = async () => {
|
loginTencentIM()
|
||||||
await refreshUserInfo()
|
return
|
||||||
await TUILogin.login({
|
}
|
||||||
SDKAppID: tencentUserSig.value.sdkappID,
|
await getIntegral()
|
||||||
userID: tencentUserSig.value.userId,
|
const res = await getUserData()
|
||||||
userSig: tencentUserSig.value.userSig,
|
await setUserInfo(res.data)
|
||||||
framework: `vue3`
|
loginTencentIM()
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await TUIChatEngine.login({
|
/**
|
||||||
SDKAppID: tencentUserSig.value.sdkappID,
|
* 设置用户信息
|
||||||
userID: tencentUserSig.value.userId,
|
*/
|
||||||
userSig: tencentUserSig.value.userSig,
|
const setUserInfo = async data => {
|
||||||
useUploadPlugin: true // 使用文件上传插件
|
const res = await getTencentUserSig()
|
||||||
})
|
const ryData = await getRongYunLoginInfo()
|
||||||
// #ifdef H5
|
const IM_DATA = {
|
||||||
await useLoginState().login({
|
...res.data,
|
||||||
SDKAppID: tencentUserSig.value.sdkappID,
|
...ryData.data
|
||||||
userID: tencentUserSig.value.userId,
|
}
|
||||||
userSig: tencentUserSig.value.userSig
|
tencentUserSig.value = IM_DATA
|
||||||
})
|
userInfo.value = data
|
||||||
// #endif
|
setUserInfoData(data)
|
||||||
|
setSig(IM_DATA)
|
||||||
|
}
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
/** 获取用户积分 */
|
||||||
await useLoginState().login({
|
const getIntegral = async () => {
|
||||||
sdkAppID: tencentUserSig.value.sdkappID,
|
const res = await getUserIntegral()
|
||||||
userID: tencentUserSig.value.userId,
|
integralData.value = res.data.availablePoints
|
||||||
userSig: tencentUserSig.value.userSig
|
}
|
||||||
})
|
|
||||||
console.log(tencentUserSig.value.appKey, '====')
|
|
||||||
await connectIM()
|
|
||||||
// #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//连接融云IM
|
/**
|
||||||
const connectIM = async () => {
|
* 登录腾讯 IM
|
||||||
let options = {}
|
*/
|
||||||
imEngine.value = await RCIMIWEngine.create(tencentUserSig.value.appKey, options)
|
const loginTencentIM = async () => {
|
||||||
imEngine.value.setOnConnectedListener((res) => {
|
await refreshUserInfo()
|
||||||
if (res.code != 0) {
|
await TUILogin.login({
|
||||||
uni.hideLoading();
|
SDKAppID: tencentUserSig.value.sdkappID,
|
||||||
// uni.showToast({
|
userID: tencentUserSig.value.userId,
|
||||||
// title: 'OnCon:' + res.code,
|
userSig: tencentUserSig.value.userSig,
|
||||||
// icon: 'error'
|
framework: `vue3`
|
||||||
// })
|
})
|
||||||
console.log("连接已存在");
|
|
||||||
// return
|
|
||||||
}
|
|
||||||
//连接成功
|
|
||||||
CallLib.init({});
|
|
||||||
console.log('call.init')
|
|
||||||
uni.hideLoading();
|
|
||||||
uni.showToast({
|
|
||||||
title: res.userId
|
|
||||||
});
|
|
||||||
if (uni.getSystemInfoSync().platform === 'android') {
|
|
||||||
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) {
|
|
||||||
uni.hideLoading();
|
|
||||||
uni.showToast({
|
|
||||||
title: 'connect:' + code,
|
|
||||||
icon: 'error'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
await TUIChatEngine.login({
|
||||||
* 清除用户信息(退出登录)
|
SDKAppID: tencentUserSig.value.sdkappID,
|
||||||
*/
|
userID: tencentUserSig.value.userId,
|
||||||
const clearUserInfo = async () => {
|
userSig: tencentUserSig.value.userSig,
|
||||||
const show = await showDialog('提示', '确定要退出登录吗?')
|
useUploadPlugin: true // 使用文件上传插件
|
||||||
if (show) {
|
})
|
||||||
await logout()
|
// #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,
|
||||||
const logout = async () => {
|
userID: tencentUserSig.value.userId,
|
||||||
if (!userInfo.value) return
|
userSig: tencentUserSig.value.userSig
|
||||||
try {
|
})
|
||||||
userInfo.value = null
|
console.log(tencentUserSig.value.appKey, '====')
|
||||||
|
await connectIM()
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
await userLogout()
|
//连接融云IM
|
||||||
await TUILogin.logout()
|
const connectIM = async () => {
|
||||||
await TUIChatEngine.logout()
|
let options = {}
|
||||||
// #ifdef APP-PLUS
|
imEngine.value = await RCIMIWEngine.create(
|
||||||
removeFriendList()
|
tencentUserSig.value.appKey,
|
||||||
removeGroupList()
|
options
|
||||||
await useLoginState().logout()
|
)
|
||||||
// #endif
|
imEngine.value.setOnConnectedListener(res => {
|
||||||
// #ifdef H5
|
if (res.code != 0) {
|
||||||
await useLoginState().logout()
|
uni.hideLoading()
|
||||||
// #endif
|
// uni.showToast({
|
||||||
clearAllUserInfo()
|
// title: 'OnCon:' + res.code,
|
||||||
await showToast('退出登录成功', 'success')
|
// icon: 'error'
|
||||||
reLaunch('/pages/login/login')
|
// })
|
||||||
} catch (error) {
|
console.log('连接已存在')
|
||||||
clearAllUserInfo()
|
// return
|
||||||
await showToast('退出登录成功', 'success')
|
}
|
||||||
reLaunch('/pages/login/login')
|
//连接成功
|
||||||
}
|
CallLib.init({})
|
||||||
}
|
console.log('call.init')
|
||||||
|
uni.hideLoading()
|
||||||
|
// uni.showToast({
|
||||||
|
// title: res.userId
|
||||||
|
// })
|
||||||
|
console.log('登录成功')
|
||||||
|
if (uni.getSystemInfoSync().platform === 'android') {
|
||||||
|
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) {
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({
|
||||||
|
title: 'connect:' + code,
|
||||||
|
icon: 'error'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 清空所有用户缓存 */
|
function onAllListeners() {
|
||||||
const clearAllUserInfo = async () => {
|
CallLib.onCallReceived(res => {
|
||||||
userInfo.value = null
|
console.log(res)
|
||||||
tencentUserSig.value = null
|
console.log(
|
||||||
fontSizeData.value = 26
|
'Engine:OnCallReceived=>' + '监听通话呼入, 目标id=>',
|
||||||
clearToken()
|
res.data.targetId
|
||||||
removeUserInfoData()
|
)
|
||||||
removeSig()
|
if (res.data.targetId) {
|
||||||
removeFontSize()
|
// 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
|
||||||
|
)
|
||||||
|
console.log('=====通话用户id', callUserId.value)
|
||||||
|
sendCallMsg(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 refreshUserInfo = async () => {
|
const pages = getCurrentPages()
|
||||||
const res = await getUserData()
|
console.log('pages: ', pages)
|
||||||
await getIntegral()
|
if (pages.length > 1) {
|
||||||
await setUserInfoData(res.data)
|
console.log('走返回')
|
||||||
userInfo.value = res.data
|
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){
|
||||||
const updateUserInfo = async partialData => {
|
|
||||||
if (!userInfo.value) return
|
|
||||||
await updateUserData(partialData)
|
|
||||||
await refreshUserInfo()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 更新字体大小 */
|
// }
|
||||||
const updateFontSize = async fontSize => {
|
}
|
||||||
fontSizeData.value = fontSize
|
}
|
||||||
setFontSize(fontSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
// 判断页面是否是 tabBar 页面
|
||||||
imEngine,
|
function isTabBarPage(route) {
|
||||||
userInfo,
|
// 这里根据你的 pages.json 配置来判断
|
||||||
integralData,
|
const tabBarPages = [
|
||||||
tencentUserSig,
|
'TUIKit/components/TUIConversation/index',
|
||||||
fontSizeData,
|
'TUIKit/components/TUIContact/index',
|
||||||
getIntegral,
|
'pages/discover/discover',
|
||||||
clearAllUserInfo,
|
'pages/my-index/my-index'
|
||||||
updateFontSize,
|
]
|
||||||
logout,
|
|
||||||
refreshUserInfo,
|
// 判断路由是否在 tabBar 页面列表中
|
||||||
fetchUserInfo,
|
return tabBarPages.includes(route)
|
||||||
loginTencentIM,
|
}
|
||||||
setUserInfo,
|
|
||||||
clearUserInfo,
|
/**
|
||||||
updateUserInfo
|
* 清除用户信息(退出登录)
|
||||||
}
|
*/
|
||||||
})
|
const clearUserInfo = async () => {
|
||||||
|
const show = await showDialog('提示', '确定要退出登录吗?')
|
||||||
|
if (show) {
|
||||||
|
await logout()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出登录(不带提示)
|
||||||
|
*/
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 清空所有用户缓存 */
|
||||||
|
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 updateUserInfo = async partialData => {
|
||||||
|
if (!userInfo.value) return
|
||||||
|
await updateUserData(partialData)
|
||||||
|
await refreshUserInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新字体大小 */
|
||||||
|
const updateFontSize = async fontSize => {
|
||||||
|
fontSizeData.value = fontSize
|
||||||
|
setFontSize(fontSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
callUserId,
|
||||||
|
callDuration,
|
||||||
|
imEngine,
|
||||||
|
userInfo,
|
||||||
|
integralData,
|
||||||
|
tencentUserSig,
|
||||||
|
fontSizeData,
|
||||||
|
callMode,
|
||||||
|
startTimer,
|
||||||
|
stopTimer,
|
||||||
|
updateCallMode,
|
||||||
|
resetTime,
|
||||||
|
getIntegral,
|
||||||
|
clearAllUserInfo,
|
||||||
|
updateFontSize,
|
||||||
|
logout,
|
||||||
|
refreshUserInfo,
|
||||||
|
fetchUserInfo,
|
||||||
|
loginTencentIM,
|
||||||
|
setUserInfo,
|
||||||
|
clearUserInfo,
|
||||||
|
updateUserInfo
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
59
utils/call-user.js
Normal file
59
utils/call-user.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import TUIChatEngine, {
|
||||||
|
TUIChatService
|
||||||
|
} from '@tencentcloud/chat-uikit-engine-lite'
|
||||||
|
import { CHAT_MSG_CUSTOM_TYPE } from '../TUIKit/constant'
|
||||||
|
import { useAuthUser } from '../composables/useAuthUser'
|
||||||
|
import { useUserStore } from '../stores/user'
|
||||||
|
|
||||||
|
/** 格式化时间显示 */
|
||||||
|
const formatTime = date => {
|
||||||
|
const minutes = Math.floor(date / 60)
|
||||||
|
const seconds = date % 60
|
||||||
|
return `${minutes.toString().padStart(2, '0')}:${seconds
|
||||||
|
.toString()
|
||||||
|
.padStart(2, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 通话消息发送 */
|
||||||
|
export const sendCallMsg = async state => {
|
||||||
|
const { resetTime, stopTimer } = useUserStore()
|
||||||
|
const { callUserId, callMode, callDuration, tencentUserSig } =
|
||||||
|
useAuthUser()
|
||||||
|
const to = callUserId.value
|
||||||
|
const userID = tencentUserSig.value.userId
|
||||||
|
if (to !== userID) {
|
||||||
|
let title = ''
|
||||||
|
if ([0, 11].includes(state)) {
|
||||||
|
title = { 0: '已挂断', 11: '对方已拒绝' }[state]
|
||||||
|
} else {
|
||||||
|
title = `通话时长 ${formatTime(callDuration.value)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
data: JSON.stringify({
|
||||||
|
businessID:
|
||||||
|
callMode.value == 0
|
||||||
|
? CHAT_MSG_CUSTOM_TYPE.VOICE_CALL
|
||||||
|
: CHAT_MSG_CUSTOM_TYPE.VIDEO_CALL,
|
||||||
|
title,
|
||||||
|
userID: to
|
||||||
|
}),
|
||||||
|
description: title,
|
||||||
|
extension: title
|
||||||
|
}
|
||||||
|
const options = {
|
||||||
|
to,
|
||||||
|
payload,
|
||||||
|
conversationType: TUIChatEngine.TYPES.CONV_C2C,
|
||||||
|
needReadReceipt: false
|
||||||
|
}
|
||||||
|
resetTime()
|
||||||
|
await TUIChatService.sendCustomMessage(options)
|
||||||
|
} else {
|
||||||
|
resetTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callMode.value == 1) {
|
||||||
|
stopTimer()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user