[Pkg-javascript-commits] [sockjs-client] 40/434: Few smoketests.

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 0c5620d238ca9d11f6f90cde1010ee681e82bce5
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Tue Aug 2 13:52:13 2011 +0100

    Few smoketests.
---
 README.md             | 10 +++---
 example-latency.html  | 74 --------------------------------------
 index.html            |  3 +-
 lib/sockjs.js         |  2 +-
 smoke-reconnect.html  | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++
 smoke-throughput.html | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 202 insertions(+), 80 deletions(-)

diff --git a/README.md b/README.md
index 32c463d..3c5856c 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
 SockJS
 ======
 
-HTML5 WebSockets-like API for the older browsers.
+Pure JavaScript WebSockets-like API for browsers that don't support
+HTML5 or are running behind a proxy.
 
  * No Flash inside (no need to open port 843 - which often doesn't
    work through proxies, no need to host `crossdomain.xml`)
@@ -23,11 +24,12 @@ Protocol                                          | Browser
 Cross domain XHR - multipart                      | IE 8, Firefox 3.5+, Safari 4+
 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+ (through misbehaving proxy)
-JsonP polling                                     | (fallback)
-
+[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
 [^4]: http://dev.w3.org/html5/eventsource/
+[^5]: https://secure.wikimedia.org/wikipedia/en/wiki/JSONP
+
diff --git a/example-latency.html b/example-latency.html
deleted file mode 100644
index 71486d2..0000000
--- a/example-latency.html
+++ /dev/null
@@ -1,74 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
-  <meta charset="UTF-8" />
-
-  <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
-
-  <script type="text/javascript" src="sockjs.js"></script>
-  <script type="text/javascript" src="static/jquery.min.js"></script>
-
-  <script type="text/javascript" src="config.js"></script>
-
-  <style type="text/css">
-      .cursor {
-        height: 30px;
-        width: 30px;
-        position: absolute;
-        border: 1px solid grey;
-      }
-
-  </style>
-
-</head>
-<body>
-
-  Latency: <code id="latency"></code><br>
-  <code id="logs" style="height:200px; overflow:auto; display: block; border: 1px grey solid;">
-  </code>
-
-<script>
-    sockjs_url += '/echo';
-
-    function log(a) {
-            if ('console' in window && 'log' in window.console) {
-                console.log(a);
-            }
-            $('#logs').append($("<code>").text(a));
-            $('#logs').append($("<br>"));
-            $('#logs').scrollTop($('#logs').scrollTop()+10000);
-      }
-
-
-    var i = 0;
-    var sjs = new SockJS(sockjs_url, ['xhrpolling']);
-    var payload = Array(1024).join('x');
-    function do_send(){
-        sjs.send({t: (new Date()).getTime(), payload:payload})
-    }
-    function send() {
-        i += 1;
-        if (sjs.readyState === SockJS.OPEN) {
-            if( i % 2 == 0)
-                setTimeout(do_send, 500);
-            else
-                do_send();
-        }
-    }
-    sjs.onopen = function() {
-        log('connected ' + sjs.protocol);
-        send();
-    };
-    sjs.onclose = function(e) {
-        log('disconnected ' + e);
-    };
-    sjs.onmessage = function(e) {
-        var msg = e.data;
-        var td = (new Date()).getTime() - msg.t;
-        $('#latency').text('' + td + ' ms');
-        send();
-    };
-</script>
-</body>
-</html>
diff --git a/index.html b/index.html
index 3fc955f..546dfe4 100644
--- a/index.html
+++ b/index.html
@@ -12,7 +12,8 @@
   <ul>
     <li><a href="tests-qunit.html">QUnit tests</a></li>
     <li><a href="example-cursors.html">Cursors example</a></li>
-    <li><a href="example-latency.html">Latency example</a></li>
+    <li><a href="smoke-throughput.html">Smoketest: througput</a></li>
+    <li><a href="smoke-reconnect.html">Smoketest: reconnect</a></li>
   </ul>
 </body>
 </html>
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 1e56e52..e1d72e3 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -106,7 +106,7 @@ SockJS.prototype._try_next_protocol = function(close_event) {
         if (!that.protocol) {
             return false;
         }
-        if (!SockJS[that.protocol].enabled()) {
+        if (!SockJS[that.protocol] || !SockJS[that.protocol].enabled()) {
             that._debug('Skipping transport:', that.protocol);
         } else {
             that._debug('Opening transport:', that.protocol);
diff --git a/smoke-reconnect.html b/smoke-reconnect.html
new file mode 100644
index 0000000..62a1e3d
--- /dev/null
+++ b/smoke-reconnect.html
@@ -0,0 +1,99 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta charset="UTF-8" />
+
+  <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
+
+  <script type="text/javascript" src="sockjs.js"></script>
+  <script type="text/javascript" src="static/jquery.min.js"></script>
+
+  <script type="text/javascript" src="config.js"></script>
+
+  <style type="text/css">
+      .cursor {
+        height: 30px;
+        width: 30px;
+        position: absolute;
+        border: 1px solid grey;
+      }
+  </style>
+
+</head>
+<body>
+<form>
+  <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="iframe-xhr-polling">iframe-xhr-polling</option>
+  <option value="jsonp-polling">jsonp-polling</option>
+  </select>
+  <input type="button" value="Start" id="connect">
+  <input type="button" value="Stop" id="disconnect" disabled="yes">
+</form>
+
+  Connected: <code id="out"></code><br>
+  <code id="logs" style="height:200px; overflow:auto; display: block; border: 1px grey solid;">
+  </code>
+
+<script>
+    sockjs_url += '/echo';
+
+    function log(a) {
+            if ('console' in window && 'log' in window.console) {
+                console.log(a);
+            }
+            $('#logs').append($("<code>").text(a));
+            $('#logs').append($("<br>"));
+            $('#logs').scrollTop($('#logs').scrollTop()+10000);
+      }
+
+    var started = false;
+    var sjs;
+    var i = 0;
+    var protocol;
+    var t0;
+    function onopen() {
+       var td = (new Date()).getTime() - t0;
+       i += 1;
+       $('#out').text(''+i +'  ' + td + ' ms');
+       sjs.close();
+    };
+    function onclose(e) {
+        if (started && e.status === 1000) {
+            t0 = (new Date()).getTime();
+            sjs = new SockJS(sockjs_url, protocol);
+            sjs.onopen = onopen
+            sjs.onclose = onclose;
+        } else {
+            log('[stopped] ' + e);
+            $('#connect').attr('disabled', false);
+            $('#disconnect').attr('disabled', true);
+        }
+    };
+    function onmessage(e) {
+            var msg = e.data;
+            var td = (new Date()).getTime() - msg.t;
+            i += 1;
+            send();
+    };
+
+    $('#connect').click(function() {
+        started = true;
+        log('[starting]');
+        protocol = $('#transport').val() || undefined;
+        onclose({status:1000});
+        $('#connect').attr('disabled', true);
+        $('#disconnect').attr('disabled', false);
+    });
+    $('#disconnect').click(function() {
+        log('[stopping...]');
+        started = false;
+    });
+</script>
+</body>
+</html>
diff --git a/smoke-throughput.html b/smoke-throughput.html
new file mode 100644
index 0000000..0a7434c
--- /dev/null
+++ b/smoke-throughput.html
@@ -0,0 +1,94 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta charset="UTF-8" />
+
+  <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
+
+  <script type="text/javascript" src="sockjs.js"></script>
+  <script type="text/javascript" src="static/jquery.min.js"></script>
+
+  <script type="text/javascript" src="config.js"></script>
+
+  <style type="text/css">
+      .cursor {
+        height: 30px;
+        width: 30px;
+        position: absolute;
+        border: 1px solid grey;
+      }
+  </style>
+
+</head>
+<body>
+<form>
+  <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="iframe-xhr-polling">iframe-xhr-polling</option>
+  <option value="jsonp-polling">jsonp-polling</option>
+  </select>
+  <input type="button" value="Connect" id="connect">
+  <input type="button" value="Disconnect" id="disconnect" disabled="yes">
+</form>
+
+  Latency: <code id="latency"></code><br>
+  <code id="logs" style="height:200px; overflow:auto; display: block; border: 1px grey solid;">
+  </code>
+
+<script>
+    sockjs_url += '/echo';
+
+    function log(a) {
+            if ('console' in window && 'log' in window.console) {
+                console.log(a);
+            }
+            $('#logs').append($("<code>").text(a));
+            $('#logs').append($("<br>"));
+            $('#logs').scrollTop($('#logs').scrollTop()+10000);
+      }
+
+    var sjs;
+    function onopen() {
+            log('connected ' + sjs.protocol);
+            send();
+    };
+    function onclose(e) {
+            log('disconnected ' + e);
+            $('#connect').attr('disabled', false);
+            $('#disconnect').attr('disabled', true);
+    };
+    var payload = Array(4096).join('x');
+    function send() {
+        sjs.send({t: (new Date()).getTime(), payload:payload})
+    };
+    var i = 0;
+    function onmessage(e) {
+            var msg = e.data;
+            var td = (new Date()).getTime() - msg.t;
+            $('#latency').text(''+i +'  ' + td + ' ms');
+            i += 1;
+            send();
+    };
+
+    $('#connect').click(function() {
+        log('[connecting]');
+        $('#connect').attr('disabled', true);
+        $('#disconnect').attr('disabled', false);
+        var t = $('#transport').val() || undefined;
+        sjs = new SockJS(sockjs_url, t);
+        sjs.onopen = onopen
+        sjs.onclose = onclose;
+        sjs.onmessage = onmessage;
+    });
+    $('#disconnect').click(function() {
+        log('[disconnecting]');
+        sjs.close();
+    });
+</script>
+</body>
+</html>

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