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')) {
|
if (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').replace(
|
'textsecure-service-ca.whispersystems.org');
|
||||||
/whispersystems-textsecure-attachments-staging.s3.amazonaws.com/g,
|
|
||||||
'whispersystems-textsecure-attachments.s3.amazonaws.com');
|
|
||||||
} else if (srcpath.match('expire.js')) {
|
} else if (srcpath.match('expire.js')) {
|
||||||
var gitinfo = grunt.config.get('gitinfo');
|
var gitinfo = grunt.config.get('gitinfo');
|
||||||
var commited = gitinfo.local.branch.current.lastCommitTime;
|
var commited = gitinfo.local.branch.current.lastCommitTime;
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
|
|
||||||
var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org';
|
var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org';
|
||||||
var SERVER_PORTS = [80, 4433, 8443];
|
var SERVER_PORTS = [80, 4433, 8443];
|
||||||
var ATTACHMENT_SERVER_URL = 'https://whispersystems-textsecure-attachments-staging.s3.amazonaws.com';
|
|
||||||
var messageReceiver;
|
var messageReceiver;
|
||||||
window.getSocketStatus = function() {
|
window.getSocketStatus = function() {
|
||||||
if (messageReceiver) {
|
if (messageReceiver) {
|
||||||
|
@ -108,7 +107,7 @@
|
||||||
|
|
||||||
// initialize the socket and start listening for messages
|
// initialize the socket and start listening for messages
|
||||||
messageReceiver = new textsecure.MessageReceiver(
|
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('message', onMessageReceived);
|
||||||
messageReceiver.addEventListener('receipt', onDeliveryReceipt);
|
messageReceiver.addEventListener('receipt', onDeliveryReceipt);
|
||||||
|
@ -119,7 +118,7 @@
|
||||||
messageReceiver.addEventListener('error', onError);
|
messageReceiver.addEventListener('error', onError);
|
||||||
|
|
||||||
window.textsecure.messaging = new textsecure.MessageSender(
|
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 (firstRun === true && textsecure.storage.user.getDeviceId() != '1') {
|
||||||
if (!storage.get('theme-setting') && textsecure.storage.get('userAgent') === 'OWI') {
|
if (!storage.get('theme-setting') && textsecure.storage.get('userAgent') === 'OWI') {
|
||||||
|
|
|
@ -37660,7 +37660,7 @@ var TextSecureServer = (function() {
|
||||||
attachment : "v1/attachments"
|
attachment : "v1/attachments"
|
||||||
};
|
};
|
||||||
|
|
||||||
function TextSecureServer(url, ports, username, password, attachment_server_url) {
|
function TextSecureServer(url, ports, username, password) {
|
||||||
if (typeof url !== 'string') {
|
if (typeof url !== 'string') {
|
||||||
throw new Error('Invalid server url');
|
throw new Error('Invalid server url');
|
||||||
}
|
}
|
||||||
|
@ -37668,17 +37668,6 @@ var TextSecureServer = (function() {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
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 = {
|
TextSecureServer.prototype = {
|
||||||
|
@ -37882,11 +37871,6 @@ var TextSecureServer = (function() {
|
||||||
urlParameters : '/' + id,
|
urlParameters : '/' + id,
|
||||||
validateResponse : {location: 'string'}
|
validateResponse : {location: 'string'}
|
||||||
}).then(function(response) {
|
}).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, {
|
return ajax(response.location, {
|
||||||
type : "GET",
|
type : "GET",
|
||||||
responseType: "arraybuffer",
|
responseType: "arraybuffer",
|
||||||
|
@ -37899,13 +37883,6 @@ var TextSecureServer = (function() {
|
||||||
call : 'attachment',
|
call : 'attachment',
|
||||||
httpType : 'GET',
|
httpType : 'GET',
|
||||||
}).then(function(response) {
|
}).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, {
|
return ajax(response.location, {
|
||||||
type : "PUT",
|
type : "PUT",
|
||||||
contentType : "application/octet-stream",
|
contentType : "application/octet-stream",
|
||||||
|
@ -38226,12 +38203,12 @@ var TextSecureServer = (function() {
|
||||||
* vim: ts=4:sw=4:expandtab
|
* 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.url = url;
|
||||||
this.signalingKey = signalingKey;
|
this.signalingKey = signalingKey;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
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);
|
var address = libsignal.SignalProtocolAddress.fromString(username);
|
||||||
this.number = address.getName();
|
this.number = address.getName();
|
||||||
|
@ -38702,8 +38679,8 @@ MessageReceiver.prototype.extend({
|
||||||
|
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
textsecure.MessageReceiver = function(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, attachment_server_url);
|
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey);
|
||||||
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
||||||
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
||||||
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
||||||
|
@ -39051,8 +39028,8 @@ Message.prototype = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageSender(url, ports, username, password, attachment_server_url) {
|
function MessageSender(url, ports, username, password) {
|
||||||
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
this.server = new TextSecureServer(url, ports, username, password);
|
||||||
this.pendingMessages = {};
|
this.pendingMessages = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39459,8 +39436,8 @@ MessageSender.prototype = {
|
||||||
|
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
textsecure.MessageSender = function(url, ports, username, password, attachment_server_url) {
|
textsecure.MessageSender = function(url, ports, username, password) {
|
||||||
var sender = new MessageSender(url, ports, username, password, attachment_server_url);
|
var sender = new MessageSender(url, ports, username, password);
|
||||||
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.ENCRYPT_MESSAGE);
|
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.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
|
||||||
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
|
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
|
||||||
|
|
|
@ -139,7 +139,7 @@ var TextSecureServer = (function() {
|
||||||
attachment : "v1/attachments"
|
attachment : "v1/attachments"
|
||||||
};
|
};
|
||||||
|
|
||||||
function TextSecureServer(url, ports, username, password, attachment_server_url) {
|
function TextSecureServer(url, ports, username, password) {
|
||||||
if (typeof url !== 'string') {
|
if (typeof url !== 'string') {
|
||||||
throw new Error('Invalid server url');
|
throw new Error('Invalid server url');
|
||||||
}
|
}
|
||||||
|
@ -147,17 +147,6 @@ var TextSecureServer = (function() {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
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 = {
|
TextSecureServer.prototype = {
|
||||||
|
@ -361,11 +350,6 @@ var TextSecureServer = (function() {
|
||||||
urlParameters : '/' + id,
|
urlParameters : '/' + id,
|
||||||
validateResponse : {location: 'string'}
|
validateResponse : {location: 'string'}
|
||||||
}).then(function(response) {
|
}).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, {
|
return ajax(response.location, {
|
||||||
type : "GET",
|
type : "GET",
|
||||||
responseType: "arraybuffer",
|
responseType: "arraybuffer",
|
||||||
|
@ -378,13 +362,6 @@ var TextSecureServer = (function() {
|
||||||
call : 'attachment',
|
call : 'attachment',
|
||||||
httpType : 'GET',
|
httpType : 'GET',
|
||||||
}).then(function(response) {
|
}).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, {
|
return ajax(response.location, {
|
||||||
type : "PUT",
|
type : "PUT",
|
||||||
contentType : "application/octet-stream",
|
contentType : "application/octet-stream",
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
* vim: ts=4:sw=4:expandtab
|
* 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.url = url;
|
||||||
this.signalingKey = signalingKey;
|
this.signalingKey = signalingKey;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
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);
|
var address = libsignal.SignalProtocolAddress.fromString(username);
|
||||||
this.number = address.getName();
|
this.number = address.getName();
|
||||||
|
@ -478,8 +478,8 @@ MessageReceiver.prototype.extend({
|
||||||
|
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
textsecure.MessageReceiver = function(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, attachment_server_url);
|
var messageReceiver = new MessageReceiver(url, ports, username, password, signalingKey);
|
||||||
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
|
||||||
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
|
||||||
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
|
||||||
|
|
|
@ -104,8 +104,8 @@ Message.prototype = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageSender(url, ports, username, password, attachment_server_url) {
|
function MessageSender(url, ports, username, password) {
|
||||||
this.server = new TextSecureServer(url, ports, username, password, attachment_server_url);
|
this.server = new TextSecureServer(url, ports, username, password);
|
||||||
this.pendingMessages = {};
|
this.pendingMessages = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,8 +512,8 @@ MessageSender.prototype = {
|
||||||
|
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
textsecure.MessageSender = function(url, ports, username, password, attachment_server_url) {
|
textsecure.MessageSender = function(url, ports, username, password) {
|
||||||
var sender = new MessageSender(url, ports, username, password, attachment_server_url);
|
var sender = new MessageSender(url, ports, username, password);
|
||||||
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.ENCRYPT_MESSAGE);
|
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.retransmitMessage.bind(sender), textsecure.replay.Type.TRANSMIT_MESSAGE);
|
||||||
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
|
textsecure.replay.registerFunction(sender.sendMessage.bind(sender), textsecure.replay.Type.REBUILD_MESSAGE);
|
||||||
|
|
Loading…
Reference in a new issue