[Pkg-javascript-commits] [sockjs-client] 43/434: Renamed xhrpolling to xhr-polling, other changes
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:00 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit 5fa37d0767c737b7f20957cd3640c2a7e805cde3
Author: Marek Majkowski <majek04 at gmail.com>
Date: Tue Aug 2 17:41:38 2011 +0100
Renamed xhrpolling to xhr-polling, other changes
---
README.md | 4 ++--
lib/main.js | 1 +
lib/sockjs.js | 38 ++++++++++++++++++++++++++++++--------
lib/trans-iframe-within.js | 2 +-
lib/trans-iframe-xhr-polling.js | 26 ++++++++++++++++++++++++++
lib/trans-websocket.js | 4 ++--
lib/trans-xhrpolling.js | 2 +-
smoke-reconnect.html | 3 +--
smoke-throughput.html | 3 +--
tests-src/test-run.coffee | 9 +++++++--
10 files changed, 72 insertions(+), 20 deletions(-)
diff --git a/README.md b/README.md
index 3c5856c..ccd9dd8 100644
--- a/README.md
+++ b/README.md
@@ -21,12 +21,12 @@ Protocol | Browser
------------------------------------------------- | -------------
[WebSocket hixie-76][^1] | Chrome 6-12
[WebSocket hybi-10][^2] | Chrome 14+, Firefox 6+
-Cross domain XHR - multipart | IE 8, Firefox 3.5+, Safari 4+
+[IFrame via postMessage][^3] + [EventSource][^4] | Opera 10.70+, Firefox 3.5+, Safari 5+
Cross domain XHR - polling | IE 8, Firefox 3.5+, Safari 4+, Chrome 3+ (through misbehaving proxy)
-[IFrame via postMessage][^3] + [EventSource][^4] | Opera 10.70+
[IFrame via postMessage][^3] + XHR polling | Opera 9+
[JsonP][^5] polling | (fallback)
+
[^1]: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
[^2]: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10
[^3]: https://developer.mozilla.org/en/DOM/window.postMessage
diff --git a/lib/main.js b/lib/main.js
index 6c99b7e..93a40ac 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -14,6 +14,7 @@ SockJS = (function(){
<!-- include lib/trans-iframe.js -->
<!-- include lib/trans-iframe-within.js -->
<!-- include lib/trans-iframe-eventsource.js -->
+<!-- include lib/trans-iframe-xhr-polling.js -->
<!-- include lib/trans-iframe-htmlfile.js -->
return SockJS;
})();
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 417afcf..c26d9d5 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -9,9 +9,8 @@ var SockJS = function(url, protocols, options) {
that._connid = utils.random_string(8);
that._trans_url = that._base_url + '/' + that._server + '/' + that._connid;
that._protocols = ['websocket',
- 'xhr-multipart',
- 'xhr-polling',
'iframe-eventsource',
+ 'xhr-polling',
'iframe-xhr-polling',
'jsonp-polling'];
switch(typeof protocols) {
@@ -40,10 +39,18 @@ SockJS.prototype._debug = function() {
SockJS.prototype._dispatchOpen = function() {
var that = this;
- if (that.readyState !== SockJS.CONNECTING)
- throw new Error('INVALID_STATE_ERR');
- that.readyState = SockJS.OPEN;
- that.dispatchEvent(new SimpleEvent("open"));
+ if (that.readyState === SockJS.CONNECTING) {
+ if (that._transport_tref) {
+ clearTimeout(that._transport_tref);
+ that._transport_tref = null;
+ }
+ that.readyState = SockJS.OPEN;
+ that.dispatchEvent(new SimpleEvent("open"));
+ } else {
+ // The server might have been restarted, and lost track of our
+ // connection.
+ that._didClose(1006, "Server lost session");
+ }
};
SockJS.prototype._dispatchMessage = function(data) {
@@ -63,16 +70,31 @@ SockJS.prototype._didClose = function(status, reason) {
if (that._transport)
that._transport.doCleanup();
that._transport = null;
+ if (that._transport_tref) {
+ clearTimeout(that._transport_tref);
+ that._transport_tref = null;
+ }
var close_event = new SimpleEvent("close", {status: status, reason: reason});
if (!utils.userSetStatus(status) && that.readyState === SockJS.CONNECTING) {
- if (that._try_next_protocol(close_event))
+ if (that._try_next_protocol(close_event)) {
+ that._transport_tref = setTimeout(
+ function() {
+ if (that.readyState === SockJS.CONNECTING) {
+ // I can't understand how it is possible to run
+ // this timer, when the state is CLOSED, but
+ // apparently in IE everythin is possible.
+ that._didClose(2007,
+ "Transport timeouted");
+ }
+ }, 5001);
return;
+ }
close_event = new SimpleEvent("close", {status: 2000,
reason: "All transports failed",
last_event: close_event});
}
- that.readyState = SockJS.CLOSE;
+ that.readyState = SockJS.CLOSED;
setTimeout(function() {
that.dispatchEvent(close_event);
diff --git a/lib/trans-iframe-within.js b/lib/trans-iframe-within.js
index a43a81c..73dc92c 100644
--- a/lib/trans-iframe-within.js
+++ b/lib/trans-iframe-within.js
@@ -52,7 +52,7 @@ SockJS.bootstrap_iframe = function() {
// alert('test ticker');
// facade = new FacadeJS();
- // facade._transport = new FacadeJS['w-iframe-htmlfile'](facade, 'http://172.16.173.128:9999/ticker/12/basd');
+ // facade._transport = new FacadeJS['w-iframe-xhr-polling'](facade, 'http://mmajkowski.eng.vmware.com:9999/ticker/12/basd');
utils.attachMessage(onMessage);
diff --git a/lib/trans-iframe-xhr-polling.js b/lib/trans-iframe-xhr-polling.js
new file mode 100644
index 0000000..ba3dac0
--- /dev/null
+++ b/lib/trans-iframe-xhr-polling.js
@@ -0,0 +1,26 @@
+var XhrPollingIframeTransport = SockJS['iframe-xhr-polling'] = function () {
+ var that = this;
+ that.protocol = 'w-iframe-xhr-polling';
+ that.i_constructor.apply(that, arguments);
+};
+
+// Inheritance.
+XhrPollingIframeTransport.prototype = new IframeTransport();
+
+XhrPollingIframeTransport.enabled = function () {
+ return window.XMLHttpRequest && IframeTransport.enabled();
+};
+
+
+// Exactly the same as xhr-polling, but with different `enabled`
+var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function () {
+ XhrTransport.apply(this, arguments);
+};
+
+// Inheritnace
+XhrPollingITransport.prototype = new BufferedSender();
+XhrPollingITransport.prototype._schedule_recv =
+ XhrTransport.prototype._schedule_recv;
+XhrPollingITransport.prototype.doCleanup =
+ XhrTransport.prototype.doCleanup;
+
diff --git a/lib/trans-websocket.js b/lib/trans-websocket.js
index e65e915..0689043 100644
--- a/lib/trans-websocket.js
+++ b/lib/trans-websocket.js
@@ -8,7 +8,7 @@ var WebSocketTransport = SockJS.websocket = function(ri, trans_url) {
}
that.ri = ri;
that.url = url;
- var Constructor = window.WebSocket || MozWebSocket;
+ var Constructor = window.WebSocket || window.MozWebSocket;
that.ws = new Constructor(that.url);
that.ws.onmessage = function(e) {
that.ri._didMessage(e.data);
@@ -33,5 +33,5 @@ WebSocketTransport.prototype.doCleanup = function() {
};
WebSocketTransport.enabled = function() {
- return (typeof WebSocket === 'function' || MozWebSocket);
+ return (window.WebSocket || window.MozWebSocket);
};
diff --git a/lib/trans-xhrpolling.js b/lib/trans-xhrpolling.js
index 70139f4..3b52207 100644
--- a/lib/trans-xhrpolling.js
+++ b/lib/trans-xhrpolling.js
@@ -1,6 +1,6 @@
// Requires CORS-enabled browser.
-var XhrTransport = SockJS.xhrpolling = function(ri, trans_url){
+var XhrTransport = SockJS['xhr-polling'] = function(ri, trans_url){
var that = this;
that.ri = ri;
that.trans_url = trans_url;
diff --git a/smoke-reconnect.html b/smoke-reconnect.html
index 364b961..b07f4b5 100644
--- a/smoke-reconnect.html
+++ b/smoke-reconnect.html
@@ -26,9 +26,8 @@
<select id="transport">
<option value="">- any - </option>
<option value="websocket">websocket</option>
- <option value="xhr-multipart">xhr-multipart</option>
- <option value="xhr-polling">xhr-polling</option>
<option value="iframe-eventsource">iframe-eventsource</option>
+ <option value="xhr-polling">xhr-polling</option>
<option value="iframe-xhr-polling">iframe-xhr-polling</option>
<option value="jsonp-polling">jsonp-polling</option>
</select>
diff --git a/smoke-throughput.html b/smoke-throughput.html
index a543769..5e73855 100644
--- a/smoke-throughput.html
+++ b/smoke-throughput.html
@@ -26,9 +26,8 @@
<select id="transport">
<option value="">- any - </option>
<option value="websocket">websocket</option>
- <option value="xhr-multipart">xhr-multipart</option>
- <option value="xhr-polling">xhr-polling</option>
<option value="iframe-eventsource">iframe-eventsource</option>
+ <option value="xhr-polling">xhr-polling</option>
<option value="iframe-xhr-polling">iframe-xhr-polling</option>
<option value="jsonp-polling">jsonp-polling</option>
</select>
diff --git a/tests-src/test-run.coffee b/tests-src/test-run.coffee
index 60d858e..d08e49c 100644
--- a/tests-src/test-run.coffee
+++ b/tests-src/test-run.coffee
@@ -1,7 +1,7 @@
test_protocol = (protocol) ->
module(protocol)
- if not SockJS[protocol].enabled()
+ if not SockJS[protocol] or not SockJS[protocol].enabled()
test "[unsupported]", ->
log('Unsupported protocol: "' + protocol + '"')
else
@@ -19,5 +19,10 @@ test_protocol = (protocol) ->
asyncTest("invalid url port", test_invalid_url_port(protocol))
-for protocol in ['websocket', 'xhrpolling', 'jsonp', 'iframe-eventsource', 'iframe-htmlfile']
+protocols = ['websocket',
+ 'iframe-eventsource',
+ 'xhr-polling',
+ 'iframe-xhr-polling',
+ 'jsonp-polling']
+for protocol in protocols
test_protocol(protocol)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list