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

websocket-stream

Package Overview
Dependencies
Maintainers
1
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 0.2.0 to 0.3.0

4

binary-server.js

@@ -13,2 +13,4 @@ var WebSocketServer = require('ws').Server

stream.end()
})
})
console.log(':8080')

@@ -18,2 +18,4 @@ var WebSocketServer = require('ws').Server

})
})
})
console.log(':8080')
var websocket = require('./')
var elstreamo = require('el-streamo')
ws = websocket('ws://localhost:8080')
ws = websocket('ws://localhost:8080', {type: Uint8Array})
var elstream = elstreamo.writable('#messages')
ws.on('data', function(c) { console.log(c) })
ws.on('data', function(c) { console.log({foo: c}) })
ws.pipe(elstream)

@@ -22,3 +22,2 @@ var stream = require('stream')

this.ws = new WebSocket(server, this.options.protocol)
this.ws.binaryType = this.options.binaryType || 'arraybuffer'
this.ws.onmessage = this.onMessage.bind(this)

@@ -37,4 +36,10 @@ this.ws.onerror = this.onError.bind(this)

WebsocketStream.prototype.onMessage = function(e, flags) {
if (e.data) return this.emit('data', e.data, flags)
this.emit('data', e, flags)
var data = e
if (data.data) data = data.data
// type must be a Typed Array (ArrayBufferView)
var type = this.options.type
if (type && data instanceof ArrayBuffer) data = new type(data)
this.emit('data', data, flags)
}

@@ -41,0 +46,0 @@

{
"name": "websocket-stream",
"version": "0.2.0",
"version": "0.3.0",
"description": "websockets with the node stream api. works in browser and node",

@@ -5,0 +5,0 @@ "scripts": {

@@ -46,3 +46,5 @@ # websocket-stream

```js
websocketStream('ws://foobar', { binaryType: 'blob' })
websocketStream('ws://foobar', { type: someTypedArray })
// e.g. {type: Uint8Array} means you'll get Uint8Arrays back instead of ArrayBuffers
```

@@ -55,3 +57,3 @@

protocol: // optional, string, specify websocket protocol
binaryType: // optional, string, defaults to 'arraybuffer', can also be 'blob'
type: // optional, TypedArray object, wraps the ArrayBuffer before emitting
}

@@ -58,0 +60,0 @@ ```

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