Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better websocket detection

  • Loading branch information...
commit fcc67990e1251b8cc7b75cb2fc0c703174b3e599 1 parent d1b00c4
Claudio Cicali authored

Showing 3 changed files with 28 additions and 4 deletions. Show diff stats Hide diff stats

  1. +4 1 bin/jecho
  2. +23 2 lib/JechoClient.js
  3. +1 1  package.json
5 bin/jecho
@@ -32,7 +32,7 @@ try {
32 32 process.exit(1);
33 33 }
34 34
35   -var version = "0.2.1";
  35 +var version = "0.2.2";
36 36
37 37 program
38 38 .version(version)
@@ -253,6 +253,9 @@ function main() {
253 253 var d = new Date();
254 254 d = d.toString().match(/\d+:\d+:\d+/)[0].color('white').color("bold") + ("." + d.getMilliseconds().padZero(3)).color('white');
255 255
  256 + if (typeof text != "string") {
  257 + text = "" + text;
  258 + }
256 259 util.print((useNL ? "\n" : "") + d + " - " + subject.color("cyan") + " " + dir.color("bgyellow").color("black") + " " + text.replace(/\\n/g, "\n").color("yellow") + "\n");
257 260
258 261 clearTimeout(prompto);
25 lib/JechoClient.js
@@ -13,6 +13,27 @@ var JechoClient = {
13 13
14 14 buffer: [],
15 15
  16 + supportsWebSockets: function() {
  17 +
  18 + if (typeof(WebSocket) != "function") {
  19 + return false;
  20 + }
  21 +
  22 + var UA = window.navigator.userAgent.toLowerCase();
  23 +
  24 + if (/chrome|firefox/.test(UA)) {
  25 + return true;
  26 + }
  27 +
  28 + // Supports WebSockets on Android WebViews and Default Browser only if the OS version is > 4.3
  29 + var test = UA.match(/android\s(\d)\.(\d)/);
  30 + if (test && parseInt(test[1], 10) < 4 || (parseInt(test[1], 10) > 3 && parseInt(test[2], 10) < 4)) {
  31 + return false;
  32 + }
  33 +
  34 + return true;
  35 + },
  36 +
16 37 init: function() {
17 38
18 39 var _self = this;
@@ -28,9 +49,9 @@ var JechoClient = {
28 49 return false;
29 50 }
30 51
31   - if ( !this.useXHR && typeof(WebSocket) != "function" ) {
  52 + if ( !this.useXHR && !this.supportsWebSockets() ) {
32 53 this.useXHR = true;
33   - this.send('e', "WebSockets not supported. Falling back to XHR.");
  54 + this.send('e', "Client does not support WebSockets: falling back to XHR.");
34 55 }
35 56
36 57 if (!this.useXHR) {
2  package.json
... ... @@ -1,6 +1,6 @@
1 1 {
2 2 "name": "jecho",
3   - "version": "0.2.1",
  3 + "version": "0.2.2",
4 4 "description": "JavaScript remote web debugging tool",
5 5 "author": "Claudio Cicali <claudio.cicali@gmail.com>",
6 6 "main": "jecho.js",

0 comments on commit fcc6799

Please sign in to comment.
Something went wrong with that request. Please try again.