Skip to content

Commit

Permalink
用户在离线状态下发送消息,会自动重连并将未成功发送的消息发送出去
Browse files Browse the repository at this point in the history
  • Loading branch information
clock committed Jul 14, 2017
1 parent 944ef79 commit c9ec038
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion demo/javascript/src/components/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ module.exports = React.createClass({
} else {
if (text == 'logout' || text == 'WEBIM_CONNCTION_SERVER_ERROR type=8') {
text = Demo.lan.logoutSuc;
window.location.href = '#'
window.location.href = '#';
Demo.api.NotifySuccess(text);
} else {
Demo.api.NotifyError('onError:' + text);
Expand Down
22 changes: 11 additions & 11 deletions demo/javascript/src/components/sign/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ module.exports = React.createClass({
};
if (WebIM.config.isWindowSDK) {
var appDir = "";
if(WebIM.config.appDir){
if (WebIM.config.appDir) {
appDir = WebIM.config.appDir;
}
var imIP = "";
if(WebIM.config.imIP){
if (WebIM.config.imIP) {
imIP = WebIM.config.imIP;
}
var imPort = "";
if(WebIM.config.imPort){
if (WebIM.config.imPort) {
imPort = WebIM.config.imPort;
}
var restIPandPort = "";
if(WebIM.config.restIPandPort){
if (WebIM.config.restIPandPort) {
restIPandPort = WebIM.config.restIPandPort;
}
WebIM.doQuery('{"type":"createAccount","id":"' + options.username + '","password":"' + options.password
WebIM.doQuery('{"type":"createAccount","id":"' + options.username + '","password":"' + options.password
+ '","appDir":"' + appDir + '","appKey":"' + WebIM.config.appkey + '","imIP":"' + imIP + '","imPort":"' + imPort + '","restIPandPort":"' + restIPandPort + '"}', function (response) {
options.success();
},
function (code, msg) {
me.submiting = false;
alert("registerUser:" + code + " - " + msg);
});
options.success();
},
function (code, msg) {
me.submiting = false;
alert("registerUser:" + code + " - " + msg);
});
} else {
Demo.conn.registerUser(options);
}
Expand Down
1 change: 0 additions & 1 deletion demo/javascript/src/components/webim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var Loading = require('./common/loading');

module.exports = React.createClass({
getInitialState: function () {

return {
signIn: true,
signUp: false,
Expand Down
36 changes: 32 additions & 4 deletions sdk/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,21 @@ var _loginCallback = function (status, msg, conn) {
conn.retry && _handleMessageQueue(conn);
conn.heartBeat();
conn.isAutoLogin && conn.setPresence();

try{
if(conn.unSendMsgArr.length > 0){
for(var i in conn.unSendMsgArr){
var dom = conn.unSendMsgArr[i];
conn.sendCommand(dom);
delete conn.unSendMsgArr[i];
}
}
}catch(e){
console.error(e.message);
}
conn.offLineSendConnecting = false;
conn.logOut = false;

conn.onOpened({
canReceive: supportRecMessage,
canSend: supportSedMessage,
Expand Down Expand Up @@ -679,6 +694,9 @@ var connection = function (options) {
this.orgName = '';
this.appName = '';
this.token = '';
this.unSendMsgArr = [];
this.offLineSendConnecting = false;
this.logOut = false;

this.dnsArr = ['https://rs.easemob.com', 'https://rsbak.easemob.com', 'http://182.92.174.78', 'http://112.126.66.111']; //http dns server hosts
this.dnsIndex = 0; //the dns ip used in dnsArr currently
Expand Down Expand Up @@ -1116,6 +1134,7 @@ connection.prototype.attach = function (options) {
};

connection.prototype.close = function (reason) {
this.logOut = true;
this.stopHeartBeat();

var status = this.context.status;
Expand Down Expand Up @@ -1819,6 +1838,11 @@ connection.prototype.sendCommand = function (dom, id) {
if (this.isOpened()) {
this.context.stropheConn.send(dom);
} else {
this.unSendMsgArr.push(dom);
if(!this.offLineSendConnecting && !this.logOut){
this.offLineSendConnecting = true;
this.reconnect();
}
this.onError({
type: _code.WEBIM_CONNCTION_DISCONNECTED,
reconnect: true
Expand Down Expand Up @@ -2282,10 +2306,14 @@ connection.prototype.isClosed = function () {
connection.prototype.clear = function () {
var key = this.context.appKey;
if (this.errorType != _code.WEBIM_CONNCTION_DISCONNECTED) {
this.context = {
status: _code.STATUS_INIT,
appKey: key
};
if(this.logOut){
this.unSendMsgArr = [];
this.offLineSendConnecting = false;
this.context = {
status: _code.STATUS_INIT,
appKey: key
};
}
}
if (this.intervalId) {
clearInterval(this.intervalId);
Expand Down

0 comments on commit c9ec038

Please sign in to comment.