From db6c3e7ea2c39b467bf2230f9562179fcc49b461 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 28 Jan 2022 09:39:36 +0800 Subject: [PATCH 1/7] test --- pages/im/friends/info.vue | 2 +- pages/im/index.vue | 3 + pages/im/private/call.nvue | 149 ++++++++++++++++++++++--------------- pages/im/private/index.vue | 5 -- utils/im/index.js | 61 ++++++++------- 5 files changed, 122 insertions(+), 98 deletions(-) diff --git a/pages/im/friends/info.vue b/pages/im/friends/info.vue index 98c117a..1f9b382 100644 --- a/pages/im/friends/info.vue +++ b/pages/im/friends/info.vue @@ -207,7 +207,7 @@ singleCall(e) { CallLib.startSingleCall(this.targetId, e.type, ''); uni.redirectTo({ - url: '/pages/im/private/call', + url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type, success: (err) => { console.log('跳转视频通话成功'); }, diff --git a/pages/im/index.vue b/pages/im/index.vue index 54e6e4f..961e989 100644 --- a/pages/im/index.vue +++ b/pages/im/index.vue @@ -205,6 +205,9 @@ // 进入聊天的详情页面,清理未读消息数量 toDetail(item) { this.hidePop() + // uni.navigateTo({ + // url: '/pages/im/private/call?targetId=' + item.targetId + '&mediaType=1' + // }) uni.navigateTo({ url: '/pages/im/private/index?targetId=' + item.targetId + '&conversationType=' + item .conversationType diff --git a/pages/im/private/call.nvue b/pages/im/private/call.nvue index 439c555..3535a78 100644 --- a/pages/im/private/call.nvue +++ b/pages/im/private/call.nvue @@ -8,20 +8,42 @@ - + - - {{userInfo.name}} - 等待对方接听 - 已接通 {{ connected }} - {{ mediaType == 0 ? '邀请您语音通话' : '邀请您视频通话' }} + + {{userInfo.name}} + 等待对方接听 + 已接通 + {{ mediaType == 0 ? '邀请您语音通话' : '邀请您视频通话' }} - 麦克风 - 挂断 - 接听 - 扬声器 + + + + + + 麦克风 + + + + + + 挂断 + + + + + + 接听 + + + + + + + 扬声器 + @@ -37,50 +59,32 @@ return { targetId: '', mediaType: 0, // 0 语音 1 视频 - users: [], userInfo: {}, isOut: false, connected: false, micStatus: false, speStatus: false, remoteRinging: false, - innerAudioContext: null + ring: null } }, onLoad(e) { - this.targetId = e.targetId || 10051 + this.targetId = e.targetId this.mediaType = e.mediaType getFriendInfo(this.targetId).then(res => { this.userInfo = res }) this.startRing() // 监听通话链接状态 - - setTimeout(() => { - CallLib.setVideoView(10047, this.$refs.bigVideoView.ref, 0, false) - }, 200) - - uni.$on('onCallConnected', () => { - console.log('OnCallConnected'); - this.connected = true - this.stopRing() - }) - uni.$on('onCallDisconnected', () => { - this.hangup() - }) - uni.$on('onRemoteUserRinging', () => { + uni.$once('onCallConnected', this.onCallConnected) + uni.$once('onCallDisconnected', this.hangup) + uni.$once('onRemoteUserRinging', () => { this.remoteRinging = true }) - uni.$on('onRemoteUserJoined', () => { + uni.$once('onRemoteUserJoined', () => { this.remoteRinging = false }) }, - beforeDestroy() { - uni.$off('onCallConnected') - uni.$off('onCallDisconnected') - uni.$off('onRemoteUserRinging') - uni.$off('onRemoteUserJoined') - }, computed: { windowWidth() { return uni.getSystemInfoSync().windowWidth @@ -100,10 +104,15 @@ }, accept() { CallLib.accept() + }, + onCallConnected() { + // 关掉铃声 + this.stopRing() + // 设置链接状态 + this.connected = true // 视频通话,才开摄像头 if (this.mediaType == 1) { const session = CallLib.getCurrentCallSession() - this.users = session.users setTimeout(() => { CallLib.setVideoView(session.targetId, this.$refs.bigVideoView.ref, 0, false) @@ -118,11 +127,10 @@ setTimeout(() => { this.downRing() - uni.navigateBack() - // uni.redirectTo({ - // url: '/pages/im/private/index?targetId=' + this.targetId + '&conversationType=1' - // }) - }, 500); + uni.switchTab({ + url: '/pages/im/index' + }) + }, 200); }, toHome() { uni.switchTab({ @@ -130,24 +138,24 @@ }) }, startRing() { - const innerAudioContext = uni.createInnerAudioContext() - this.innerAudioContext = innerAudioContext - innerAudioContext.autoplay = true - innerAudioContext.loop = true - innerAudioContext.src = '/static/im/sounds/call-ring.mp3' - innerAudioContext.onEnded(() => { - innerAudioContext.destroy() + const ring = uni.createInnerAudioContext() + this.ring = ring + ring.autoplay = true + ring.loop = true + ring.src = '/static/im/sounds/call-ring.mp3' + ring.onEnded(() => { + ring.destroy() }) }, stopRing() { - this.innerAudioContext.stop() + this.ring.stop() }, downRing() { - const innerAudioContext = uni.createInnerAudioContext() - innerAudioContext.autoplay = true - innerAudioContext.src = '/static/im/sounds/call-down.mp3' - innerAudioContext.onEnded(() => { - innerAudioContext.destroy() + const ding = uni.createInnerAudioContext() + ding.autoplay = true + ding.src = '/static/im/sounds/call-down.mp3' + ding.onEnded(() => { + ding.destroy() }) } } @@ -156,17 +164,18 @@ diff --git a/pages/im/private/index.vue b/pages/im/private/index.vue index 9f5029d..e0e70c8 100644 --- a/pages/im/private/index.vue +++ b/pages/im/private/index.vue @@ -130,11 +130,6 @@ computed: { disabled() { return this.inputTxt.length == 0 - }, - friend() { - return function(targetId) { - return this.$store.getters.userInfo(targetId) - } } }, onNavigationBarButtonTap(e) { diff --git a/utils/im/index.js b/utils/im/index.js index 4a864ea..0ce3c2f 100644 --- a/utils/im/index.js +++ b/utils/im/index.js @@ -101,39 +101,38 @@ const addListeners = () => { } }) // 监听通话呼入 - CallLib.onCallReceived((res) => { - console.log("Engine:OnCallReceived=>" + "监听通话呼入, 目标id=>", res.data.targetId); - console.log('RES', res); + CallLib.onCallReceived(({ + data + }) => { + console.log('onCallReceived'); uni.navigateTo({ - url: '/pages/im/private/call?targetId=' + res.data.targetId + '&mediaType=' + - res.data.mediaType, - success: (err) => { - console.log('跳转视频通话成功'); - }, - fail: (err) => { - console.log('跳转视频页失败', err); - } + url: '/pages/im/private/call?targetId=' + data.targetId + '&mediaType=' + + data.mediaType }) - }) - - CallLib.onCallConnected((res) => { - uni.$emit('onCallConnected'); - }) - CallLib.onCallOutgoing((res) => { - uni.$emit('onCallOutgoing'); - }) - CallLib.onRemoteUserRinging((res) => { - uni.$emit('onRemoteUserRinging'); - }) - CallLib.onRemoteUserJoined((res) => { - uni.$emit('onRemoteUserJoined'); - }) - CallLib.onCallDisconnected((res) => { - uni.$emit('onCallDisconnected'); - }) - CallLib.onRemoteUserLeft((res) => { - uni.$emit('onCallDisconnected'); - }) + }) + + // 通话建立成功 + CallLib.onCallConnected(() => { + uni.$emit('onCallConnected'); + }) + + CallLib.onCallOutgoing((res) => { + uni.$emit('onCallOutgoing'); + }) + CallLib.onRemoteUserRinging((res) => { + uni.$emit('onRemoteUserRinging'); + }) + CallLib.onRemoteUserJoined((res) => { + uni.$emit('onRemoteUserJoined'); + }) + CallLib.onCallDisconnected((res) => { + console.log('断开链接', res); + uni.$emit('onCallDisconnected'); + }) + CallLib.onRemoteUserLeft((res) => { + console.log('远端离开', res); + uni.$emit('onRemoteUserLeft'); + }) } // 维护消息列表 From 572066de9ae3c8d2d9189503dbf3209ed4cf6ffc Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 28 Jan 2022 09:51:22 +0800 Subject: [PATCH 2/7] update --- pages/im/friends/info.vue | 238 +++++++++++++++++++------------------- utils/im/index.js | 2 +- 2 files changed, 118 insertions(+), 122 deletions(-) diff --git a/pages/im/friends/info.vue b/pages/im/friends/info.vue index c1f78b6..b9c505a 100644 --- a/pages/im/friends/info.vue +++ b/pages/im/friends/info.vue @@ -126,140 +126,136 @@ } }); }, - toPrivate() { - uni.redirectTo({ - url: '/pages/im/private/index?conversationType=1&targetId=' + this.targetId - }); - }, - setRemark() { - uni.showToast({ - title: '开发中', - icon: 'none' - }); - }, - deleteFriend() { - uni.showModal({ - title: '删除确认', - content: '确认删除后不可恢复', - success: e => { - if (e.confirm) { - deleteFriend(this.targetId).then(res => { - // 删除聊天记录 - RongIMLib.deleteMessages(1, this.targetId); - RongIMLib.removeConversation(1, this.targetId); - uni.showToast({ - icon: 'none', - title: '好友删除成功', - success() { - uni.switchTab({ - url: '/pages/im/index' - }); - } - }); - }); - } + methods: { + copyAddress() { + uni.setClipboardData({ + data: this.userInfo.address, + success: () => { + uni.showToast({ + icon: 'none', + title: '复制成功' }) - }, - toPrivate() { - uni.redirectTo({ - url: '/pages/im/private/index?conversationType=1&targetId=' + this.targetId - }) - }, - setRemark() { - uni.showToast({ - title: '开发中', - icon: 'none' - }) - }, - deleteFriend() { - uni.showModal({ - title: '删除确认', - content: '确认删除后不可恢复', - success: (e) => { - if (e.confirm) { - deleteFriend(this.targetId).then(res => { - // 删除聊天记录 - RongIMLib.deleteMessages(1, this.targetId) - RongIMLib.removeConversation(1, this.targetId) - uni.showToast({ - icon: 'none', - title: '好友删除成功', - success() { - uni.switchTab({ - url: '/pages/im/index' - }) - } - }) + } + }) + }, + toPrivate() { + uni.redirectTo({ + url: '/pages/im/private/index?conversationType=1&targetId=' + this.targetId + }); + }, + setRemark() { + uni.showToast({ + title: '开发中', + icon: 'none' + }); + }, + deleteFriend() { + uni.showModal({ + title: '删除确认', + content: '确认删除后不可恢复', + success: e => { + if (e.confirm) { + deleteFriend(this.targetId).then(res => { + // 删除聊天记录 + RongIMLib.deleteMessages(1, this.targetId); + RongIMLib.removeConversation(1, this.targetId); + uni.showToast({ + icon: 'none', + title: '好友删除成功', + success() { + uni.switchTab({ + url: '/pages/im/index' + }) + } }) - } + }) } - }) - }, - setStatus() { - RongIMLib.setConversationNotificationStatus(this.conversationType, this.targetId, this.status, ({ + } + }) + }, + toPrivate() { + uni.redirectTo({ + url: '/pages/im/private/index?conversationType=1&targetId=' + this.targetId + }) + }, + setRemark() { + uni.showToast({ + title: '开发中', + icon: 'none' + }) + }, + deleteFriend() { + uni.showModal({ + title: '删除确认', + content: '确认删除后不可恢复', + success: (e) => { + if (e.confirm) { + deleteFriend(this.targetId).then(res => { + // 删除聊天记录 + RongIMLib.deleteMessages(1, this.targetId) + RongIMLib.removeConversation(1, this.targetId) + uni.showToast({ + icon: 'none', + title: '好友删除成功', + success() { + uni.switchTab({ + url: '/pages/im/index' + }) + } + }) + }) + } + } + }) + }, + setStatus() { + RongIMLib.setConversationNotificationStatus(this.conversationType, this.targetId, this.status, + ({ status }) => { this.status = !Boolean(status) }) - }, - setTop() { - RongIMLib.setConversationToTop(this.conversationType, this.targetId, this.isTop, (res) => { - RongIMLib.getConversation(this.conversationType, this.targetId, ({ - conversation - }) => { - this.isTop = conversation.isTop - }) + }, + setTop() { + RongIMLib.setConversationToTop(this.conversationType, this.targetId, this.isTop, (res) => { + RongIMLib.getConversation(this.conversationType, this.targetId, ({ + conversation + }) => { + this.isTop = conversation.isTop }) - }, - // 申请好友 - toBeFriend() { - pedingFriend(this.targetId).then(res => { - uni.showToast({ - title: '申请成功', - icon: 'none' - }); - - }) - .catch(err => { - uni.showToast({ - icon: 'error', - title: err.message, - duration: 2000 - }) - }) - }, - singleCall(e) { - CallLib.startSingleCall(this.targetId, e.type, ''); - uni.redirectTo({ - url: '/pages/im/private/call', - success: (err) => { - console.log('跳转视频通话成功'); - }, - fail: (err) => { - console.log('跳转视频页失败', err); - } - }) -<<<<<<< HEAD }) }, - singleCall(e) { - CallLib.startSingleCall(this.targetId, e.type, ''); - uni.redirectTo({ - url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type, - success: (err) => { - console.log('跳转视频通话成功'); - }, - fail: (err) => { - console.log('跳转视频页失败', err); - } - }) + // 申请好友 + toBeFriend() { + pedingFriend(this.targetId).then(res => { + uni.showToast({ + title: '申请成功', + icon: 'none' + }); + + }) + .catch(err => { + uni.showToast({ + icon: 'error', + title: err.message, + duration: 2000 + }) + }) }, -======= - }, ->>>>>>> d3c351f58f900a4484c2811b73ef00ace4632e2b + singleCall(e) { + CallLib.startSingleCall(this.targetId, e.type, ''); + uni.redirectTo({ + url: '/pages/im/private/call?targetId=' + this.targetId + '&mediaType=' + e.type, + success: (err) => { + console.log('跳转视频通话成功'); + }, + fail: (err) => { + console.log('跳转视频页失败', err); + } + }) + } } } - }; diff --git a/pages/im/index.vue b/pages/im/index.vue index 81d01a4..4be35a2 100644 --- a/pages/im/index.vue +++ b/pages/im/index.vue @@ -56,7 +56,7 @@ {{item}} - + @@ -74,7 +74,9 @@ import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index" import im from '@/utils/im/index.js' import userAuth from '@/public/userAuth' - import { getImToken } from '@/apis/interfaces/im.js' + import { + getImToken + } from '@/apis/interfaces/im.js' export default { data() { return { @@ -202,9 +204,6 @@ // 进入聊天的详情页面,清理未读消息数量 toDetail(item) { this.hidePop() - // uni.navigateTo({ - // url: '/pages/im/private/call?targetId=' + item.targetId + '&mediaType=1' - // }) uni.navigateTo({ url: '/pages/im/private/index?targetId=' + item.targetId + '&conversationType=' + item .conversationType @@ -229,10 +228,8 @@ scanQrCode() { uni.scanCode({ success: (res) => { - // "result": "ADDFRIEND|10010", if (res.scanType == 'QR_CODE') { res.result.substr(0, 10) == 'ADDFRIEND|' - // 跳转到添加好友页面 uni.navigateTo({ url: '/pages/im/friends/info?targetId=' + res.result.substr(10) }) diff --git a/utils/im/index.js b/utils/im/index.js index b86a154..4cfaafb 100644 --- a/utils/im/index.js +++ b/utils/im/index.js @@ -8,7 +8,7 @@ import { const initIm = (KEY) => { RongIMLib.init(KEY) - CallLib.init({}) + CallLib.init() addListeners() } @@ -89,7 +89,7 @@ function inArray(search, array) { const addListeners = () => { // 添加连接状态监听函数 RongIMLib.addConnectionStatusListener((res) => { - console.log('连接状态监', res.data.status); + console.log('连接状态监听', res.data.status); store.dispatch('updateConnectionStatus', res.data.status) }) // 添加消息监听函数 @@ -104,7 +104,8 @@ const addListeners = () => { CallLib.onCallReceived(({ data }) => { - console.log('onCallReceived'); + console.log('onCallReceived', data) + uni.navigateTo({ url: '/pages/im/private/call?targetId=' + data.targetId + '&mediaType=' + data.mediaType From f9e2819cc7300352471e274a5ce2716ec619cfbe Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 28 Jan 2022 11:24:10 +0800 Subject: [PATCH 4/7] =?UTF-8?q?IM=E7=9A=84=E9=93=BE=E6=8E=A5=E5=92=8C?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E6=97=B6=E6=9C=BA=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?APP=E6=89=93=E5=BC=80=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E7=99=BB=E5=BD=95=EF=BC=8C=E9=93=BE=E6=8E=A5=E3=80=82=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=99=BB=E5=BD=95=E5=90=8E=E6=96=AD=E5=BC=80=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=20=E6=96=B0=E6=9C=8B=E5=8F=8B=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/interfaces/im.js | 38 +- manifest.json | 1 + pages/im/friends/index.vue | 26 +- pages/im/index.vue | 8 +- pages/user/index.vue | 993 ++++++++++++++++++++----------------- public/userAuth.js | 249 +++++----- utils/im/index.js | 28 +- 7 files changed, 728 insertions(+), 615 deletions(-) diff --git a/apis/interfaces/im.js b/apis/interfaces/im.js index b179e16..b6ff4d4 100644 --- a/apis/interfaces/im.js +++ b/apis/interfaces/im.js @@ -22,14 +22,14 @@ const getImToken = () => { url: 'im/token', }, true) } - -// 删除好友 -const deleteFriend = (targetId) => { - return request({ - method: 'DELETE', - url: 'im/friends/' + targetId, - }) -} + +// 删除好友 +const deleteFriend = (targetId) => { + return request({ + method: 'DELETE', + url: 'im/friends/' + targetId, + }) +} // 获取用户信息 const getUserInfo = (targetId) => { @@ -37,9 +37,9 @@ const getUserInfo = (targetId) => { url: 'im/userInfo/' + targetId, }) } - -/** - * 查看好友资料,附带好友关系 + +/** + * 查看好友资料,附带好友关系 */ const getFriendInfo = (userId) => { return request({ @@ -84,16 +84,26 @@ const pedingFriend = (recipient) => { url: 'im/friends/' + recipient }) } + +/** + * 好友申请数量 + */ +const getPendingCount = () => { + return request({ + url: 'im/friends/pending/count' + }) +} export { - getImToken, + getImToken, deleteFriend, getFriends, - getUserInfo, + getUserInfo, getFriendInfo, getPedings, resolveFriend, rejectFriend, searchFriend, - pedingFriend + pedingFriend, + getPendingCount } diff --git a/manifest.json b/manifest.json index c09ce08..c681adb 100644 --- a/manifest.json +++ b/manifest.json @@ -32,6 +32,7 @@ "", "", "", + "", "", "", "", diff --git a/pages/im/friends/index.vue b/pages/im/friends/index.vue index 1811ed5..db6c55e 100644 --- a/pages/im/friends/index.vue +++ b/pages/im/friends/index.vue @@ -4,7 +4,9 @@ - 新的朋友 + + 新的朋友 ({{ pendingCount }}) + @@ -22,7 +24,8 @@ - import { - getFriends + getFriends, + getPendingCount } from '@/apis/interfaces/im'; + export default { data() { return { indexs: [], - friends: [] + friends: [], + pendingCount: 0 }; }, onShow() { getFriends().then(res => { - this.indexs = res.indexList; - this.friends = res.itemArr; - }); + this.indexs = res.indexList + this.friends = res.itemArr + }) + getPendingCount().then(res => { + console.log(res); + this.pendingCount = res + }) }, - computed: {}, methods: { - // 扫码提示 showToast() { uni.showToast({ title: '群聊功能暂未开放,敬请期待', diff --git a/pages/im/index.vue b/pages/im/index.vue index 4be35a2..f6a32be 100644 --- a/pages/im/index.vue +++ b/pages/im/index.vue @@ -102,12 +102,8 @@ } }, onShow() { - if (this.$store.state.token !== '') { - getImToken().then(res => { - im.connect(res.token, res.userInfo, () => { - this.getConversationList() - }) - }) + if (this.$store.state.token !== '') { + this.getConversationList() } this.isShown = true }, diff --git a/pages/user/index.vue b/pages/user/index.vue index 84a04f2..91ff793 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -1,472 +1,531 @@ -