1 Star 0 Fork 0

gtfhao/websdk-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
init-muti.js 2.72 KB
一键复制 编辑 原始数据 按行查看 历史
薛争锋 提交于 2017-08-11 12:43 . 支持多次回调队列
function initMuti(callbacks, appInfo, modules){
window.RongIM = window.RongIM || {};
RongIM.appInfo = RongIM.appInfo || appInfo;
//缓存消息回调队列
onMessageList = window.onMessageList || [];
onMessageList.push(callbacks.onMessage);
//缓存状态队列
onConnectList = window.onConnectList || [];
onConnectList.push(callbacks.onConnect);
modules = modules || {};
var RongIMLib = modules.RongIMLib || window.RongIMLib;
var RongIMClient = RongIMLib.RongIMClient;
if(RongIM.ready){
callbacks.onReady && callbacks.onReady(RongIM.instance);
callbacks.onConnect && callbacks.onConnect(RongIM.userInfo);
return;
}else{
var appInfo = RongIM.appInfo;
var appKey = appInfo.appKey;
var token = appInfo.token;
var navi = appInfo.navi || "";
var protobuf = modules.protobuf || null;
var config = {};
//私有云
if(navi !== ""){
config.navi = navi;
}
//support protobuf url + module
if(protobuf != null){
config.protobuf = protobuf;
};
RongIMLib.RongIMClient.init(appKey,null,config);
//开始链接
RongIMClient.connect(token, {
onSuccess: function(userId) {
RongIM.ready = true;
RongIM.userInfo = {
data : {userId: userId},
status : "ok",
info : "链接成功"
};
for(var i = 0, len = onConnectList.length; i<len; i++){
onConnectList[i](RongIM.userInfo);
}
},
onTokenIncorrect: function() {
// console.log('token无效');
RongIM.ready = false;
RongIM.userInfo = {
data : {},
status : "fail",
info : "token无效"
};
for(var i = 0, len = onConnectList.length; i<len; i++){
onConnectList[i](userInfo);
}
},
onError:function(errorCode){
// console.log("connect error");
// console.log(errorCode);
RongIM.ready = false;
RongIM.userInfo = {
data : {},
status : "fail",
info : errorCode
};
for(var i = 0, len = onConnectList.length; i<len; i++){
onConnectList[i](userInfo);
}
}
});
}
// 连接状态监听器
RongIMClient.setConnectionStatusListener({
onChanged: function (status) {
// console.log(status);
switch (status) {
case RongIMLib.ConnectionStatus.CONNECTED:
RongIM.instance = RongIMClient.getInstance();
callbacks.onReady && callbacks.onReady(RongIM.instance);
break;
}
}
});
RongIMClient.setOnReceiveMessageListener({
// 接收到的消息
onReceived: function (message) {
// 判断消息类型
// console.log("新消息: " + message.targetId);
// console.log(message);
for(var i = 0, len = onMessageList.length; i<len; i++){
onMessageList[i](message);
}
}
});
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gtfhao/websdk-demo.git
git@gitee.com:gtfhao/websdk-demo.git
gtfhao
websdk-demo
websdk-demo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385