语音通话类型展示

This commit is contained in:
2022-02-21 12:05:19 +08:00
parent ce954c5dcc
commit f4b06bbf01
7 changed files with 202 additions and 41 deletions

View File

@@ -28,9 +28,6 @@
} }
} }
}, },
mounted() {
console.log(this.item);
},
computed: { computed: {
contact() { contact() {
return function(targetId) { return function(targetId) {

View File

@@ -22,10 +22,10 @@
<view class="preview" v-if="msg.objectName=='RC:LBSMsg'"> <view class="preview" v-if="msg.objectName=='RC:LBSMsg'">
<text v-if="conversationType == 3">{{ user.name }}</text>[位置] <text v-if="conversationType == 3">{{ user.name }}</text>[位置]
</view> </view>
<view class="preview" v-if="msg.objectName=='RC:AudioMsg'"> <view class="preview" v-if="msg.objectName=='RC:InfoNtf' && msg.message=='0'">
<text v-if="conversationType == 3">{{ user.name }}</text>[语音通话] <text v-if="conversationType == 3">{{ user.name }}</text>[语音通话]
</view> </view>
<view class="preview" v-if="msg.objectName=='RC:VideoMsg'"> <view class="preview" v-if="msg.objectName=='RC:InfoNtf' && msg.message=='1'">
<text v-if="conversationType == 3">{{ user.name }}</text>[视频通话] <text v-if="conversationType == 3">{{ user.name }}</text>[视频通话]
</view> </view>
<view class="preview" v-if="msg.objectName=='RC:GrpNtf'"> <view class="preview" v-if="msg.objectName=='RC:GrpNtf'">

View File

@@ -0,0 +1,76 @@
<template>
<view class="msg--text">
<text class="name" v-if="!guest && name">{{ name }}</text>
<view>
<text class="im--text" :class="guest ? 'right': 'left'" v-if="msg.message == '1'">语音通话</text>
<text class="im--text" :class="guest ? 'right': 'left'" v-else>视频通话</text>
</view>
</view>
</template>
<!-- msg
{
"message": "1",
"objectName": "RC:InfoNtf",
"userInfo": {
"userId": "10051",
"name": "Jason.电信",
"extra": "",
"portraitUrl": "http://storage.zh.shangkelian.cn/uploads/2022/02/16/29b13f5301694721ad7acd8b8b67bbd9.jpg"
}
}
-->
<script>
export default {
name: 'showText',
props: {
msg: {
type: Object,
default: () => {
return {}
}
},
name: {
type: String,
default: ''
},
guest: {
type: Boolean,
default: true
}
},
mounted() {
console.log(this.msg);
}
}
</script>
<style scoped lang="scss">
.msg--text {
.name {
font-size: 26rpx;
color: $text-gray-m;
display: inline-block;
}
.im--text {
max-width: 508rpx;
padding: 20rpx;
line-height: 46rpx;
font-size: 32rpx;
color: $text-color;
display: inline-block;
word-break: break-all;
&.left {
border-radius: 0 20rpx 20rpx 20rpx;
background: white;
}
&.right {
border-radius: 20rpx 0 20rpx 20rpx;
background: $main-color;
color: white;
}
}
}
</style>

View File

@@ -37,6 +37,7 @@
getFriendsLetter getFriendsLetter
} from '@/apis/interfaces/im'; } from '@/apis/interfaces/im';
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import im from '@/utils/im/index.js'
export default { export default {
data() { data() {

View File

@@ -1,27 +1,30 @@
<template> <template>
<view class="call"> <view class="call">
<view class="video"> <view class="video">
<RongCloud-Call-RCUniCallView ref="bigVideoView" :style="{width:windowWidth+'px',height:windowHeight+'px'}" <RongCloud-Call-RCUniCallView ref="bigVideoView" :style="bigVideoStyle" class="bigVideoView">
class="bigVideoView">
</RongCloud-Call-RCUniCallView>
<RongCloud-Call-RCUniCallView ref="smallVideoView" class="smallVideoView">
</RongCloud-Call-RCUniCallView> </RongCloud-Call-RCUniCallView>
<movable-area class="movableArea" :style="movableAreaStyle">
<movable-view class="movableView" direction="all" :x="50" :y="50" v-if="mediaType == 1 && connected">
<RongCloud-Call-RCUniCallView ref="smallVideoView" class="smallVideoView" @click="changeMine">
</RongCloud-Call-RCUniCallView>
</movable-view>
</movable-area>
</view> </view>
<view class="status" v-if="!connected || mediaType == 0"> <view class="status" v-if="!connected">
<view class="remote"> <view class="remote">
<u-avatar :src="contact(targetId).portraitUrl" shape="square" size="96" bgColor="#fff" /> <u-avatar :src="contact(targetId).portraitUrl" shape="square" :size="avatarSize" bgColor="#fff" />
<view><text class="nickname">{{ contact(targetId).name }}</text></view> <view><text class="nickname">{{ contact(targetId).name }}</text></view>
<view v-if="remoteRinging"><text class="mediaType">等待对方接听</text></view> <view v-if="remoteRinging"><text class="mediaType">等待对方接听</text></view>
<view v-if="connected"><text class="mediaType">已接通</text></view> <view v-if="connected"><text class="mediaType">已接通</text></view>
<view v-else><text class="mediaType">{{ mediaType == 0 ? '邀请您语音通话' : '邀请您视频通话' }}</text></view>
</view> </view>
</view> </view>
<view class="buttons"> <view class="buttons">
<view class="btn" v-if="connected" @click="changeMicrophone"> <view class="btn" v-if="connected" @click="changeMicrophone">
<view class="icon"> <view class="icon">
<u-icon name="mic" color="#ffffff" size="30" /> <u-icon name="mic-off" color="#ffffff" size="30" v-if="micOff" />
<u-icon name="mic-off" color="#ffffff" size="30" /> <u-icon name="mic" color="#ffffff" size="30" v-else />
</view> </view>
<text class="text">麦克风</text> <text class="text">麦克风</text>
</view> </view>
@@ -39,8 +42,8 @@
</view> </view>
<view class="btn" v-if="connected" @click="changeSpeaker"> <view class="btn" v-if="connected" @click="changeSpeaker">
<view class="icon"> <view class="icon">
<u-icon name="volume-fill" color="#ffffff" size="27" /> <u-icon name="volume-off-fill" color="#ffffff" size="27" v-if="volumeOff" />
<u-icon name="volume-off-fill" color="#ffffff" size="27" /> <u-icon name="volume-fill" color="#ffffff" size="27" v-else />
</view> </view>
<text class="text">扬声器</text> <text class="text">扬声器</text>
</view> </view>
@@ -51,22 +54,30 @@
<script> <script>
import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index' import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
import * as IMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as IMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import utils from '@/utils/index.js'
export default { export default {
data() { data() {
return { return {
targetId: '', targetId: '',
mediaType: 0, // 0 语音 1 视频 mediaType: 0, // 0 语音 1 视频
isOut: false,
connected: false, connected: false,
micStatus: false, micStatus: false,
speStatus: false, speStatus: false,
remoteRinging: false, remoteRinging: false,
ring: null, ring: null,
isCall: false isCall: false,
avatarSize: 96,
bigVideoStyle: {},
movableAreaStyle: {},
// 关闭麦克风
micOff: false,
// 关闭扬声器
volumeOff: false
} }
}, },
onLoad(e) { onLoad(e) {
this.avatarSize = utils.rpx2px(200)
this.targetId = e.targetId this.targetId = e.targetId
this.mediaType = e.mediaType this.mediaType = e.mediaType
this.isCall = Boolean(e.isCall) this.isCall = Boolean(e.isCall)
@@ -75,9 +86,9 @@
CallLib.startSingleCall(this.targetId, this.mediaType, ''); CallLib.startSingleCall(this.targetId, this.mediaType, '');
if (this.mediaType == 1) { if (this.mediaType == 1) {
const session = CallLib.getCurrentCallSession() const session = CallLib.getCurrentCallSession()
this.$nextTick(() => { setTimeout(() => {
CallLib.setVideoView(session.mine.userId, this.$refs.bigVideoView.ref, 0, false) CallLib.setVideoView(session.mine.userId, this.$refs.bigVideoView.ref, 0, false)
}) }, 200)
} }
} }
// 响铃 // 响铃
@@ -91,6 +102,15 @@
uni.$once('onRemoteUserJoined', () => { uni.$once('onRemoteUserJoined', () => {
this.remoteRinging = false this.remoteRinging = false
}) })
this.bigVideoStyle = {
width: this.windowWidth + 'px',
height: this.windowHeight + 'px',
// backgroundImage: `url("${this.contact(this.targetId).portraitUrl}")`
}
this.movableAreaStyle = {
width: this.windowWidth + 'px',
height: this.windowHeight + 'px',
}
}, },
beforeDestroy() { beforeDestroy() {
@@ -109,11 +129,40 @@
} }
}, },
methods: { methods: {
afterHangup() {
const conversationType = IMLib.ConversationType.PRIVATE // 会话类型
const targetId = this.targetId
const sentStatus = 30
const messageContent = {
objectName: 'RC:InfoNtf',
userInfo: this.$store.getters.sender,
message: String(this.mediaType),
extra: '这里传接通和时长信息',
}
const sentTime = 0 // 消息的发送时间
IMLib.insertOutgoingMessage(conversationType, targetId, sentStatus, messageContent, sentTime,
({
code,
message
}) => {
console.log(code);
// 插入消息成功
if (code === 0) {
console.log(message)
}
}
)
uni.$emit('onReceiveMessage', {
targetId: this.targetId
})
},
changeMicrophone() { changeMicrophone() {
this.micOff = !this.micOff
CallLib.enableMicrophone(this.micStatus) CallLib.enableMicrophone(this.micStatus)
this.micStatus = !this.micStatus this.micStatus = !this.micStatus
}, },
changeSpeaker() { changeSpeaker() {
this.volumeOff = !this.volumeOff
CallLib.enableSpeaker(this.speStatus) CallLib.enableSpeaker(this.speStatus)
this.speStatus = !this.speStatus this.speStatus = !this.speStatus
}, },
@@ -134,7 +183,25 @@
}, 200) }, 200)
} }
}, },
// 切换主屏显示人
changeMine() {
if (this.isCall) {
const session = CallLib.getCurrentCallSession()
setTimeout(() => {
CallLib.setVideoView(session.targetId, this.$refs.bigVideoView.ref, 0, false)
CallLib.setVideoView(session.mine.userId, this.$refs.smallVideoView.ref, 0, true)
}, 200)
} else {
const session = CallLib.getCurrentCallSession()
setTimeout(() => {
CallLib.setVideoView(session.targetId, this.$refs.smallVideoView.ref, 0, true)
CallLib.setVideoView(session.mine.userId, this.$refs.bigVideoView.ref, 0, false)
}, 200)
}
this.isCall = !this.isCall
},
hangup() { hangup() {
this.afterHangup()
CallLib.hangup() CallLib.hangup()
this.stopRing() this.stopRing()
@@ -181,23 +248,33 @@
position: relative; position: relative;
.video { .video {
.bigVideoView { .movableArea {
background: #000; position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
.movableView {
width: 180rpx;
height: 320rpx;
position: relative;
.smallVideoView {
width: 180rpx;
height: 320rpx;
background-color: #666;
}
}
} }
.smallVideoView { .bigVideoView {
background: blue; background-color: #666;
position: absolute;
right: 100rpx;
top: 100rpx;
width: 180rpx;
height: 320rpx;
} }
} }
.status { .status {
flex: 1; flex: 1;
background: #666;
width: 750rpx; width: 750rpx;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
@@ -236,10 +313,6 @@
.btn { .btn {
align-items: center; align-items: center;
&.hangup {
background-color: $text-price;
}
.icon { .icon {
background: $main-color; background: $main-color;
width: 132rpx; width: 132rpx;
@@ -248,6 +321,10 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
&.hangup {
background-color: $text-price;
}
} }
.text { .text {

View File

@@ -17,6 +17,8 @@
:msg="item.content" /> :msg="item.content" />
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1" <show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
:msg="item.content" /> :msg="item.content" />
<show-call v-if="item.objectName === 'RC:InfoNtf'" :guest="item.messageDirection == 1"
:msg="item.content" />
<view class="state" v-if="item.messageDirection == 1"> <view class="state" v-if="item.messageDirection == 1">
<text <text
:class="item.sentStatus === 50?'state-text':'state-text-active'">{{ item.sentStatus == 50 ? '已读': '未读'}}</text> :class="item.sentStatus === 50?'state-text':'state-text-active'">{{ item.sentStatus == 50 ? '已读': '未读'}}</text>
@@ -34,13 +36,15 @@
import showVoice from '../components/showVoice' import showVoice from '../components/showVoice'
import showImage from '../components/showImage' import showImage from '../components/showImage'
import showText from '../components/showText' import showText from '../components/showText'
import showCall from '../components/showCall'
import sentMessageBar from '../components/sentMessageBar' import sentMessageBar from '../components/sentMessageBar'
export default { export default {
components: { components: {
sentMessageBar, sentMessageBar,
showVoice, showVoice,
showImage, showImage,
showText showText,
showCall
}, },
data() { data() {
return { return {
@@ -119,7 +123,7 @@
this.conversationType, this.conversationType,
this.targetId, this.targetId,
0, 0,
20, 120,
true, true,
(messages) => { (messages) => {
this.messages = messages this.messages = messages
@@ -189,18 +193,23 @@
&.right { &.right {
flex-direction: row-reverse; flex-direction: row-reverse;
.state { .state {
text-align: right; text-align: right;
} }
} }
.msg { .msg {
margin: 0 20rpx; margin: 0 20rpx;
.state { .state {
padding-top: 10rpx; padding-top: 10rpx;
.state-text { .state-text {
font-size: $title-size-m - 2; font-size: $title-size-m - 2;
color: rgba($color: $main-color, $alpha: 0.3) color: rgba($color: $main-color, $alpha: 0.3)
} }
.state-text-active { .state-text-active {
font-size: $title-size-m - 2; font-size: $title-size-m - 2;
color: #cecece; color: #cecece;

View File

@@ -16,7 +16,8 @@ const getMessageList = (conversationType, targetId, timeStamp, count, isForward,
'RC:SightMsg', 'RC:SightMsg',
'RC:ReferenceMsg', 'RC:ReferenceMsg',
'RC:CombineMsg', 'RC:CombineMsg',
'RC:GrpNtf' 'RC:GrpNtf',
'RC:InfoNtf'
] ]
RongIMLib.getHistoryMessagesByTimestamp( RongIMLib.getHistoryMessagesByTimestamp(