Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/easemob/web-im
Browse files Browse the repository at this point in the history
  • Loading branch information
clock committed Jun 26, 2017
2 parents 6db5164 + f18c688 commit ad6f949
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
4 changes: 2 additions & 2 deletions demo/javascript/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ module.exports = {
Demo.api.NotifyError("logout:" + msg);
});
} else {
window.history.pushState({}, 0, 'index.html');
window.location.href = '#';
Demo.conn.close('logout');
if (type == WebIM.statusCode.WEBIM_CONNCTION_CLIENT_LOGOUT) {
Demo.conn.errorType = type;
Expand Down Expand Up @@ -321,7 +321,7 @@ module.exports = {
for (var i in Demo.chatRecord[targetId].messages) {
if (Demo.chatRecord[targetId].messages[i] == undefined)
continue;
if(!Demo.chatRecord[targetId].messages[i].read){
if (!Demo.chatRecord[targetId].messages[i].read) {
Demo.api.appendMsg(Demo.chatRecord[targetId].messages[i].message,
Demo.chatRecord[targetId].messages[i].type,
Demo.chatRecord[targetId].messages[i].status,
Expand Down
8 changes: 4 additions & 4 deletions demo/javascript/src/components/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = React.createClass({
getInitialState: function () {
var me = this;

var uri = WebIM.utils.parseUri();
var uri = WebIM.utils.parseHrefHash();
var curNode = uri.curNode;
var windows = [];
if (curNode) {
Expand Down 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.history.pushState({}, 0, 'index.html');
window.location.href = '#'
Demo.api.NotifySuccess(text);
} else {
Demo.api.NotifyError('onError:' + text);
Expand Down Expand Up @@ -944,9 +944,9 @@ module.exports = React.createClass({
},

updateNode: function (cid) {
var uri = WebIM.utils.parseUri();
var uri = WebIM.utils.parseHrefHash();
var username = uri.username;
window.history.pushState({}, 0, 'index.html?username=' + username + '&curNode=' + cid);
window.location.href = '#username=' + username + '&curNode=' + cid;
Demo.chatState[Demo.selectedCate].selected = cid;
this.storeChatWindow();
this.setChatWindow(true);
Expand Down
12 changes: 5 additions & 7 deletions demo/javascript/src/components/sign/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ module.exports = React.createClass({
var encryptUsername = btoa(username);
encryptUsername = encryptUsername.replace(/=*$/g, "");
var token = token.access_token;
var url = 'index.html?username=' + encryptUsername;
var url = '#username=' + encryptUsername;
WebIM.utils.setCookie('webim_' + encryptUsername, token, 1);
window.history.pushState({}, 0, url);
window.location.href = url
Demo.token = token;
},
error: function () {
window.history.pushState({}, 0, 'index.html');
window.location.href = '#'

}
};

Expand All @@ -104,7 +105,6 @@ module.exports = React.createClass({
if (Demo.user) {
if (Demo.user != username) {
Demo.chatRecord = {};
console.log('clearclear');
}
}

Expand Down Expand Up @@ -158,15 +158,13 @@ module.exports = React.createClass({
},

componentWillMount: function () {
var uri = WebIM.utils.parseUri();
var uri = WebIM.utils.parseHrefHash();
var username = uri.username;
var auth = WebIM.utils.getCookie()['webim_' + username];
Demo.token = auth;
if (username && auth) {
username = atob(username);
this.signin(username, auth, true);
} else {
window.history.pushState({}, 0, 'index.html');
}
},

Expand Down
24 changes: 20 additions & 4 deletions sdk/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,16 +742,32 @@
};
},

parseUri: function(){
parseUri: function () {
var pattern = /([^\?|&])\w+=([^&]+)/g;
var uri = {};
if(window.location.search){
if (window.location.search) {
var args = window.location.search.match(pattern);
for(var i in args){
for (var i in args) {
var str = args[i];
var eq = str.indexOf('=');
var key = str.substr(0, eq);
var value = str.substr(eq+1);
var value = str.substr(eq + 1);
uri[key] = value;
}
}
return uri;
},

parseHrefHash: function () {
var pattern = /([^\#|&])\w+=([^&]+)/g;
var uri = {};
if (window.location.hash) {
var args = window.location.hash.match(pattern);
for (var i in args) {
var str = args[i];
var eq = str.indexOf('=');
var key = str.substr(0, eq);
var value = str.substr(eq + 1);
uri[key] = value;
}
}
Expand Down

0 comments on commit ad6f949

Please sign in to comment.