Created
November 7, 2017 09:22
-
-
Save wision/813af88cde7a447401924ad72c64ec87 to your computer and use it in GitHub Desktop.
binaryjs using ws module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/client.js b/lib/client.js | |
index ca30634..921bbcb 100644 | |
--- a/lib/client.js | |
+++ b/lib/client.js | |
@@ -2,7 +2,7 @@ | |
var Stream = require('stream').Stream; | |
var EventEmitter = require('events').EventEmitter; | |
var BufferReadStream = require('streamers').BufferReadStream; | |
-var WebSocket = require('streamws'); | |
+var WebSocket = require('ws'); | |
var util = require('./util'); | |
var BinaryStream = require('./stream').BinaryStream; | |
@@ -31,7 +31,7 @@ function BinaryClient(socket, options) { | |
this._socket = socket; | |
} | |
- this._socket.binaryType = 'arraybuffer'; | |
+ this._socket.binaryType = 'nodebuffer'; | |
this._socket.addEventListener('open', function(){ | |
self.emit('open'); | |
diff --git a/lib/server.js b/lib/server.js | |
index 9903941..543f58b 100644 | |
--- a/lib/server.js | |
+++ b/lib/server.js | |
@@ -1,4 +1,4 @@ | |
-var ws = require('streamws'); | |
+var WebSocket = require('ws'); | |
var EventEmitter = require('events').EventEmitter; | |
var util = require('./util'); | |
@@ -18,10 +18,10 @@ function BinaryServer(options) { | |
this._clientCounter = 0; | |
- if (options.server && (options.server instanceof ws.Server)) { | |
+ if (options.server && (options.server instanceof WebSocket.Server)) { | |
this._server = options.server; | |
} else { | |
- this._server = new ws.Server(options); | |
+ this._server = new WebSocket.Server(options); | |
} | |
this._server.on('connection', function(socket){ | |
diff --git a/lib/stream.js b/lib/stream.js | |
index c0c3433..427663e 100644 | |
--- a/lib/stream.js | |
+++ b/lib/stream.js | |
@@ -73,16 +73,14 @@ BinaryStream.prototype._write = function(code, data, bonus) { | |
return false; | |
} | |
var message = util.pack([code, data, bonus]); | |
- return this._socket.send(message) !== false; | |
+ this._socket.send(message, {binary: true}) | |
}; | |
BinaryStream.prototype.write = function(data) { | |
if(this.writable) { | |
- var out = this._write(2, data, this.id); | |
- return !this.paused && out; | |
+ this._write(2, data, this.id); | |
} else { | |
this.emit('error', new Error('Stream is not writable')); | |
- return false; | |
} | |
}; | |
diff --git a/package.json b/package.json | |
index 2ccdf18..c7625c4 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -16,9 +16,9 @@ | |
"node": ">=0.10.20" | |
}, | |
"dependencies": { | |
- "streamws": ">=0.1.1", | |
"binarypack": ">=0.0.4", | |
- "streamers": ">=0.1.0" | |
+ "streamers": ">=0.1.0", | |
+ "ws": "^2.2.0" | |
}, | |
"devDependencies": { | |
"mocha": "~1.3.0", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment