Don't hardcode the attachment server url
There may come a day when we may need to change this url from the server side. On that day, clients should continue to operate normally. The service should be able to change attachment server locations without requiring a client update. // FREEBIE
This commit is contained in:
parent
43de0cc2ec
commit
611bbaef35
6 changed files with 21 additions and 70 deletions
|
@ -125,9 +125,7 @@ module.exports = function(grunt) {
|
|||
if (srcpath.match('background.js')) {
|
||||
return content.replace(
|
||||
/textsecure-service-staging.whispersystems.org/g,
|
||||
'textsecure-service-ca.whispersystems.org').replace(
|
||||
/whispersystems-textsecure-attachments-staging.s3.amazonaws.com/g,
|
||||
'whispersystems-textsecure-attachments.s3.amazonaws.com');
|
||||
'textsecure-service-ca.whispersystems.org');
|
||||
} else if (srcpath.match('expire.js')) {
|
||||
var gitinfo = grunt.config.get('gitinfo');
|
||||
var commited = gitinfo.local.branch.current.lastCommitTime;
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
|
||||
var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org';
|
||||
var SERVER_PORTS = [80, 4433, 8443];
|
||||
var ATTACHMENT_SERVER_URL = 'https://whispersystems-textsecure-attachments-staging.s3.amazonaws.com';
|
||||
var messageReceiver;
|
||||
window.getSocketStatus = function() {
|
||||
if (messageReceiver) {
|
||||
|
@ -108,7 +107,7 @@
|
|||
|
||||
// initialize the socket and start listening for messages
|
||||
messageReceiver = new textsecure.MessageReceiver(
|
||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD, mySignalingKey, ATTACHMENT_SERVER_URL
|
||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD, mySignalingKey
|
||||
);
|
||||
messageReceiver.addEventListener('message', onMessageReceived);
|
||||
messageReceiver.addEventListener('receipt', onDeliveryReceipt);
|
||||
|
@ -119,7 +118,7 @@
|
|||
messageReceiver.addEventListener('error', onError);
|
||||
|
||||
window.textsecure.messaging = new textsecure.MessageSender(
|
||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD, ATTACHMENT_SERVER_URL
|
||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD
|
||||
);
|
||||
if (firstRun === true && textsecure.storage.user.getDeviceId() != '1') {
|
||||
if (!storage.get('theme-setting') && textsecure.storage.get('userAgent') === 'OWI') {
|
||||
|
|
|
@ -37660,7 +37660,7 @@ var TextSecureServer = (function() {
|
|||
attachment : "v1/attachments"
|
||||
};
|
||||
|
||||
function TextSecureServer(url, ports, username, password, attachment_server_url) {
|
||||
function TextSecureServer(url, ports, username, password) {
|
||||
if (typeof url !== 'string') {
|
||||
throw new Error('Invalid server url');
|
||||
}
|
||||
|
@ -37668,17 +37668,6 @@ var TextSecureServer = (function() {
|
|||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
||||
this.attachment_id_regex = RegExp("^https:\/\/.*\/(\\d+)\?");
|
||||
if (attachment_server_url) {
|
||||
// strip trailing /
|
||||
attachment_server_url = attachment_server_url.replace(/\/$/,'');
|
||||
// and escape
|
||||
attachment_server_url = attachment_server_url.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
this.attachment_id_regex = RegExp( "^" + attachment_server_url + "\/(\\d+)\?");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
TextSecureServer.prototype = {
|
||||
|
@ -37882,11 +37871,6 @@ var TextSecureServer = (function() {
|
|||
urlParameters : '/' + id,
|
||||
validateResponse : {location: 'string'}
|
||||
}).then(function(response) {
|
||||
var match = response.location.match(this.attachment_id_regex);
|
||||
if (!match) {
|
||||
console.log('Invalid attachment url for incoming message', response.location);
|
||||
throw new Error('Received invalid attachment url');
|
||||
}
|
||||
return ajax(response.location, {
|
||||
type : "GET",
|
||||
responseType: "arraybuffer",
|
||||
|
@ -37899,13 +37883,6 @@ var TextSecureServer = (function() {
|
|||
call : 'attachment',
|
||||
httpType : 'GET',
|
||||
}).then(function(response) {
|
||||
// Extract the id as a string from the location url
|
||||
// (workaround for ids too large for Javascript numbers)
|
||||
var match = response.location.match(this.attachment_id_regex);
|
||||
if (!match) {
|
||||
console.log('Invalid attachment url for outgoing message', response.location);
|
||||
throw new Error('Received invalid attachment url');
|
||||
}
|
||||
return ajax(response.location, {
|
||||
type : "PUT",
|
||||
contentType : "application/octet-stream",
|
||||
|
@ -38226,12 +38203,12 @@ var TextSecureServer = (function() {
|
|||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
|
||||
function MessageReceiver(url, ports, username, password, signalingKey, attachment_server_url) {
|
||||
function MessageReceiver(url, ports, username, password, signalingKey) {
|
||||
this.url = url;
|
||||
this.signalingKey = signalingKey;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
||||
this.server = new TextSecureServer(url, ports, username, password);
|
||||
|
||||
var address = libsignal.SignalProtocolAddress.fromString(username);
|
||||
this.number = address.getName();
|
||||
|
@ -38702,8 +38679,8 @@ MessageReceiver.prototype.extend({
|
|||
|
||||
window.textsecure = window.textsecure || {};
|
||||
|
||||
textsecure.MessageReceiver = function(url, ports, username, password, signalingKey, attachment_server_url) {
|
||||
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey, attachment_server_url);
|
||||
textsecure.MessageReceiver = function(url, ports, username, password, signalingKey) {
|
||||
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey);
|
||||
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
||||
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
||||
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
||||
|
@ -39051,8 +39028,8 @@ Message.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
function MessageSender(url, ports, username, password, attachment_server_url) {
|
||||
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
||||
function MessageSender(url, ports, username, password) {
|
||||
this.server = new TextSecureServer(url, ports, username, password);
|
||||
this.pendingMessages = {};
|
||||
}
|
||||
|
||||
|
@ -39459,8 +39436,8 @@ MessageSender.prototype = {
|
|||
|
||||
window.textsecure = window.textsecure || {};
|
||||
|
||||
textsecure.MessageSender = function(url, ports, username, password, attachment_server_url) {
|
||||
var sender = new MessageSender(url, ports, username, password, attachment_server_url);
|
||||
textsecure.MessageSender = function(url, ports, username, password) {
|
||||
var sender = new MessageSender(url, ports, username, password);
|
||||
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);
|
||||
|
|
|
@ -139,7 +139,7 @@ var TextSecureServer = (function() {
|
|||
attachment : "v1/attachments"
|
||||
};
|
||||
|
||||
function TextSecureServer(url, ports, username, password, attachment_server_url) {
|
||||
function TextSecureServer(url, ports, username, password) {
|
||||
if (typeof url !== 'string') {
|
||||
throw new Error('Invalid server url');
|
||||
}
|
||||
|
@ -147,17 +147,6 @@ var TextSecureServer = (function() {
|
|||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
||||
this.attachment_id_regex = RegExp("^https:\/\/.*\/(\\d+)\?");
|
||||
if (attachment_server_url) {
|
||||
// strip trailing /
|
||||
attachment_server_url = attachment_server_url.replace(/\/$/,'');
|
||||
// and escape
|
||||
attachment_server_url = attachment_server_url.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
this.attachment_id_regex = RegExp( "^" + attachment_server_url + "\/(\\d+)\?");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
TextSecureServer.prototype = {
|
||||
|
@ -361,11 +350,6 @@ var TextSecureServer = (function() {
|
|||
urlParameters : '/' + id,
|
||||
validateResponse : {location: 'string'}
|
||||
}).then(function(response) {
|
||||
var match = response.location.match(this.attachment_id_regex);
|
||||
if (!match) {
|
||||
console.log('Invalid attachment url for incoming message', response.location);
|
||||
throw new Error('Received invalid attachment url');
|
||||
}
|
||||
return ajax(response.location, {
|
||||
type : "GET",
|
||||
responseType: "arraybuffer",
|
||||
|
@ -378,13 +362,6 @@ var TextSecureServer = (function() {
|
|||
call : 'attachment',
|
||||
httpType : 'GET',
|
||||
}).then(function(response) {
|
||||
// Extract the id as a string from the location url
|
||||
// (workaround for ids too large for Javascript numbers)
|
||||
var match = response.location.match(this.attachment_id_regex);
|
||||
if (!match) {
|
||||
console.log('Invalid attachment url for outgoing message', response.location);
|
||||
throw new Error('Received invalid attachment url');
|
||||
}
|
||||
return ajax(response.location, {
|
||||
type : "PUT",
|
||||
contentType : "application/octet-stream",
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
|
||||
function MessageReceiver(url, ports, username, password, signalingKey, attachment_server_url) {
|
||||
function MessageReceiver(url, ports, username, password, signalingKey) {
|
||||
this.url = url;
|
||||
this.signalingKey = signalingKey;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
||||
this.server = new TextSecureServer(url, ports, username, password);
|
||||
|
||||
var address = libsignal.SignalProtocolAddress.fromString(username);
|
||||
this.number = address.getName();
|
||||
|
@ -478,8 +478,8 @@ MessageReceiver.prototype.extend({
|
|||
|
||||
window.textsecure = window.textsecure || {};
|
||||
|
||||
textsecure.MessageReceiver = function(url, ports, username, password, signalingKey, attachment_server_url) {
|
||||
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey, attachment_server_url);
|
||||
textsecure.MessageReceiver = function(url, ports, username, password, signalingKey) {
|
||||
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey);
|
||||
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
||||
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
||||
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
||||
|
|
|
@ -104,8 +104,8 @@ Message.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
function MessageSender(url, ports, username, password, attachment_server_url) {
|
||||
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
||||
function MessageSender(url, ports, username, password) {
|
||||
this.server = new TextSecureServer(url, ports, username, password);
|
||||
this.pendingMessages = {};
|
||||
}
|
||||
|
||||
|
@ -512,8 +512,8 @@ MessageSender.prototype = {
|
|||
|
||||
window.textsecure = window.textsecure || {};
|
||||
|
||||
textsecure.MessageSender = function(url, ports, username, password, attachment_server_url) {
|
||||
var sender = new MessageSender(url, ports, username, password, attachment_server_url);
|
||||
textsecure.MessageSender = function(url, ports, username, password) {
|
||||
var sender = new MessageSender(url, ports, username, password);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue