加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
im.js 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
yanhan 提交于 2020-07-20 19:34 . feat: web-call-quickstart
function reconnect() {
var callback = {
onSuccess: function (userId) {
console.log('reconnect success. ' + userId);
},
onTokenIncorrect: function () {
console.log('token 无效');
},
onError: function (errorCode) {
reconnect();
}
};
var config = {
auto: true,
url: 'cdn.ronghub.com/RongIMLib-2.2.6.min.js?d=' + Date.now(),
rate: [100, 1000, 3000, 6000, 10000]
};
RongIMClient.reconnect(callback, config);
}
function initIM(params) {
var appkey = params.appkey;
var token = params.token;
RongIMClient.init(appkey);
RongIMClient.setConnectionStatusListener({
onChanged: function (status) {
console.log('status changed', status);
switch (status) {
case RongIMLib.ConnectionStatus.CONNECTING:
break;
case RongIMLib.ConnectionStatus.DISCONNECTED:
break;
case RongIMLib.ConnectionStatus.DOMAIN_INCORRECT:
case RongIMLib.ConnectionStatus.NETWORK_UNAVAILABLE:
reconnect();
break;
}
}
});
RongIMClient.setOnReceiveMessageListener({
onReceived: function (message) {
console.log(message);
}
});
return new Promise((resolve, reject) => {
RongIMClient.connect(token, {
onSuccess: resolve,
onTokenIncorrect: reject,
onError: reject
});
});
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化