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.1.0 to 0.2.0

28

index.js

@@ -11,2 +11,4 @@ var stream = require('stream')

this.writable = true
this._buffer = []
if (typeof server === "object") {

@@ -18,2 +20,3 @@ this.ws = server

this.ws.on('open', this.onOpen.bind(this))
if (this.ws.readyState === 1) this._open = true
} else {

@@ -44,2 +47,3 @@ this.ws = new WebSocket(server, this.options.protocol)

WebsocketStream.prototype.onClose = function(err) {
if (this._destroy) return
this.emit('end')

@@ -49,7 +53,22 @@ }

WebsocketStream.prototype.onOpen = function(err) {
if (this._destroy) return
this._open = true
for (var i = 0; i < this._buffer.length; i++) {
this._write(this._buffer[i])
}
this._buffer = undefined
this.emit('open')
this.emit('connect')
if (this._end) this.ws.close()
}
WebsocketStream.prototype.write = function(data) {
if (!this._open) {
this._buffer.push(data)
} else {
this._write(data)
}
}
WebsocketStream.prototype._write = function(data) {
typeof WebSocket != 'undefined' && this.ws instanceof WebSocket

@@ -60,4 +79,11 @@ ? this.ws.send(data)

WebsocketStream.prototype.end = function() {
WebsocketStream.prototype.end = function(data) {
if (data !== undefined) this.write(data)
if (this._open) this.ws.close()
this._end = true
}
WebsocketStream.prototype.destroy = function() {
this._destroy = true
this.ws.close()
}

2

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

@@ -14,3 +15,2 @@ "scripts": {

],
"version": "0.1.0",
"_npmUser": {

@@ -17,0 +17,0 @@ "name": "maxogden",

@@ -19,2 +19,10 @@ # websocket-stream

### browserify steps
```javascript
npm install -g browserify // install browserify
cd node_modules/websocket-stream
npm install . // install dev dependencies
browserify index.js -s websocket-stream > websocket-stream.js // require websocket-stream.js in your client-side app
```
# on the server

@@ -21,0 +29,0 @@

Sorry, the diff of this file is not supported yet

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