Rename textsecure.websocket and make it internal-only
This commit is contained in:
parent
89c24cd2fa
commit
da34b8e0f8
4 changed files with 246 additions and 252 deletions
166
js/key_worker.js
166
js/key_worker.js
|
@ -38415,91 +38415,89 @@ window.axolotl.sessions = {
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
;(function(){
|
||||
|
||||
/*
|
||||
* var socket = TextSecureWebSocket(url);
|
||||
*
|
||||
* Returns an adamantium-reinforced super socket, capable of sending
|
||||
* app-level keep alives and automatically reconnecting.
|
||||
*
|
||||
*/
|
||||
|
||||
TextSecureWebSocket = function (url) {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* var socket = textsecure.websocket(url);
|
||||
*
|
||||
* Returns an adamantium-reinforced super socket, capable of sending
|
||||
* app-level keep alives and automatically reconnecting.
|
||||
*
|
||||
*/
|
||||
|
||||
window.textsecure.websocket = function (url) {
|
||||
var keepAliveTimer;
|
||||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
};
|
||||
var error;
|
||||
|
||||
function resetKeepAliveTimer() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
keepAliveTimer = setTimeout(function() {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(
|
||||
new textsecure.protobuf.WebSocketMessage({
|
||||
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||
}).encode().toArrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
resetKeepAliveTimer();
|
||||
}, 55000);
|
||||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||
console.log('websocket closed', e.code);
|
||||
}
|
||||
socketWrapper.onclose(e);
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
error = e;
|
||||
console.log('websocket error');
|
||||
socketWrapper.onerror(e);
|
||||
};
|
||||
|
||||
function onmessage(response) {
|
||||
socketWrapper.onmessage(response);
|
||||
resetKeepAliveTimer();
|
||||
};
|
||||
|
||||
function send(msg) {
|
||||
resetKeepAliveTimer();
|
||||
socket.send(msg);
|
||||
};
|
||||
|
||||
function connect() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
if (++reconnectSemaphore <= 0) { return; }
|
||||
|
||||
if (socket) { socket.close(); }
|
||||
socket = new WebSocket(url);
|
||||
|
||||
socket.onopen = resetKeepAliveTimer;
|
||||
socket.onerror = onerror
|
||||
socket.onclose = onclose;
|
||||
socket.onmessage = onmessage;
|
||||
socketWrapper.send = send;
|
||||
};
|
||||
|
||||
connect();
|
||||
return socketWrapper;
|
||||
var keepAliveTimer;
|
||||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
};
|
||||
})();
|
||||
var error;
|
||||
|
||||
function resetKeepAliveTimer() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
keepAliveTimer = setTimeout(function() {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(
|
||||
new textsecure.protobuf.WebSocketMessage({
|
||||
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||
}).encode().toArrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
resetKeepAliveTimer();
|
||||
}, 55000);
|
||||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||
console.log('websocket closed', e.code);
|
||||
}
|
||||
socketWrapper.onclose(e);
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
error = e;
|
||||
console.log('websocket error');
|
||||
socketWrapper.onerror(e);
|
||||
};
|
||||
|
||||
function onmessage(response) {
|
||||
socketWrapper.onmessage(response);
|
||||
resetKeepAliveTimer();
|
||||
};
|
||||
|
||||
function send(msg) {
|
||||
resetKeepAliveTimer();
|
||||
socket.send(msg);
|
||||
};
|
||||
|
||||
function connect() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
if (++reconnectSemaphore <= 0) { return; }
|
||||
|
||||
if (socket) { socket.close(); }
|
||||
socket = new WebSocket(url);
|
||||
|
||||
socket.onopen = resetKeepAliveTimer;
|
||||
socket.onerror = onerror
|
||||
socket.onclose = onclose;
|
||||
socket.onmessage = onmessage;
|
||||
socketWrapper.send = send;
|
||||
};
|
||||
|
||||
connect();
|
||||
return socketWrapper;
|
||||
};
|
||||
|
||||
/* vim: ts=4:sw=4:expandtab
|
||||
*
|
||||
|
@ -39361,7 +39359,7 @@ window.textsecure.api = function () {
|
|||
var password = textsecure.storage.get("password");
|
||||
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
||||
}
|
||||
return window.textsecure.websocket(URL+params)
|
||||
return TextSecureWebSocket(URL+params)
|
||||
}
|
||||
|
||||
self.getMessageWebsocket = function() {
|
||||
|
|
|
@ -38414,91 +38414,89 @@ window.axolotl.sessions = {
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
;(function(){
|
||||
|
||||
/*
|
||||
* var socket = TextSecureWebSocket(url);
|
||||
*
|
||||
* Returns an adamantium-reinforced super socket, capable of sending
|
||||
* app-level keep alives and automatically reconnecting.
|
||||
*
|
||||
*/
|
||||
|
||||
TextSecureWebSocket = function (url) {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* var socket = textsecure.websocket(url);
|
||||
*
|
||||
* Returns an adamantium-reinforced super socket, capable of sending
|
||||
* app-level keep alives and automatically reconnecting.
|
||||
*
|
||||
*/
|
||||
|
||||
window.textsecure.websocket = function (url) {
|
||||
var keepAliveTimer;
|
||||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
};
|
||||
var error;
|
||||
|
||||
function resetKeepAliveTimer() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
keepAliveTimer = setTimeout(function() {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(
|
||||
new textsecure.protobuf.WebSocketMessage({
|
||||
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||
}).encode().toArrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
resetKeepAliveTimer();
|
||||
}, 55000);
|
||||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||
console.log('websocket closed', e.code);
|
||||
}
|
||||
socketWrapper.onclose(e);
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
error = e;
|
||||
console.log('websocket error');
|
||||
socketWrapper.onerror(e);
|
||||
};
|
||||
|
||||
function onmessage(response) {
|
||||
socketWrapper.onmessage(response);
|
||||
resetKeepAliveTimer();
|
||||
};
|
||||
|
||||
function send(msg) {
|
||||
resetKeepAliveTimer();
|
||||
socket.send(msg);
|
||||
};
|
||||
|
||||
function connect() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
if (++reconnectSemaphore <= 0) { return; }
|
||||
|
||||
if (socket) { socket.close(); }
|
||||
socket = new WebSocket(url);
|
||||
|
||||
socket.onopen = resetKeepAliveTimer;
|
||||
socket.onerror = onerror
|
||||
socket.onclose = onclose;
|
||||
socket.onmessage = onmessage;
|
||||
socketWrapper.send = send;
|
||||
};
|
||||
|
||||
connect();
|
||||
return socketWrapper;
|
||||
var keepAliveTimer;
|
||||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
};
|
||||
})();
|
||||
var error;
|
||||
|
||||
function resetKeepAliveTimer() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
keepAliveTimer = setTimeout(function() {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(
|
||||
new textsecure.protobuf.WebSocketMessage({
|
||||
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||
}).encode().toArrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
resetKeepAliveTimer();
|
||||
}, 55000);
|
||||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||
console.log('websocket closed', e.code);
|
||||
}
|
||||
socketWrapper.onclose(e);
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
error = e;
|
||||
console.log('websocket error');
|
||||
socketWrapper.onerror(e);
|
||||
};
|
||||
|
||||
function onmessage(response) {
|
||||
socketWrapper.onmessage(response);
|
||||
resetKeepAliveTimer();
|
||||
};
|
||||
|
||||
function send(msg) {
|
||||
resetKeepAliveTimer();
|
||||
socket.send(msg);
|
||||
};
|
||||
|
||||
function connect() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
if (++reconnectSemaphore <= 0) { return; }
|
||||
|
||||
if (socket) { socket.close(); }
|
||||
socket = new WebSocket(url);
|
||||
|
||||
socket.onopen = resetKeepAliveTimer;
|
||||
socket.onerror = onerror
|
||||
socket.onclose = onclose;
|
||||
socket.onmessage = onmessage;
|
||||
socketWrapper.send = send;
|
||||
};
|
||||
|
||||
connect();
|
||||
return socketWrapper;
|
||||
};
|
||||
|
||||
/* vim: ts=4:sw=4:expandtab
|
||||
*
|
||||
|
@ -39360,7 +39358,7 @@ window.textsecure.api = function () {
|
|||
var password = textsecure.storage.get("password");
|
||||
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
||||
}
|
||||
return window.textsecure.websocket(URL+params)
|
||||
return TextSecureWebSocket(URL+params)
|
||||
}
|
||||
|
||||
self.getMessageWebsocket = function() {
|
||||
|
|
|
@ -333,7 +333,7 @@ window.textsecure.api = function () {
|
|||
var password = textsecure.storage.get("password");
|
||||
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
||||
}
|
||||
return window.textsecure.websocket(URL+params)
|
||||
return TextSecureWebSocket(URL+params)
|
||||
}
|
||||
|
||||
self.getMessageWebsocket = function() {
|
||||
|
|
|
@ -13,88 +13,86 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
;(function(){
|
||||
|
||||
/*
|
||||
* var socket = TextSecureWebSocket(url);
|
||||
*
|
||||
* Returns an adamantium-reinforced super socket, capable of sending
|
||||
* app-level keep alives and automatically reconnecting.
|
||||
*
|
||||
*/
|
||||
|
||||
TextSecureWebSocket = function (url) {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* var socket = textsecure.websocket(url);
|
||||
*
|
||||
* Returns an adamantium-reinforced super socket, capable of sending
|
||||
* app-level keep alives and automatically reconnecting.
|
||||
*
|
||||
*/
|
||||
|
||||
window.textsecure.websocket = function (url) {
|
||||
var keepAliveTimer;
|
||||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
};
|
||||
var error;
|
||||
|
||||
function resetKeepAliveTimer() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
keepAliveTimer = setTimeout(function() {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(
|
||||
new textsecure.protobuf.WebSocketMessage({
|
||||
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||
}).encode().toArrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
resetKeepAliveTimer();
|
||||
}, 55000);
|
||||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||
console.log('websocket closed', e.code);
|
||||
}
|
||||
socketWrapper.onclose(e);
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
error = e;
|
||||
console.log('websocket error');
|
||||
socketWrapper.onerror(e);
|
||||
};
|
||||
|
||||
function onmessage(response) {
|
||||
socketWrapper.onmessage(response);
|
||||
resetKeepAliveTimer();
|
||||
};
|
||||
|
||||
function send(msg) {
|
||||
resetKeepAliveTimer();
|
||||
socket.send(msg);
|
||||
};
|
||||
|
||||
function connect() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
if (++reconnectSemaphore <= 0) { return; }
|
||||
|
||||
if (socket) { socket.close(); }
|
||||
socket = new WebSocket(url);
|
||||
|
||||
socket.onopen = resetKeepAliveTimer;
|
||||
socket.onerror = onerror
|
||||
socket.onclose = onclose;
|
||||
socket.onmessage = onmessage;
|
||||
socketWrapper.send = send;
|
||||
};
|
||||
|
||||
connect();
|
||||
return socketWrapper;
|
||||
var keepAliveTimer;
|
||||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
};
|
||||
})();
|
||||
var error;
|
||||
|
||||
function resetKeepAliveTimer() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
keepAliveTimer = setTimeout(function() {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(
|
||||
new textsecure.protobuf.WebSocketMessage({
|
||||
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||
}).encode().toArrayBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
resetKeepAliveTimer();
|
||||
}, 55000);
|
||||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
if (e !== 1000 ) { // CLOSE_NORMAL
|
||||
console.log('websocket closed', e.code);
|
||||
}
|
||||
socketWrapper.onclose(e);
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
error = e;
|
||||
console.log('websocket error');
|
||||
socketWrapper.onerror(e);
|
||||
};
|
||||
|
||||
function onmessage(response) {
|
||||
socketWrapper.onmessage(response);
|
||||
resetKeepAliveTimer();
|
||||
};
|
||||
|
||||
function send(msg) {
|
||||
resetKeepAliveTimer();
|
||||
socket.send(msg);
|
||||
};
|
||||
|
||||
function connect() {
|
||||
clearTimeout(keepAliveTimer);
|
||||
if (++reconnectSemaphore <= 0) { return; }
|
||||
|
||||
if (socket) { socket.close(); }
|
||||
socket = new WebSocket(url);
|
||||
|
||||
socket.onopen = resetKeepAliveTimer;
|
||||
socket.onerror = onerror
|
||||
socket.onclose = onclose;
|
||||
socket.onmessage = onmessage;
|
||||
socketWrapper.send = send;
|
||||
};
|
||||
|
||||
connect();
|
||||
return socketWrapper;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue