From 40868636dac4267355baf1591decdd30be7580e6 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 6 Oct 2011 16:55:10 -0500 Subject: [PATCH] Link to API page. Default length for rQshift* If no length parameter is given to rQshiftStr or rQshiftBytes, then the all remaining data (the full length) will be shifted off. Also, honor the window.WEB_SOCKET_FORCE_FLASH variable to force web-socket-js to be used even if the browser has native WebSockets support. --- README.md | 3 +++ include/websock.js | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75a2d47..83a1b3d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ not affect the data between websockify and the server. ### Websock Javascript library + The `include/websock.js` Javascript library library provides a Websock object that is similar to the standard WebSocket object but Websock enables communication with raw TCP sockets (i.e. the binary stream) @@ -30,6 +31,8 @@ does not contain actual data but is simply a notification that there is new data available. Several rQ* methods are available to read binary data off of the receive queue. +The Websock API is documented on the [websock.js API wiki page](https://github.com/kanaka/websockify/wiki/websock.js) + See the "Wrap a Program" section below for an example of using Websock and websockify as a browser telnet client (`wstelnet.html`). diff --git a/include/websock.js b/include/websock.js index a688f76..49141c8 100644 --- a/include/websock.js +++ b/include/websock.js @@ -17,9 +17,9 @@ // Load Flash WebSocket emulator if needed -if (window.WebSocket) { +if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) { Websock_native = true; -} else if (window.MozWebSocket) { +} else if (window.MozWebSocket && !window.WEB_SOCKET_FORCE_FLASH) { Websock_native = true; window.WebSocket = window.MozWebSocket; } else { @@ -115,6 +115,7 @@ function rQshift32() { (rQ[rQi++] ); } function rQshiftStr(len) { + if (typeof(len) === 'undefined') { len = rQlen(); } var arr = rQ.slice(rQi, rQi + len); rQi += len; return arr.map(function (num) { @@ -122,6 +123,7 @@ function rQshiftStr(len) { } function rQshiftBytes(len) { + if (typeof(len) === 'undefined') { len = rQlen(); } rQi += len; return rQ.slice(rQi-len, rQi); }