音频通话,测试
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
|
||||
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
|
||||
import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
|
||||
import store from '@/store/index.js'
|
||||
import {
|
||||
getFriends,
|
||||
@@ -7,6 +8,7 @@ import {
|
||||
|
||||
const initIm = (KEY) => {
|
||||
RongIMLib.init(KEY)
|
||||
CallLib.init()
|
||||
addListeners()
|
||||
}
|
||||
|
||||
@@ -38,8 +40,8 @@ const setNotifyBadge = () => {
|
||||
*/
|
||||
const connect = (token, userInfo, callback) => {
|
||||
RongIMLib.connect(token, res => {
|
||||
console.log('连接结果', res);
|
||||
|
||||
console.log('连接结果', res);
|
||||
|
||||
callback(res)
|
||||
})
|
||||
|
||||
@@ -58,23 +60,23 @@ const connect = (token, userInfo, callback) => {
|
||||
|
||||
const disconnect = () => {
|
||||
RongIMLib.disconnect()
|
||||
}
|
||||
|
||||
// 允许通知的消息类型,触发更新消息列表操作
|
||||
const notifyMsgTypes = [
|
||||
'RC:TxtMsg',
|
||||
'RC:VcMsg',
|
||||
'RC:HQVCMsg',
|
||||
'RC:ImgMsg',
|
||||
'RC:GIFMsg',
|
||||
'RC:ImgTextMsg',
|
||||
'RC:FileMsg',
|
||||
'RC:LBSMsg',
|
||||
'RC:SightMsg',
|
||||
'RC:ReferenceMsg',
|
||||
'RC:CombineMsg',
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
// 允许通知的消息类型,触发更新消息列表操作
|
||||
const notifyMsgTypes = [
|
||||
'RC:TxtMsg',
|
||||
'RC:VcMsg',
|
||||
'RC:HQVCMsg',
|
||||
'RC:ImgMsg',
|
||||
'RC:GIFMsg',
|
||||
'RC:ImgTextMsg',
|
||||
'RC:FileMsg',
|
||||
'RC:LBSMsg',
|
||||
'RC:SightMsg',
|
||||
'RC:ReferenceMsg',
|
||||
'RC:CombineMsg',
|
||||
]
|
||||
|
||||
function inArray(search, array) {
|
||||
for (var i in array) {
|
||||
if (array[i] == search) {
|
||||
@@ -82,22 +84,51 @@ function inArray(search, array) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const addListeners = () => {
|
||||
// 添加连接状态监听函数
|
||||
RongIMLib.addConnectionStatusListener((res) => {
|
||||
console.log('连接状态监', res.data.status);
|
||||
console.log('连接状态监', res.data.status);
|
||||
store.dispatch('updateConnectionStatus', res.data.status)
|
||||
})
|
||||
// 添加消息监听函数
|
||||
RongIMLib.addReceiveMessageListener((res) => {
|
||||
console.log('收到消息', res.data.message);
|
||||
const message = res.data.message
|
||||
if (inArray(message.objectName, notifyMsgTypes)) {
|
||||
newMessage(message)
|
||||
console.log('收到消息', res.data.message);
|
||||
const message = res.data.message
|
||||
if (inArray(message.objectName, notifyMsgTypes)) {
|
||||
newMessage(message)
|
||||
}
|
||||
})
|
||||
// 监听通话呼入
|
||||
CallLib.onCallReceived((res) => {
|
||||
console.log("Engine:OnCallReceived=>" + "监听通话呼入, 目标id=>", res.data.targetId);
|
||||
console.log('RES', res);
|
||||
uni.navigateTo({
|
||||
url: '/pages/im/private/call?targetId=' + res.data.targetId,
|
||||
success: (err) => {
|
||||
console.log('跳转视频通话成功');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('跳转视频页失败', err);
|
||||
}
|
||||
})
|
||||
})
|
||||
CallLib.onCallOutgoing((res) => {
|
||||
console.log("主叫端拨出电话后,通过回调 onCallOutgoing,通知当前 call 的详细信息", res)
|
||||
})
|
||||
CallLib.onCallConnected((res) => {
|
||||
console.log("Engine:OnCallConnected=>" + "通话接通时,通过回调 onCallConnected 通知当前 call 的详细信息", res)
|
||||
});
|
||||
CallLib.onRemoteUserJoined((res) => {
|
||||
console.log("Engine:OnRemoteUserJoined=>" + "主叫端拨出电话,被叫端收到请求后,加入通话,被叫端Id为=>", res.data.userId);
|
||||
})
|
||||
CallLib.onCallDisconnected((res) => {
|
||||
console.log("Engine:OnCallDisconnected=>" + "挂断成功, 挂断原因=>", res.data.reason)
|
||||
})
|
||||
CallLib.onRemoteUserLeft((res) => {
|
||||
console.log("Engine:OnRemoteUserLeft=>" + "远端用户挂断,远端Id为=>", res.data.reason)
|
||||
})
|
||||
}
|
||||
|
||||
// 维护消息列表
|
||||
@@ -194,6 +225,6 @@ export default {
|
||||
connect,
|
||||
sendMsg,
|
||||
setNotifyBadge,
|
||||
syncFriends,
|
||||
syncFriends,
|
||||
syncUserInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user