|
|
|
@ -37474,6 +37474,18 @@ window.textsecure.utils = function() {
|
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function PortManager(ports) {
|
|
|
|
|
this.ports = ports;
|
|
|
|
|
this.idx = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PortManager.prototype = {
|
|
|
|
|
constructor: PortManager,
|
|
|
|
|
getPort: function() {
|
|
|
|
|
return this.ports[this.idx++];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var TextSecureServer = (function() {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
@ -37499,6 +37511,9 @@ var TextSecureServer = (function() {
|
|
|
|
|
// Promise-based async xhr routine
|
|
|
|
|
function promise_ajax(url, options) {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
if (!url) {
|
|
|
|
|
url = options.host + ':' + options.port + '/' + options.path;
|
|
|
|
|
}
|
|
|
|
|
console.log(options.type, url);
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open(options.type, url, true /*async*/);
|
|
|
|
@ -37546,24 +37561,29 @@ var TextSecureServer = (function() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ajax(url, options) {
|
|
|
|
|
options.stack = new Error().stack; // just in case, save stack here.
|
|
|
|
|
var count = 3;
|
|
|
|
|
|
|
|
|
|
function retry(e) {
|
|
|
|
|
if (e.name === 'HTTPError' && e.code === -1 && count > 0) {
|
|
|
|
|
count = count - 1;
|
|
|
|
|
function retry_ajax(url, options, limit, count) {
|
|
|
|
|
count = count || 0;
|
|
|
|
|
limit = limit || 3;
|
|
|
|
|
if (options.ports) {
|
|
|
|
|
options.port = options.ports[count % options.ports.length];
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
return promise_ajax(url, options).catch(function(e) {
|
|
|
|
|
if (e.name === 'HTTPError' && e.code === -1 && count < limit) {
|
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
resolve(promise_ajax(url, options).catch(retry));
|
|
|
|
|
}, 1000 );
|
|
|
|
|
resolve(retry_ajax(url, options, limit, count));
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return promise_ajax(url, options).catch(retry);
|
|
|
|
|
function ajax(url, options) {
|
|
|
|
|
options.stack = new Error().stack; // just in case, save stack here.
|
|
|
|
|
return retry_ajax(url, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function HTTPError(code, response, stack) {
|
|
|
|
@ -37581,17 +37601,18 @@ var TextSecureServer = (function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var URL_CALLS = {
|
|
|
|
|
accounts : "/v1/accounts",
|
|
|
|
|
devices : "/v1/devices",
|
|
|
|
|
keys : "/v2/keys",
|
|
|
|
|
messages : "/v1/messages",
|
|
|
|
|
attachment : "/v1/attachments"
|
|
|
|
|
accounts : "v1/accounts",
|
|
|
|
|
devices : "v1/devices",
|
|
|
|
|
keys : "v2/keys",
|
|
|
|
|
messages : "v1/messages",
|
|
|
|
|
attachment : "v1/attachments"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function TextSecureServer(url, username, password, attachment_server_url) {
|
|
|
|
|
function TextSecureServer(url, ports, username, password, attachment_server_url) {
|
|
|
|
|
if (typeof url !== 'string') {
|
|
|
|
|
throw new Error('Invalid server url');
|
|
|
|
|
}
|
|
|
|
|
this.portManager = new PortManager(ports);
|
|
|
|
|
this.url = url;
|
|
|
|
|
this.username = username;
|
|
|
|
|
this.password = password;
|
|
|
|
@ -37610,11 +37631,17 @@ var TextSecureServer = (function() {
|
|
|
|
|
|
|
|
|
|
TextSecureServer.prototype = {
|
|
|
|
|
constructor: TextSecureServer,
|
|
|
|
|
getUrl: function() {
|
|
|
|
|
return this.url + ':' + this.portManager.getPort();
|
|
|
|
|
},
|
|
|
|
|
ajax: function(param) {
|
|
|
|
|
if (!param.urlParameters) {
|
|
|
|
|
param.urlParameters = '';
|
|
|
|
|
}
|
|
|
|
|
return ajax(this.url + URL_CALLS[param.call] + param.urlParameters, {
|
|
|
|
|
return ajax(null, {
|
|
|
|
|
host : this.url,
|
|
|
|
|
ports : this.portManager.ports,
|
|
|
|
|
path : URL_CALLS[param.call] + param.urlParameters,
|
|
|
|
|
type : param.httpType,
|
|
|
|
|
data : param.jsonData && textsecure.utils.jsonThing(param.jsonData),
|
|
|
|
|
contentType : 'application/json; charset=utf-8',
|
|
|
|
@ -37823,7 +37850,7 @@ var TextSecureServer = (function() {
|
|
|
|
|
},
|
|
|
|
|
getMessageSocket: function() {
|
|
|
|
|
return new WebSocket(
|
|
|
|
|
this.url.replace('https://', 'wss://')
|
|
|
|
|
this.getUrl().replace('https://', 'wss://')
|
|
|
|
|
.replace('http://', 'ws://')
|
|
|
|
|
+ '/v1/websocket/?login=' + encodeURIComponent(this.username)
|
|
|
|
|
+ '&password=' + encodeURIComponent(this.password)
|
|
|
|
@ -37833,7 +37860,7 @@ var TextSecureServer = (function() {
|
|
|
|
|
getProvisioningSocket: function () {
|
|
|
|
|
console.log('opening provisioning socket', this.url);
|
|
|
|
|
return new WebSocket(
|
|
|
|
|
this.url.replace('https://', 'wss://')
|
|
|
|
|
this.getUrl().replace('https://', 'wss://')
|
|
|
|
|
.replace('http://', 'ws://')
|
|
|
|
|
+ '/v1/websocket/provisioning/?agent=OWD'
|
|
|
|
|
);
|
|
|
|
@ -37852,8 +37879,8 @@ var TextSecureServer = (function() {
|
|
|
|
|
'use strict';
|
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
|
|
|
|
|
|
function AccountManager(url, username, password) {
|
|
|
|
|
this.server = new TextSecureServer(url, username, password);
|
|
|
|
|
function AccountManager(url, ports, username, password) {
|
|
|
|
|
this.server = new TextSecureServer(url, ports, username, password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccountManager.prototype = {
|
|
|
|
@ -38032,12 +38059,12 @@ var TextSecureServer = (function() {
|
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function MessageReceiver(url, username, password, signalingKey, attachment_server_url) {
|
|
|
|
|
function MessageReceiver(url, ports, username, password, signalingKey, attachment_server_url) {
|
|
|
|
|
this.url = url;
|
|
|
|
|
this.signalingKey = signalingKey;
|
|
|
|
|
this.username = username;
|
|
|
|
|
this.password = password;
|
|
|
|
|
this.server = new TextSecureServer(url, username, password, attachment_server_url);
|
|
|
|
|
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
|
|
|
|
|
|
|
|
|
var address = libsignal.SignalProtocolAddress.fromString(username);
|
|
|
|
|
this.number = address.getName();
|
|
|
|
@ -38502,8 +38529,8 @@ MessageReceiver.prototype.extend({
|
|
|
|
|
|
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
|
|
|
|
|
|
textsecure.MessageReceiver = function(url, username, password, signalingKey, attachment_server_url) {
|
|
|
|
|
var messageReceiver = new MessageReceiver(url, username, password, signalingKey, attachment_server_url);
|
|
|
|
|
textsecure.MessageReceiver = function(url, ports, username, password, signalingKey, attachment_server_url) {
|
|
|
|
|
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey, attachment_server_url);
|
|
|
|
|
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
|
|
|
|
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
|
|
|
|
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
|
|
|
@ -38835,8 +38862,8 @@ Message.prototype = {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function MessageSender(url, username, password, attachment_server_url) {
|
|
|
|
|
this.server = new TextSecureServer(url, username, password, attachment_server_url);
|
|
|
|
|
function MessageSender(url, ports, username, password, attachment_server_url) {
|
|
|
|
|
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
|
|
|
|
this.pendingMessages = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -39187,8 +39214,8 @@ MessageSender.prototype = {
|
|
|
|
|
|
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
|
|
|
|
|
|
textsecure.MessageSender = function(url, username, password, attachment_server_url) {
|
|
|
|
|
var sender = new MessageSender(url, username, password, attachment_server_url);
|
|
|
|
|
textsecure.MessageSender = function(url, ports, username, password, attachment_server_url) {
|
|
|
|
|
var sender = new MessageSender(url, ports, username, password, attachment_server_url);
|
|
|
|
|
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.ENCRYPT_MESSAGE);
|
|
|
|
|
textsecure.replay.registerFunction(sender.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
|
|
|
|
|
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
|
|
|
|
|