MessageReceiver accepts a server websocket url

// FREEBIE
This commit is contained in:
lilia 2015-07-23 15:41:17 -07:00
parent fd5b0aeb85
commit 1f8856fa69
5 changed files with 30 additions and 42 deletions

View file

@ -124,7 +124,7 @@ module.exports = function(grunt) {
files: [{ expand: true, dest: 'dist/', src: ['<%= dist.src %>'] }], files: [{ expand: true, dest: 'dist/', src: ['<%= dist.src %>'] }],
options: { options: {
process: function(content, srcpath) { process: function(content, srcpath) {
if (srcpath.match('libtextsecure')) { if (srcpath.match('libtextsecure') || srcpath.match('background.js')) {
return content.replace( return content.replace(
/textsecure-service-staging.whispersystems.org/g, /textsecure-service-staging.whispersystems.org/g,
'textsecure-service-ca.whispersystems.org:4433').replace( 'textsecure-service-ca.whispersystems.org:4433').replace(

View file

@ -60,7 +60,7 @@
if (!textsecure.registration.isDone()) { return; } if (!textsecure.registration.isDone()) { return; }
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(window); messageReceiver = new textsecure.MessageReceiver('wss://textsecure-service-staging.whispersystems.org', window);
} }
function onContactReceived(ev) { function onContactReceived(ev) {

View file

@ -39256,23 +39256,17 @@ TextSecureServer = function () {
}); });
}; };
var getWebsocket = function(url, auth, reconnectTimeout) { self.getMessageWebsocket = function(url) {
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?'; var user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId();
var params = ''; var password = textsecure.storage.get("password");
if (auth) { var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
var user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId(); var url = url + URL_CALLS['push'] + '/?' + params;
var password = textsecure.storage.get("password"); return TextSecureWebSocket(url)
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
}
return TextSecureWebSocket(URL+params)
}
self.getMessageWebsocket = function() {
return getWebsocket(URL_CALLS['push'], true, 1000);
} }
self.getTempWebsocket = function() { self.getTempWebsocket = function() {
return getWebsocket(URL_CALLS['temp_push'], false, 1000); var url = URL_BASE.replace(/^http/g, 'ws') + URL_CALLS['temp_push'] + '/?';
return TextSecureWebSocket(url);
} }
return self; return self;
@ -39473,21 +39467,21 @@ function generateKeys(count, progressCallback) {
'use strict'; 'use strict';
window.textsecure = window.textsecure || {}; window.textsecure = window.textsecure || {};
function MessageReceiver(eventTarget) { function MessageReceiver(url, eventTarget) {
if (eventTarget instanceof EventTarget) { if (eventTarget instanceof EventTarget) {
this.target = eventTarget; this.target = eventTarget;
} else { } else {
throw new TypeError('MessageReceiver expected an EventTarget'); throw new TypeError('MessageReceiver expected an EventTarget');
} }
this.connect(); this.connect(url);
} }
MessageReceiver.prototype = { MessageReceiver.prototype = {
constructor: MessageReceiver, constructor: MessageReceiver,
connect: function() { connect: function(url) {
var eventTarget = this.target; var eventTarget = this.target;
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
this.socket = TextSecureServer.getMessageWebsocket(); this.socket = TextSecureServer.getMessageWebsocket(url);
this.socket.onclose = function(e) { this.socket.onclose = function(e) {
if (e.code === 1006) { if (e.code === 1006) {
// possible 403. Make an request to confirm // possible 403. Make an request to confirm
@ -39689,8 +39683,8 @@ function generateKeys(count, progressCallback) {
} }
}; };
textsecure.MessageReceiver = function (eventTarget) { textsecure.MessageReceiver = function (url, eventTarget) {
var messageReceiver = new MessageReceiver(eventTarget); var messageReceiver = new MessageReceiver(url, eventTarget);
this.getStatus = function() { this.getStatus = function() {
return messageReceiver.getStatus(); return messageReceiver.getStatus();
} }

View file

@ -319,23 +319,17 @@ TextSecureServer = function () {
}); });
}; };
var getWebsocket = function(url, auth, reconnectTimeout) { self.getMessageWebsocket = function(url) {
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?'; var user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId();
var params = ''; var password = textsecure.storage.get("password");
if (auth) { var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
var user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId(); var url = url + URL_CALLS['push'] + '/?' + params;
var password = textsecure.storage.get("password"); return TextSecureWebSocket(url)
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
}
return TextSecureWebSocket(URL+params)
}
self.getMessageWebsocket = function() {
return getWebsocket(URL_CALLS['push'], true, 1000);
} }
self.getTempWebsocket = function() { self.getTempWebsocket = function() {
return getWebsocket(URL_CALLS['temp_push'], false, 1000); var url = URL_BASE.replace(/^http/g, 'ws') + URL_CALLS['temp_push'] + '/?';
return TextSecureWebSocket(url);
} }
return self; return self;

View file

@ -18,21 +18,21 @@
'use strict'; 'use strict';
window.textsecure = window.textsecure || {}; window.textsecure = window.textsecure || {};
function MessageReceiver(eventTarget) { function MessageReceiver(url, eventTarget) {
if (eventTarget instanceof EventTarget) { if (eventTarget instanceof EventTarget) {
this.target = eventTarget; this.target = eventTarget;
} else { } else {
throw new TypeError('MessageReceiver expected an EventTarget'); throw new TypeError('MessageReceiver expected an EventTarget');
} }
this.connect(); this.connect(url);
} }
MessageReceiver.prototype = { MessageReceiver.prototype = {
constructor: MessageReceiver, constructor: MessageReceiver,
connect: function() { connect: function(url) {
var eventTarget = this.target; var eventTarget = this.target;
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
this.socket = TextSecureServer.getMessageWebsocket(); this.socket = TextSecureServer.getMessageWebsocket(url);
this.socket.onclose = function(e) { this.socket.onclose = function(e) {
if (e.code === 1006) { if (e.code === 1006) {
// possible 403. Make an request to confirm // possible 403. Make an request to confirm
@ -234,8 +234,8 @@
} }
}; };
textsecure.MessageReceiver = function (eventTarget) { textsecure.MessageReceiver = function (url, eventTarget) {
var messageReceiver = new MessageReceiver(eventTarget); var messageReceiver = new MessageReceiver(url, eventTarget);
this.getStatus = function() { this.getStatus = function() {
return messageReceiver.getStatus(); return messageReceiver.getStatus();
} }