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

websocket-stream

Package Overview
Dependencies
Maintainers
3
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 1.2.0 to 1.3.0

server.js

13

echo-server.js

@@ -1,2 +0,1 @@

var WebSocketServer = require('ws').Server
var http = require('http')

@@ -23,11 +22,9 @@ var websocket = require('./')

var wss = new WebSocketServer(opts)
websocket.createServer(opts, echo)
wss.on('connection', function(ws) {
var stream = websocket(ws)
server.listen(port, cb)
stream.pipe(stream) // echo
})
server.listen(port, cb)
function echo(stream) {
stream.pipe(stream)
}
}

@@ -34,0 +31,0 @@

@@ -1,70 +0,6 @@

var through = require('through2')
var duplexify = require('duplexify')
var WS = require('ws')
module.exports = WebSocketStream
var Server = require('./server.js')
function WebSocketStream(target, protocols) {
var stream, socket
var proxy = through(socketWrite, socketEnd)
// use existing WebSocket object that was passed in
if (typeof target === 'object') {
socket = target
// otherwise make a new one
} else {
socket = new WS(target, protocols)
socket.binaryType = 'arraybuffer'
}
// was already open when passed in
if (socket.readyState === 1) {
stream = proxy
} else {
stream = duplexify()
socket.addEventListener("open", onready)
}
stream.socket = socket
socket.addEventListener("close", onclose)
socket.addEventListener("error", onerror)
socket.addEventListener("message", onmessage)
proxy.on('close', destroy)
function socketWrite(chunk, enc, next) {
socket.send(chunk, next)
}
function socketEnd(done) {
socket.close()
done()
}
function onready() {
stream.setReadable(proxy)
stream.setWritable(proxy)
stream.emit('connect')
}
function onclose() {
stream.destroy()
}
function onerror(err) {
stream.destroy(err)
}
function onmessage(event) {
var data = event.data
if (data instanceof ArrayBuffer) data = new Buffer(new Uint8Array(data))
proxy.push(data)
}
function destroy() {
socket.close()
}
return stream
}
module.exports = require('./stream.js')
module.exports.Server = Server
module.exports.createServer = Server
{
"name": "websocket-stream",
"version": "1.2.0",
"version": "1.3.0",
"description": "Use websockets with the node streams API. Works in browser and node",

@@ -26,4 +26,5 @@ "scripts": {

"duplexify": "^3.2.0",
"inherits": "^2.0.1",
"through2": "^0.6.1",
"ws": "^0.4.32",
"ws": "^0.6.5",
"xtend": "^4.0.0"

@@ -38,4 +39,5 @@ },

"browser": {
"./echo-server.js": "./fake-server.js"
"./echo-server.js": "./fake-server.js",
"./index.js": "stream.js"
}
}

@@ -17,3 +17,3 @@ # websocket-stream

In the example above `ws` is a duplex stream. That means you can pipe output to anything that accepts streams. You can also pipe data into streams (such as a webcam feed or audio data).
In the example above `ws` is a duplex stream. That means you can pipe output to anything that accepts streams. You can also pipe data into streams (such as a webcam feed or audio data).

@@ -27,7 +27,6 @@ The underlying `WebSocket` instance is available as `ws.socket`.

```javascript
var WebSocketServer = require('ws').Server
var websocket = require('websocket-stream')
var wss = new WebSocketServer({server: someHTTPServer})
wss.on('connection', function(ws) {
var stream = websocket(ws)
var wss = websocket.createServer({server: someHTTPServer}, handle)
function handle(stream) {
fs.createReadStream('bigdata.json').pipe(stream)

@@ -34,0 +33,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