make MatrixClientPeg an actual global too otherwise things go very wierd

pull/21833/head
David Baker 2015-09-28 17:46:49 +01:00
parent 8af6c2275b
commit 9fb5702c2f
1 changed files with 13 additions and 9 deletions

View File

@ -59,23 +59,23 @@ if (localStorage) {
} }
} }
module.exports = { class MatrixClient {
get: function() { get() {
return matrixClient; return matrixClient;
}, }
unset: function() { unset() {
matrixClient = null; matrixClient = null;
}, }
replaceUsingUrls: function(hs_url, is_url) { replaceUsingUrls(hs_url, is_url) {
matrixClient = Matrix.createClient({ matrixClient = Matrix.createClient({
baseUrl: hs_url, baseUrl: hs_url,
idBaseUrl: is_url idBaseUrl: is_url
}); });
}, }
replaceUsingAccessToken: function(hs_url, is_url, user_id, access_token) { replaceUsingAccessToken(hs_url, is_url, user_id, access_token) {
if (localStorage) { if (localStorage) {
try { try {
localStorage.clear(); localStorage.clear();
@ -97,5 +97,9 @@ module.exports = {
console.warn("No local storage available: can't persist session!"); console.warn("No local storage available: can't persist session!");
} }
} }
}; }
if (!global.mxMatrixClient) {
global.mxMatrixClient = new MatrixClient();
}
module.exports = global.mxMatrixClient;