websocket-stream
Advanced tools
Comparing version 3.2.1 to 3.3.0
{ | ||
"name": "websocket-stream", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"license": "BSD-2-Clause", | ||
@@ -5,0 +5,0 @@ "description": "Use websockets with the node streams API. Works in browser and node", |
@@ -37,2 +37,8 @@ # websocket-stream | ||
##### `options.binary` | ||
Always convert to `Buffer` in Node.js before sending. | ||
Default: `true` | ||
##### Other options | ||
@@ -39,0 +45,0 @@ |
@@ -20,3 +20,3 @@ | ||
this.on('connection', function(conn) { | ||
this.emit('stream', stream(conn)) | ||
this.emit('stream', stream(conn, opts)) | ||
}) | ||
@@ -23,0 +23,0 @@ } |
@@ -61,3 +61,8 @@ var through = require('through2') | ||
var coerceToBuffer = options.binary || options.binary === undefined | ||
function socketWriteNode(chunk, enc, next) { | ||
if (coerceToBuffer && !(chunk instanceof Buffer)) { | ||
chunk = new Buffer(chunk, 'utf8') | ||
} | ||
socket.send(chunk, next) | ||
@@ -64,0 +69,0 @@ } |
@@ -28,1 +28,23 @@ var ws = require('./') | ||
}) | ||
test('with bare WebSocket, strings as strings', function (t) { | ||
var socket = new WebSocket('ws://localhost:8344') | ||
socket.onmessage = function (e) { | ||
var data = e.data | ||
t.ok(typeof data === 'string', 'data must be a string') | ||
socket.close() | ||
t.end() | ||
} | ||
}) | ||
test('with bare WebSocket, binary only', function (t) { | ||
var socket = new WebSocket('ws://localhost:8345') | ||
socket.onmessage = function (e) { | ||
var data = e.data | ||
t.notOk(typeof data === 'string', 'data must not be a string') | ||
socket.close() | ||
t.end() | ||
} | ||
}) |
@@ -0,1 +1,3 @@ | ||
var http = require('http') | ||
var websocket = require('./') | ||
var echo = require('./echo-server.js') | ||
@@ -6,1 +8,25 @@ | ||
}) | ||
function forBare (opts) { | ||
var server = http.createServer() | ||
websocket.createServer({ | ||
server: server, | ||
binary: opts.binary | ||
}, sendString) | ||
server.listen(opts.port) | ||
function sendString (stream) { | ||
stream.write('hello world') | ||
} | ||
} | ||
forBare({ | ||
port: 8344, | ||
binary: false | ||
}) | ||
forBare({ | ||
port: 8345 | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16933
412
77
3