webcastjs
v1.0.1
Published
A direct implementation of webcast.js
Downloads
4
Readme
webcastjs
A nodejs implementation of webcast.js
Install
npm i webcastjs
Usage
webcastjs
provides a client and a server
As a client
const { Client } = require('webcastjs')
var client = new Client('ws://localhost:3000', {
// Insert hello object
})
client.sendMeta({
title: 'some random title',
anythingElse: "it's up to you"
})
someArbitraryReadableStream.pipe(client)
new Client(address, hello) extends Writable
Creates a new client object. Client objects can be used as a writable stream.
address
: aws://
address for the serverhello
: a hello object as described here
Client.sendMeta(data)
Broadcast arbitrary metadata
data
: anything
As a server
The webcast Server
is a modification on the standard ws.Server
. Websockets will be emitted like a regular ws.Server
while receiving an error handling filter in compliance with webcast.js specs.
const { Server } = require('webcastjs')
const WebSocket = require('ws')
var server = new Server({ port: 3000 })})
server.on('connection', ws => {
ws.on('hello', hello => {
console.log('Hello', hello)
})
ws.on('close', () => console.log('Closed'))
WebSocket.createWebSocketStream(ws).pipe(process.stdout)
})
new class Server(opts) extends EventEmitter
Creates a new webcast Server
opts
: See WebSocket.Server['Options']
emits connection(ws)
Emits whenever a new connection is successfully established
ws
: the websocket
ws emits
The websocket is modified to emit unique events
hello
: the first hello messagemetadata
: a change in metadataframe
: a valid webcast.js frame