Socket
Book a DemoInstallSign in
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

websockets with the node stream api. works in browser and node

Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
204K
-7.72%
Maintainers
1
Weekly downloads
 
Created
Source

websocket-stream

npm install websocket-stream

use HTML5 websockets the node way -- with streams

in the browser

you can use browserify to package this module for browser use. there is a also pre-made + minified version you can download and use right away called websocket-stream-min.js

var websocket = require('websocket-stream')
var ws = websocket('ws://realtimecats.com')
ws.pipe(somewhereAwesome)

ws is a stream and speaks stream events: data, error and end. 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)

on the server

using the ws module you can make a websocket server and use this module to get websocket streams on the server:

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)
  fs.createReadStream('bigdata.json').pipe(stream)
})

extras

the metadata event has the full websocket event

you can pass in a custom protocol to the constructor as the second argument

require('websocket-stream').WebsocketStream is the raw constructor

BSD LICENSE

Keywords

websocket

FAQs

Package last updated on 17 Nov 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts