Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/easemob/web-im into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
clock committed Sep 12, 2017
2 parents 59f6af4 + 6577907 commit 824a340
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 56 deletions.
2 changes: 1 addition & 1 deletion demo/javascript/dist/webim.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ WebIM.config = {
* true: A visitor can sign in to multiple webpages and receive messages at all the webpages.
* false: A visitor can sign in to only one webpage and receive messages at the webpage.
*/
isMultiLoginSessions: false,
isMultiLoginSessions: true,
/*
* set presence after login
*/
Expand Down
52 changes: 1 addition & 51 deletions demo/javascript/src/components/sign/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,6 @@ module.exports = React.createClass({
};
},

validTabs: function () {
if (!WebIM.config.isMultiLoginSessions || !window.localStorage) {
return true;
} else {
Demo.userTimestamp = new Date().getTime();

var key = 'easemob_' + Demo.user;
var val = window.localStorage.getItem(key);
var count = 0;
var oneMinute = 60 * 1000;

if (val === undefined || val === '' || val === null) {
val = 'last';
}
val = Demo.userTimestamp + ',' + val;
var timestampArr = val.split(',');
var uniqueTimestampArr = [];
// Unique

for (var o in timestampArr) {
if (timestampArr[o] === 'last')
continue;
uniqueTimestampArr[timestampArr[o]] = 1;
}

val = 'last';
for (var o in uniqueTimestampArr) {
// if more than one minute, cut it
if (parseInt(o) + oneMinute < Demo.userTimestamp) {
continue;
}
count++;
if (count > this.state.pageLimit) {
return false;
}
val = o + ',' + val;
}
window.localStorage.setItem(key, val);
return true;
}
},

keyDown: function (e) {
if (e && e.keyCode === 13) {
this.login();
Expand Down Expand Up @@ -137,15 +95,7 @@ module.exports = React.createClass({
Demo.api.NotifyError('open:' + code + " - " + msg);
});
} else {
if (this.validTabs() === true) {
Demo.conn.open(options);
}
else {
Demo.conn.onError({
type: "One account can't open more than " + this.state.pageLimit + ' pages in one minute on the same browser'
});
return;
}
Demo.conn.open(options);
}
},

Expand Down
63 changes: 59 additions & 4 deletions sdk/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,62 @@ if (window.XDomainRequest) {
// };
}

Strophe.Connection.prototype._sasl_auth1_cb = function (elem) {
// save stream:features for future usage
this.features = elem;
var i, child;
for (i = 0; i < elem.childNodes.length; i++) {
child = elem.childNodes[i];
if (child.nodeName == 'bind') {
this.do_bind = true;
}

if (child.nodeName == 'session') {
this.do_session = true;
}
}

if (!this.do_bind) {
this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
return false;
} else {
this._addSysHandler(this._sasl_bind_cb.bind(this), null, null,
null, "_bind_auth_2");

var resource = Strophe.getResourceFromJid(this.jid);
if (resource) {
// this.send($iq({type: "set", id: "_bind_auth_2"})
// .c('bind', {xmlns: Strophe.NS.BIND})
// .c('resource', {}).t(resource).tree());
var device_uuid = "device_uuid";
if (this.options.isMultiLoginSessions) {
device_uuid = new Date().getTime() + Math.floor(Math.random().toFixed(6) * 1000000)
}
try {
this.send(
$iq({type: "set", id: "_bind_auth_2"})
.c('bind', {xmlns: Strophe.NS.BIND})
.c('resource', {}).t(resource)
.up()
.c('os').t('webim')
.up()
.c('device_uuid').t(device_uuid)
.up()
.c('is_manual_login').t('true')
.tree()
);
} catch (e) {
console.log("Bind Error: ", e.message);
}
} else {
this.send($iq({type: "set", id: "_bind_auth_2"})
.c('bind', {xmlns: Strophe.NS.BIND})
.tree());
}
}
return false;
};

Strophe.Request.prototype._newXHR = function () {
var xhr = _utils.xmlrequest(true);
if (xhr.overrideMimeType) {
Expand Down Expand Up @@ -323,7 +379,7 @@ var _login = function (options, conn) {
conn.context.accessToken = options.access_token;
conn.context.accessTokenExpires = options.expires_in;
if (conn.isOpening() && conn.context.stropheConn) {
stropheConn = conn.context.stropheConn;
stropheConn = conn.getStrophe();
} else if (conn.isOpened() && conn.context.stropheConn) {
// return;
stropheConn = conn.getStrophe();
Expand Down Expand Up @@ -626,9 +682,7 @@ var _validCheck = function (options, conn) {
var jid = appKey + '_' + user.toLowerCase() + '@' + conn.domain,
resource = options.resource || 'webim';

if (conn.isMultiLoginSessions) {
resource += user + new Date().getTime() + Math.floor(Math.random().toFixed(6) * 1000000);
}

conn.context.jid = jid + '/' + resource;
conn.context.userId = user;
conn.context.appKey = appKey;
Expand Down Expand Up @@ -1033,6 +1087,7 @@ connection.prototype.getStrophe = function () {
}

var stropheConn = new Strophe.Connection(this.url, {
isMultiLoginSessions: this.isMultiLoginSessions,
inactivity: this.inactivity,
maxRetries: this.maxRetries,
pollingTime: this.pollingTime
Expand Down

0 comments on commit 824a340

Please sign in to comment.