[Pkg-javascript-commits] [sockjs-client] 95/434: Generic htmlfile support

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:06 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 ceafdd67f2dfb30a764e86326792941168a9cb92
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Tue Aug 23 15:39:36 2011 +0100

    Generic htmlfile support
---
 README.md                    | 35 +++++++++++++++++++++--
 lib/index.js                 |  1 +
 lib/sockjs.js                |  3 +-
 lib/trans-iframe-htmlfile.js | 68 ++++++++++++++++++++++++++++++++++++++++++++
 tests/html/src/tests.coffee  |  3 +-
 5 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 80f36e1..40871c0 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,33 @@ SockJS server. Here's a simple example:
     </script>
 
 
+SockJS-client API
+-----------------
+
+### SockJS class
+
+Similar to 'WebSocket' class 'SockJS' constructor takes one, or more arguments:
+
+```javascript
+var sockjs = new SockJS(url, protocols, options);
+```
+
+Where `options` is a hash which can contain:
+
+<dl>
+<dt>debug (boolean)</dt>
+<dd>Print more debugging messages using 'console.log'.</dd>
+<dt>devel (boolean)</dt>
+<dd>Development mode. Currently settint it affects only caching of 'iframe.html'.</dd>
+<dt>cookie (boolean)</dt>
+<dd>Disables transports which doesn't support cookies (ie: XDR on
+    IE). Usefull for load balancing based on sticky sessions provided by
+    JSESSIONID cookie.</dd>
+<dt></dt>
+<dd></dd>
+</dl>
+
+
 Supported transports
 --------------------
 
@@ -81,10 +108,11 @@ Protocol                                          | Browser
 [WebSocket hixie-76][^1]                          | Chrome 6-12, Safari 5, Firefox 4 (disabled), Opera 11 (disabled)
 [WebSocket hybi-10][^2]                           | Chrome 14+, Firefox 6+
 [IFrame via postMessage][^3] + [EventSource][^4]  | Opera 10.70+, Firefox 3.5+
-[XDR streaming][^7] (CORS)                        | IE 8, Firefox 3.5+, Safari 4+, Chrome 3+
-[XDR polling][^5] (CORS)                          | IE 8, Firefox 3.5+, Safari 4+, Chrome 3+ (through misbehaving proxy)
+[XDR (CORS) streaming][^7]                        | IE 8 (no cookies), Firefox 3.5+, Safari 4+, Chrome 3+
+[IFrame via postMessage][^3] + [HtmlFile][^8]     | IE 8 (with cookies)
+[XDR (CORS) polling][^5]                          | IE 8, Firefox 3.5+, Safari 4+, Chrome 3+ (through misbehaving proxy)
 [IFrame via postMessage][^3] + XHR polling        | Opera 9+
-[JsonP polling][^6]                               | (fallback)
+[JsonP polling][^6]                               | (rough and slow fallback)
 
 
 [^1]: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
@@ -94,6 +122,7 @@ Protocol                                          | Browser
 [^5]: https://secure.wikimedia.org/wikipedia/en/wiki/XMLHttpRequest#Cross-domain_requests
 [^6]: https://secure.wikimedia.org/wikipedia/en/wiki/JSONP
 [^7]: http://www.debugtheweb.com/test/teststreaming.aspx
+[^8]: http://cometdaily.com/2007/11/18/ie-activexhtmlfile-transport-part-ii/
 
 
 Deployment
diff --git a/lib/index.js b/lib/index.js
index 03aca34..6d378f1 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -15,6 +15,7 @@ SockJS = (function(){
 <!-- 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;
           })();
 if ('_sockjs_onload' in window) setTimeout(_sockjs_onload, 1);
