From ed3aa9667d2e5feeb267c2599da6975bd7c18421 Mon Sep 17 00:00:00 2001 From: lilia Date: Sat, 17 May 2014 13:56:08 -0700 Subject: [PATCH] Fix undefined URL_BASE in background.js Sieze an opportunity to move code out of the helpers.js. Only 616 more lines to go. --- js/api.js | 11 +++++++++++ js/helpers.js | 5 +---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/js/api.js b/js/api.js index 5773a76c4..21eb4686d 100644 --- a/js/api.js +++ b/js/api.js @@ -222,5 +222,16 @@ window.textsecure.api = function() { }); }; + self.getWebsocket = function() { + var user = storage.getUnencrypted("number_id"); + var password = storage.getEncrypted("password"); + var URL = URL_BASE.replace(/^http/g, 'ws') + URL_CALLS['push'] + '/?'; + var params = $.param({ + user: '+' + getString(user).substring(1), + password: getString(password) + }); + return new WebSocket(URL+params); + } + return self; }(); diff --git a/js/helpers.js b/js/helpers.js index 584b19488..9e004ec61 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -440,10 +440,7 @@ window.textsecure.subscribeToPush = function() { if (subscribeToPushMessageSemaphore <= 0) return; - var user = storage.getUnencrypted("number_id"); - var password = storage.getEncrypted("password"); - var URL = URL_BASE.replace(/^http:/g, "ws:").replace(/^https:/g, "wss:") + URL_CALLS['push'] + "/?user=%2B" + getString(user).substring(1) + "&password=" + getString(password); - var socket = new WebSocket(URL); + var socket = textsecure.api.getWebsocket(); var pingInterval;