From ed6af4f2befd2e259f09234a592cc95610095bc8 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sun, 7 Apr 2013 20:07:44 -0700 Subject: Declare delayDefault as a variable. --- priv/bullet.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'priv/bullet.js') diff --git a/priv/bullet.js b/priv/bullet.js index 4ba2cb8..7cf10a9 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -172,7 +172,8 @@ var isClosed = true; var readyState = CLOSED; var heartbeat; - var delay = delayDefault = 80; + var delay = 80; + var delayDefault = 80; var delayMax = 10000; var transport; -- cgit v1.2.3 From cb88dfc843072ea18301bad2a98b6f32d755fac6 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sun, 7 Apr 2013 20:21:29 -0700 Subject: Handle missing transport in send() and close(). The transport might be missing if we are in the middle of a reconnect attempt. --- priv/bullet.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'priv/bullet.js') diff --git a/priv/bullet.js b/priv/bullet.js index 7cf10a9..88c9f89 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -251,11 +251,17 @@ url = newURL; }; this.send = function(data){ - return transport.send(data); + if (transport){ + return transport.send(data); + } else{ + return false; + } }; this.close = function(){ readyState = CLOSING; - transport.close(); + if (transport){ + transport.close(); + } }; }; -- cgit v1.2.3 From d2f9805b0d668e5b76ca63cd1b47b8a205ba09e1 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sun, 7 Apr 2013 20:23:04 -0700 Subject: Drop transport reference after closing. --- priv/bullet.js | 1 + 1 file changed, 1 insertion(+) (limited to 'priv/bullet.js') diff --git a/priv/bullet.js b/priv/bullet.js index 88c9f89..f1b22ba 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -215,6 +215,7 @@ if (readyState == CLOSING){ readyState = CLOSED; + transport = false; stream.onclose(); } else{ // Close happened on connect, select next transport -- cgit v1.2.3 From 954b4f29ee7c6edddaa462041d6a8d45cf5ba7bb Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Mon, 8 Apr 2013 20:01:54 -0700 Subject: Support EventSource as a transport. --- priv/bullet.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'priv/bullet.js') diff --git a/priv/bullet.js b/priv/bullet.js index f1b22ba..19d294d 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -32,7 +32,7 @@ onheartbeat is called once every few seconds to allow you to easily setup a ping/pong mechanism. */ -(function($){$.extend({bullet: function(url){ +(function($){$.extend({bullet: function(url, options){ var CONNECTING = 0; var OPEN = 1; var CLOSING = 2; @@ -47,6 +47,10 @@ websocket: function(){ var ret = false; + if (options !== undefined && options.disableWebSocket) { + return false; + } + if (window.WebSocket){ ret = window.WebSocket; } @@ -63,7 +67,54 @@ return false; }, + eventsource: function(){ + if (options !== undefined && options.disableEventSource) { + return false; + } + + if (!window.EventSource){ + return false; + } + + var eventsourceURL = url.replace('ws:', 'http:').replace('wss:', 'https:'); + var source = new window.EventSource(eventsourceURL); + + source.onopen = function () { + fake.readyState = OPEN; + fake.onopen(); + }; + + source.onmessage = function (event) { + fake.onmessage(event); + }; + + source.onerror = function () { + source.close(); // bullet will handle reconnects + source = undefined; + fake.onerror(); + }; + + var fake = { + readyState: CONNECTING, + send: function(data){ + return false; // fallback to another method instead? + }, + close: function(){ + fake.readyState = CLOSED; + source.close(); + source = undefined; + fake.onclose(); + } + }; + + return {'heart': false, 'transport': function(){ return fake; }}; + }, + xhrPolling: function(){ + if (options !== undefined && options.disableXHRPolling) { + return false; + } + var timeout; var xhr; -- cgit v1.2.3