Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

websocket-stream

Package Overview
Dependencies
Maintainers
5
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-stream - npm Package Compare versions

Comparing version 3.2.1 to 3.3.0

2

package.json
{
"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
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc