Fix wsproxy to be compatible with node.js v0.10.x
diff --git a/wsproxy/wsproxy-tcp.js b/wsproxy/wsproxy-tcp.js
index 7bdb1c9..8ff84a2 100644
--- a/wsproxy/wsproxy-tcp.js
+++ b/wsproxy/wsproxy-tcp.js
@@ -56,7 +56,7 @@
if (LOG > 1) console.log("Message from clinet: " + message);
}
else if (typeof message == 'object') {
- var bytesView = new Uint8Array(message);
+ var bytesView = new Buffer(message);
if (LOG > 1) {
var logMsg = 'Byte array from client: ';
@@ -66,7 +66,7 @@
}
if (sock_ready) {
- sock.write(bytesView.buffer);
+ sock.write(bytesView);
} else {
send_queue.push(message);
}
@@ -90,7 +90,7 @@
sock.on('data', function(data) {
if (typeof data == 'object') {
- var bytesView = new Uint8Array(data);
+ var bytesView = new Buffer(data);
if (LOG > 1) {
console.log('Byte array from server: ');
@@ -101,7 +101,7 @@
}
if (ws_ready == true) {
- ws.send(bytesView.buffer, {binary: true, mask: false});
+ ws.send(bytesView, {binary: true, mask: false});
}
}
});
diff --git a/wsproxy/wsproxy-udp.js b/wsproxy/wsproxy-udp.js
index db63b82..0a65862 100755
--- a/wsproxy/wsproxy-udp.js
+++ b/wsproxy/wsproxy-udp.js
@@ -99,20 +99,17 @@
});
udp.on('message', function(msg, rinfo) {
- if (typeof msg == 'object') {
- // From Buffer to ArrayBuffer
- var bytesView = new Uint8Array(msg);
-
+ if (msg instanceof Buffer) {
if (LOG > 2) {
console.log('udp.onmessage: Byte array from server: ');
- console.log('udp.onmessage: bytesView.length ' + bytesView.length);
+ console.log('udp.onmessage: msg.length ' + msg.length);
var logMsg = "";
- for (var i = 0; i < bytesView.length; i++)
- logMsg += String.fromCharCode(bytesView[i]);
+ for (var i = 0; i < msg.length; i++)
+ logMsg += String.fromCharCode(msg[i]);
console.log(logMsg);
}
- ws.send(bytesView.buffer, {binary: true, mask: false});
+ ws.send(msg, {binary: true, mask: false});
}
});