From ba9bf407fbbe500b0894b57a9749f1168e94e588 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Wed, 19 Jun 2013 20:00:32 -0700 Subject: Ignore close callback when closed. This fixes a bug where closing a bullet connection in poll mode will not work. --- priv/bullet.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/bullet.js b/priv/bullet.js index 50686f6..7c3c977 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -257,8 +257,9 @@ }; transport.onclose = function(){ // Firefox 13.0.1 sends 2 close events. - // Return directly if we already handled it. - if (isClosed){ + // Return directly if we already handled it + // or we are closed + if (isClosed || readyState == CLOSED){ return; } -- cgit v1.2.3 From 7bdad97940fb928f7770980d89cd6c611252c6f1 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Wed, 19 Jun 2013 20:06:36 -0700 Subject: Fix jshint warning. --- priv/bullet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/bullet.js b/priv/bullet.js index 7c3c977..072a39e 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -138,7 +138,7 @@ 'application/x-www-form-urlencoded; charset=utf-8', headers: {'X-Socket-Transport': 'xhrPolling'}, success: function(data){ - if (data.length != 0){ + if (data.length !== 0){ fake.onmessage({'data': data}); } } @@ -174,7 +174,7 @@ fake.onopen(fake); } // Connection might have closed without a response body - if (data.length != 0){ + if (data.length !== 0){ fake.onmessage({'data': data}); } if (fake.readyState == OPEN){ -- cgit v1.2.3 From b6d7e1241e67dedcd9f3786bbdd82685fe257da0 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Wed, 19 Jun 2013 20:11:17 -0700 Subject: Drop reference to xhr request when done. --- priv/bullet.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'priv') diff --git a/priv/bullet.js b/priv/bullet.js index 072a39e..0fbc2ac 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -116,7 +116,7 @@ } var timeout; - var xhr; + var xhr = null; var fake = { readyState: CONNECTING, @@ -148,7 +148,10 @@ }, close: function(){ this.readyState = CLOSED; - xhr.abort(); + if (xhr){ + xhr.abort(); + xhr = null; + } clearTimeout(timeout); fake.onclose(); }, @@ -169,6 +172,7 @@ data: {}, headers: {'X-Socket-Transport': 'xhrPolling'}, success: function(data){ + xhr = null; if (fake.readyState == CONNECTING){ fake.readyState = OPEN; fake.onopen(fake); @@ -182,6 +186,7 @@ } }, error: function(xhr){ + xhr = null; fake.onerror(); } }); -- cgit v1.2.3 From 95366273731c5b05927053bc781624ebb06b1cb7 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sat, 22 Jun 2013 11:25:45 -0700 Subject: Use xhr for sending with eventsource connections. --- priv/bullet.js | 61 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'priv') diff --git a/priv/bullet.js b/priv/bullet.js index 0fbc2ac..e43fe75 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -38,6 +38,36 @@ var CLOSING = 2; var CLOSED = 3; + var xhrSend = function(data){ + /** + Send a message using ajax. Used for both the + eventsource and xhrPolling transports. + */ + if (this.readyState != CONNECTING && this.readyState != OPEN){ + return false; + } + + var sendUrl = url.replace('ws:', 'http:').replace('wss:', 'https:'); + + $.ajax({ + async: false, + cache: false, + type: 'POST', + url: sendUrl, + data: data, + dataType: 'text', + contentType: 'application/x-www-form-urlencoded; charset=utf-8', + headers: {'X-Socket-Transport': 'xhrPolling'}, + success: function(data){ + if (data.length !== 0){ + fake.onmessage({'data': data}); + } + } + }); + + return true; + }; + var transports = { /** The websocket transport is disabled for Firefox 6.0 because it @@ -96,9 +126,7 @@ var fake = { readyState: CONNECTING, - send: function(data){ - return false; // fallback to another method instead? - }, + send: xhrSend, close: function(){ fake.readyState = CLOSED; source.close(); @@ -120,32 +148,7 @@ var fake = { readyState: CONNECTING, - send: function(data){ - if (this.readyState != CONNECTING && this.readyState != OPEN){ - return false; - } - - var fakeurl = url.replace('ws:', 'http:').replace('wss:', 'https:'); - - $.ajax({ - async: false, - cache: false, - type: 'POST', - url: fakeurl, - data: data, - dataType: 'text', - contentType: - 'application/x-www-form-urlencoded; charset=utf-8', - headers: {'X-Socket-Transport': 'xhrPolling'}, - success: function(data){ - if (data.length !== 0){ - fake.onmessage({'data': data}); - } - } - }); - - return true; - }, + send: xhrSend, close: function(){ this.readyState = CLOSED; if (xhr){ -- cgit v1.2.3