From 90eb9cb0c8930ab6e39dcb26e1c2776b618828ad Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 26 Jul 2014 18:14:24 -0400 Subject: [PATCH] Remove ping, update to latest spec proposal --- js/api.js | 18 ++---------------- js/options.js | 5 ++--- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/js/api.js b/js/api.js index 630585be4..68444a0f8 100644 --- a/js/api.js +++ b/js/api.js @@ -294,8 +294,6 @@ window.textsecure.api = function() { var params = $.param({}); var reconnectSemaphore = 0; - var pingInterval; - var socketWrapper = { onmessage: function() {}, ondisconnect: function() {}, onconnect: function() {} }; var connect = function() { @@ -307,7 +305,6 @@ window.textsecure.api = function() { socket.onerror = function(socketEvent) { console.log('Server is down :('); - clearInterval(pingInterval); reconnectSemaphore--; setTimeout(function() { connect(); }, reconnectTimeout); socketWrapper.ondisconnect(); @@ -315,7 +312,6 @@ window.textsecure.api = function() { socket.onclose = function(socketEvent) { console.log('Server closed :('); - clearInterval(pingInterval); reconnectSemaphore--; setTimeout(function() { connect(); }, reconnectTimeout); socketWrapper.ondisconnect(); @@ -323,14 +319,6 @@ window.textsecure.api = function() { socket.onopen = function(socketEvent) { console.log('Connected to server!'); - pingInterval = setInterval(function() { - console.log("Sending server ping message."); - if (socket.readyState == socket.CLOSED || socket.readyState == socket.CLOSING) { - socket.close(); - socket.onclose(); - } else - socket.send(JSON.stringify({type: 2})); - }, reconnectTimeout / 2); socketWrapper.onconnect(); }; @@ -343,9 +331,7 @@ window.textsecure.api = function() { return; } - if (message.type == 3) - console.log("Got pong message"); - else if ((message.type === undefined && message.id !== undefined) || message.type === 4) + if ((message.type === undefined && message.id !== undefined) || message.type === 4) socketWrapper.onmessage(message); else console.log("Got invalid message from server: " + message); @@ -368,7 +354,7 @@ window.textsecure.api = function() { //XXX var socketWrapper = { onmessage: function() {}, ondisconnect: function() {}, onconnect: function() {} }; setTimeout(function() { - socketWrapper.onmessage({type: 4, message: "404-42-magic"}); + socketWrapper.onmessage({uuid: "404-42-magic"}); }, 1000); return socketWrapper; //return getWebsocket(URL_CALLS['temp_push'], false, 5000); diff --git a/js/options.js b/js/options.js index f203f4761..456b68a70 100644 --- a/js/options.js +++ b/js/options.js @@ -138,10 +138,9 @@ textsecure.registerOnLoadFunction(function() { var socket = textsecure.api.getTempWebsocket(); socket.onmessage = function(message) { - //TODO: Get a server format for this - if (message.type === 4) { + if (message.uuid) { qrCode.makeCode('textsecure-device-init:/' + - '?channel_uuid=' + message.message + + '?channel_uuid=' + message.uuid + '&channel_server=' + textsecure.api.relay + '&publicKey=' + btoa(getString(cryptoInfo.publicKey))); $('img').removeAttr('style');