diff --git a/lib/sockjs.js b/lib/sockjs.js
index f2319c6..20ac833 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -10,6 +10,7 @@ var SockJS = function(url, protocols, options) {
     that._trans_url = that._base_url + '/' + that._server + '/' + that._connid;
     that._protocols = ['websocket',
                        'iframe-eventsource',
+                       'iframe-htmlfile',
                        'xhr-polling',
                        'iframe-xhr-polling',
                        'jsonp-polling'];
@@ -137,7 +138,7 @@ SockJS.prototype._try_next_protocol = function(close_event) {
         if (!that.protocol) {
             return false;
         }
-        if (!SockJS[that.protocol] || !SockJS[that.protocol].enabled()) {
+        if (!SockJS[that.protocol] || !SockJS[that.protocol].enabled(that._options)) {
             that._debug('Skipping transport:', that.protocol);
         } else {
             that._debug('Opening transport:', that.protocol);
diff --git a/lib/trans-iframe-htmlfile.js b/lib/trans-iframe-htmlfile.js
new file mode 100644
index 0000000..2c436c6
--- /dev/null
+++ b/lib/trans-iframe-htmlfile.js
@@ -0,0 +1,68 @@
+// This transport generally works in any browser, but will cause a
+// spinning cursor to appear in any browser other than IE.
+// We may test this transport in all browsers - why not, but in
+// production it should be only run in IE.
+
+var HtmlFileIframeTransport = SockJS['iframe-htmlfile'] = function () {
+    var that = this;
+    that.protocol = 'w-iframe-htmlfile';
+    that.i_constructor.apply(that, arguments);
+};
+
+// Inheritance.
+HtmlFileIframeTransport.prototype = new IframeTransport();
+
+var isIeHtmlfileCapable = function() {
+    if ('ActiveXObject' in window) {
+        try {
+            return !!new ActiveXObject('htmlfile');
+        } catch (x) {}
+    }
+    return false;
+};
+
+HtmlFileIframeTransport.enabled = function (options) {
+    // Development or IE  _and_  iframe postWindow working.
+    var ie = isIeHtmlfileCapable();
+    return (options.devel || ie) && IframeTransport.enabled();
+};
+
+
+var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function (ri, trans_url) {
+    utils.polluteGlobalNamespace();
+
+    var that = this;
+    that.ri = ri;
+    that.trans_url = trans_url;
+    that.send_constructor(ajaxSender);
+    that.ie = isIeHtmlfileCapable();
+
+    that.id = 'a' + utils.random_string(6, 26);
+    var iframe_url = trans_url + '/htmlfile?c=' + escape(WPrefix + '.' + that.id);
+    that.is_loaded = false;
+    var callback = function(data) {
+        if (!that.is_loaded) {
+            that.is_loaded = true;
+            that.iframeObj.loaded();
+        }
+        that.ri._didMessage(data);
+    };
+    _window[WPrefix][that.id] = callback;
+
+    that.iframeObj = utils.createIframe(iframe_url, function(e) {
+                                            that.doCleanup();
+                                            that.ri._didClose(1001, "Can't load htmlfile iframe (" + e + ")");
+                                        });
+};
+
+// Inheritnace
+HtmlFileTransport.prototype = new BufferedSender();
+
+HtmlFileTransport.prototype.doCleanup = function() {
+    var that = this;
+    if (that.iframeObj) {
+        that.iframeObj.cleanup();
+        delete _window[WPrefix][that.id];
+    }
+    that.send_destructor();
+};
\ No newline at end of file
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 815e747..62efcbb 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -212,7 +212,7 @@ arrIndexOf = (arr, obj) ->
 
 test_protocol = (protocol) ->
     module(protocol)
-    if not SockJS[protocol] or not SockJS[protocol].enabled()
+    if not SockJS[protocol] or not SockJS[protocol].enabled(client_opts.sockjs_opts)
         test "[unsupported by client]", ->
                 log('Unsupported protocol (by client): "' + protocol + '"')
     else if client_opts.disabled_transports and
@@ -236,6 +236,7 @@ test_protocol = (protocol) ->
 
 protocols = ['websocket',
         'iframe-eventsource',
+        'iframe-htmlfile',
         'xhr-polling',
         'iframe-xhr-polling',
         'jsonp-polling']

-- 
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