1.0.1 • Published 4 years ago

webcastjs v1.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

webcastjs

npm bundle size npm GitHub issues NPM GitHub stars npm

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: a ws:// address for the server
  • hello: 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

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 message
  • metadata: a change in metadata
  • frame: a valid webcast.js frame
1.0.1

4 years ago

1.0.0

4 years ago