简单的视频通讯
This commit is contained in:
@@ -5,21 +5,24 @@
|
||||
<!-- 聊天窗口 -->
|
||||
<view class="chat-item" v-for="(item,index) in messages" :key="index">
|
||||
<view class="chat-item-article" :class="item.messageDirection == 1 ? 'right' : 'left'">
|
||||
<view class="chat-msg">
|
||||
<view class="chat-msg">
|
||||
<!-- 文字消息 -->
|
||||
<view class="chat-msg-text">{{ item.content.content }}</view>
|
||||
<view class="chat-msg-text">{{ item.content.content }}</view>
|
||||
<!-- 语音消息 -->
|
||||
<view class="chat-msg-audio" @click="onPlayMsg()">
|
||||
<image v-if="item.messageDirection == 0" src="@/static/icon/audio_ green.png" mode="widthFix"></image>
|
||||
10"
|
||||
<image v-if="item.messageDirection == 1" src="@/static/icon/audio_white.png" mode="widthFix"></image>
|
||||
<view class="chat-msg-audio" @click="onPlayMsg()">
|
||||
<image v-if="item.messageDirection == 0" src="@/static/icon/audio_ green.png"
|
||||
mode="widthFix"></image>
|
||||
10"
|
||||
<image v-if="item.messageDirection == 1" src="@/static/icon/audio_white.png"
|
||||
mode="widthFix"></image>
|
||||
</view>
|
||||
<!-- 预留一些图片,语音表情包等位置 -->
|
||||
</view>
|
||||
<view class="chat-status" :class="{'hide': item.sentStatus == 50}"
|
||||
v-if="item.messageDirection == 1">{{targetId}}{{ item.sentStatus == 50 ? '已读': '未读'}}</view>
|
||||
<view class="chat-avatar" @click="showFriend(targetId, item.messageDirection)">
|
||||
<u-avatar v-if="item.messageDirection == 2" shape="square" bg-color="#ffffff" :src="userInfo.portraitUrl"></u-avatar>
|
||||
<view class="chat-avatar" @click="showFriend(targetId, item.messageDirection)">
|
||||
<u-avatar v-if="item.messageDirection == 2" shape="square" bg-color="#ffffff"
|
||||
:src="userInfo.portraitUrl"></u-avatar>
|
||||
<u-avatar v-else shape="square" bg-color="#ffffff" :src="$store.getters.sender.portraitUrl" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -29,34 +32,36 @@
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="chat-footer">
|
||||
<view class="msg-type" @click="msgType">
|
||||
<image src="@/static/icon/key-icon.png" v-if="importTabs === 0" mode="widthFix"></image>
|
||||
<image src="@/static/icon/msg-icon.png" v-if="importTabs === 1" mode="widthFix"></image>
|
||||
</view>
|
||||
<block v-if="importTabs === 0">
|
||||
<button type="default" class="chat-mp3" hover-class="chat-hover" @touchstart="startAudio" @touchend="chendAudio">按住 说话</button>
|
||||
</block>
|
||||
<block v-if="importTabs === 1">
|
||||
<input class="chat-input" type="text" v-model="inputTxt" confirm-type="发送" @confirm="send" cursor-spacing="10" />
|
||||
</block>
|
||||
<view class="chat-footer">
|
||||
<view class="msg-type" @click="msgType">
|
||||
<image src="@/static/icon/key-icon.png" v-if="importTabs === 0" mode="widthFix"></image>
|
||||
<image src="@/static/icon/msg-icon.png" v-if="importTabs === 1" mode="widthFix"></image>
|
||||
</view>
|
||||
<block v-if="importTabs === 0">
|
||||
<button type="default" class="chat-mp3" hover-class="chat-hover" @touchstart="startAudio"
|
||||
@touchend="chendAudio">按住 说话</button>
|
||||
</block>
|
||||
<block v-if="importTabs === 1">
|
||||
<input class="chat-input" type="text" v-model="inputTxt" confirm-type="发送" @confirm="send"
|
||||
cursor-spacing="10" />
|
||||
</block>
|
||||
<button class="chat-push" :disabled="disabled" size="mini" @click="send">发送</button>
|
||||
</view>
|
||||
|
||||
<!-- 录音中提示 -->
|
||||
<view class="audio-transcribe" v-if="showAudioTranscribe">
|
||||
<image src="@/static/icon/record-icon.png" mode="widthFix"></image>
|
||||
<view class="text">录音中 {{transcribeTime}} s</view>
|
||||
</view>
|
||||
|
||||
<!-- 录音中提示 -->
|
||||
<view class="audio-transcribe" v-if="showAudioTranscribe">
|
||||
<image src="@/static/icon/record-icon.png" mode="widthFix"></image>
|
||||
<view class="text">录音中 {{transcribeTime}} s</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
|
||||
import im from '@/utils/im/index.js'
|
||||
import permision from "@/js_sdk/wa-permission/permission.js"
|
||||
|
||||
var transcribe
|
||||
import im from '@/utils/im/index.js'
|
||||
import permision from "@/js_sdk/wa-permission/permission.js"
|
||||
|
||||
var transcribe
|
||||
var recorderManager = uni.getRecorderManager()
|
||||
|
||||
export default {
|
||||
@@ -72,11 +77,11 @@
|
||||
name: '',
|
||||
userId: '',
|
||||
portraitUrl: ''
|
||||
},
|
||||
importTabs: 0,
|
||||
showAudioTranscribe:false,
|
||||
transcribeTime: 60,
|
||||
audioSrc: '',
|
||||
},
|
||||
importTabs: 0,
|
||||
showAudioTranscribe: false,
|
||||
transcribeTime: 60,
|
||||
audioSrc: '',
|
||||
audioContextPaused: true
|
||||
}
|
||||
},
|
||||
@@ -104,18 +109,19 @@
|
||||
this.getMessageList()
|
||||
|
||||
// 监听消息回执
|
||||
RongIMLib.addReadReceiptReceivedListener((result) => {
|
||||
const res = result.data.message
|
||||
if (res.targetId == this.targetId) {
|
||||
RongIMLib.addReadReceiptReceivedListener(({
|
||||
data
|
||||
}) => {
|
||||
if (data.targetId == this.targetId) {
|
||||
this.getMessageList()
|
||||
}
|
||||
})
|
||||
|
||||
// 监听录音结束
|
||||
recorderManager.onStop(res => {
|
||||
if(res.tempFilePath) this.audioSrc = res.tempFilePath
|
||||
console.log('------------------获取到了录音的临时路径---------------')
|
||||
console.log(res.tempFilePath)
|
||||
})
|
||||
|
||||
// 监听录音结束
|
||||
recorderManager.onStop(res => {
|
||||
if (res.tempFilePath) this.audioSrc = res.tempFilePath
|
||||
console.log('------------------获取到了录音的临时路径---------------')
|
||||
console.log(res.tempFilePath)
|
||||
})
|
||||
},
|
||||
onUnload() {
|
||||
@@ -155,66 +161,66 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 播放语音消息
|
||||
onPlayMsg(){
|
||||
let innerAudioContext = uni.createInnerAudioContext()
|
||||
innerAudioContext.src = this.audioSrc
|
||||
if(this.audioContextPaused){
|
||||
innerAudioContext.play()
|
||||
this.audioContextPaused = false
|
||||
return
|
||||
}
|
||||
innerAudioContext.stop()
|
||||
innerAudioContext.onStop(resStop => {
|
||||
this.audioContextPaused = true
|
||||
})
|
||||
},
|
||||
// 检查安卓录制权限
|
||||
async getAndroidPermission(){
|
||||
return await permision.requestAndroidPermission('android.permission.RECORD_AUDIO')
|
||||
},
|
||||
// 切换聊天信息
|
||||
msgType(){
|
||||
this.importTabs = this.importTabs === 1 ? 0: 1
|
||||
},
|
||||
// 录制语音消息
|
||||
startAudio(e){
|
||||
this.getAndroidPermission().then(code => {
|
||||
switch (code){
|
||||
case 1:
|
||||
this.showAudioTranscribe = true
|
||||
recorderManager.start()
|
||||
transcribe = setInterval(() => {
|
||||
this.transcribeTime -= 1
|
||||
if(this.transcribeTime === 0){
|
||||
this.chendAudio()
|
||||
}
|
||||
},1000)
|
||||
break;
|
||||
case 0:
|
||||
uni.showToast({
|
||||
title: '暂无麦克风权限,请前往应用设置开启麦克风',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
case -1:
|
||||
uni.showToast({
|
||||
title: '应用权限错误',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
}
|
||||
})
|
||||
},
|
||||
// 结束录音
|
||||
chendAudio(e){
|
||||
if(!this.showAudioTranscribe) return
|
||||
recorderManager.stop()
|
||||
clearInterval(transcribe)
|
||||
this.transcribeTime = 60
|
||||
this.showAudioTranscribe = false
|
||||
},
|
||||
methods: {
|
||||
// 播放语音消息
|
||||
onPlayMsg() {
|
||||
let innerAudioContext = uni.createInnerAudioContext()
|
||||
innerAudioContext.src = this.audioSrc
|
||||
if (this.audioContextPaused) {
|
||||
innerAudioContext.play()
|
||||
this.audioContextPaused = false
|
||||
return
|
||||
}
|
||||
innerAudioContext.stop()
|
||||
innerAudioContext.onStop(resStop => {
|
||||
this.audioContextPaused = true
|
||||
})
|
||||
},
|
||||
// 检查安卓录制权限
|
||||
async getAndroidPermission() {
|
||||
return await permision.requestAndroidPermission('android.permission.RECORD_AUDIO')
|
||||
},
|
||||
// 切换聊天信息
|
||||
msgType() {
|
||||
this.importTabs = this.importTabs === 1 ? 0 : 1
|
||||
},
|
||||
// 录制语音消息
|
||||
startAudio(e) {
|
||||
this.getAndroidPermission().then(code => {
|
||||
switch (code) {
|
||||
case 1:
|
||||
this.showAudioTranscribe = true
|
||||
recorderManager.start()
|
||||
transcribe = setInterval(() => {
|
||||
this.transcribeTime -= 1
|
||||
if (this.transcribeTime === 0) {
|
||||
this.chendAudio()
|
||||
}
|
||||
}, 1000)
|
||||
break;
|
||||
case 0:
|
||||
uni.showToast({
|
||||
title: '暂无麦克风权限,请前往应用设置开启麦克风',
|
||||
icon: 'none'
|
||||
})
|
||||
break;
|
||||
case -1:
|
||||
uni.showToast({
|
||||
title: '应用权限错误',
|
||||
icon: 'none'
|
||||
})
|
||||
break;
|
||||
}
|
||||
})
|
||||
},
|
||||
// 结束录音
|
||||
chendAudio(e) {
|
||||
if (!this.showAudioTranscribe) return
|
||||
recorderManager.stop()
|
||||
clearInterval(transcribe)
|
||||
this.transcribeTime = 60
|
||||
this.showAudioTranscribe = false
|
||||
},
|
||||
getMessageList() {
|
||||
// 获取消息列表
|
||||
const objectNames = [
|
||||
@@ -253,10 +259,12 @@
|
||||
this.inputTxt = ''
|
||||
})
|
||||
},
|
||||
showFriend(targetId, type) {
|
||||
this.$Router.push({
|
||||
name: type === 1 ? 'imFriendsMine' : 'imFriendsInfo',
|
||||
params: {targetId}
|
||||
showFriend(targetId, type) {
|
||||
this.$Router.push({
|
||||
name: type === 1 ? 'imFriendsMine' : 'imFriendsInfo',
|
||||
params: {
|
||||
targetId
|
||||
}
|
||||
})
|
||||
},
|
||||
scrollBottom() {
|
||||
@@ -285,31 +293,33 @@
|
||||
<style lang="scss" scoped>
|
||||
.chat-content {
|
||||
height: 100vh;
|
||||
background: $window-color;
|
||||
|
||||
.audio-transcribe{
|
||||
background: rgba($color: #000000, $alpha: .6);
|
||||
position: fixed;
|
||||
height: 200rpx;
|
||||
width: 300rpx;
|
||||
border-radius: $radius;
|
||||
color: white;
|
||||
z-index: 99;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-top: -200rpx;
|
||||
margin-left: -150rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
image{
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
}
|
||||
.text{
|
||||
font-size: $title-size-m;
|
||||
}
|
||||
background: $window-color;
|
||||
|
||||
.audio-transcribe {
|
||||
background: rgba($color: #000000, $alpha: .6);
|
||||
position: fixed;
|
||||
height: 200rpx;
|
||||
width: 300rpx;
|
||||
border-radius: $radius;
|
||||
color: white;
|
||||
z-index: 99;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-top: -200rpx;
|
||||
margin-left: -150rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
image {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
}
|
||||
|
||||
.text {
|
||||
font-size: $title-size-m;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-scrool {
|
||||
@@ -341,22 +351,25 @@
|
||||
|
||||
.chat-msg {
|
||||
overflow: hidden;
|
||||
|
||||
.chat-msg-text {
|
||||
display: inline-block;
|
||||
padding: ($padding - 10) $padding;
|
||||
color: $text-color;
|
||||
box-sizing: border-box;
|
||||
font-size: $title-size-lg;
|
||||
}
|
||||
.chat-msg-audio{
|
||||
@extend .chat-msg-text;
|
||||
width: 50%;
|
||||
image{
|
||||
width: 38rpx;
|
||||
height: 38rpx;
|
||||
margin: 0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-msg-audio {
|
||||
@extend .chat-msg-text;
|
||||
width: 50%;
|
||||
|
||||
image {
|
||||
width: 38rpx;
|
||||
height: 38rpx;
|
||||
margin: 0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,15 +385,16 @@
|
||||
|
||||
.chat-avatar {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
background: white;
|
||||
border-radius: $radius-m;
|
||||
top: 0;
|
||||
background: white;
|
||||
border-radius: $radius-m;
|
||||
}
|
||||
|
||||
&.left {
|
||||
.chat-avatar {
|
||||
left: $margin;
|
||||
}
|
||||
|
||||
.chat-msg {
|
||||
.chat-msg-text {
|
||||
background-color: white;
|
||||
@@ -396,6 +410,7 @@
|
||||
|
||||
.chat-msg {
|
||||
text-align: right;
|
||||
|
||||
.chat-msg-text {
|
||||
border-radius: $radius*2 0 $radius*2 $radius*2;
|
||||
background: $main-color;
|
||||
@@ -417,18 +432,21 @@
|
||||
background: white;
|
||||
box-sizing: border-box;
|
||||
z-index: 99;
|
||||
.msg-type{
|
||||
position: absolute;
|
||||
top: 20rpx;
|
||||
left: $padding;
|
||||
line-height: 80rpx;
|
||||
image{
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
vertical-align: middle;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.msg-type {
|
||||
position: absolute;
|
||||
top: 20rpx;
|
||||
left: $padding;
|
||||
line-height: 80rpx;
|
||||
|
||||
image {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
vertical-align: middle;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-input {
|
||||
background: $window-color;
|
||||
height: 80rpx;
|
||||
@@ -436,23 +454,24 @@
|
||||
font-size: $title-size-m;
|
||||
padding: 0 $padding;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.chat-mp3{
|
||||
background: $window-color;
|
||||
line-height: 80rpx;
|
||||
text-align: center;
|
||||
border-radius: $radius-lg;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
font-size: $title-size-m;
|
||||
&::after{
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-hover{
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
.chat-mp3 {
|
||||
background: $window-color;
|
||||
line-height: 80rpx;
|
||||
text-align: center;
|
||||
border-radius: $radius-lg;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
font-size: $title-size-m;
|
||||
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-hover {
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
.chat-push[size='mini'] {
|
||||
|
||||
Reference in New Issue
Block a user