Skip to content
Browse files

Proxy more methods to socket, and some properties as well

  • Loading branch information...
1 parent 1ed2a02 commit bb9ec833149f373d1b73d827109e171726969a20 @fictorial fictorial committed
Showing with 42 additions and 4 deletions.
  1. +42 −4 lib/websocket.js
View
46 lib/websocket.js
@@ -66,6 +66,7 @@ exports.createServer = function (on_connect) {
socket.write('\u0000', 'binary');
socket.write(data, 'utf8');
socket.write('\u00ff', 'binary');
+ return true;
} catch(e) {
e.message = e.message;
sys.debug(sys.inspect(e));
@@ -77,12 +78,49 @@ exports.createServer = function (on_connect) {
throw e;
}
}
+ return false;
};
- websocket.end = function () {
- socket.end();
- };
- socket.setEncoding("utf8");
+ // Must set encoding to UTF-8 for handshake, else
+ // the 'data' callback receives a buffer.Buffer object.
+
+ socket.setEncoding('utf8');
+
+ [ "resume"
+ , "pause"
+ , "setTimeout"
+ , "setNoDelay"
+ , "setEncoding"
+ , "end"
+ ].forEach(function (toProxy) {
+ websocket[toProxy] = function () {
+ net.Stream.prototype[toProxy].apply(socket, arguments);
+ };
+ });
+
+ Object.defineProperty(websocket, 'readyState', {
+ get: function () {
+ return socket.readyState;
+ }
+ });
+
+ Object.defineProperty(websocket, 'remoteAddress', {
+ get: function () {
+ return socket.remoteAddress;
+ }
+ });
+
+ Object.defineProperty(websocket, 'writable', {
+ get: function () {
+ return socket.writable;
+ }
+ });
+
+ Object.defineProperty(websocket, 'readable', {
+ get: function () {
+ return socket.readable;
+ }
+ });
socket.addListener('data', function (data) {
var matches, chunks;

0 comments on commit bb9ec83

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