Giter Club home page Giter Club logo

node-wrtc-ws-api-server's Introduction

Node WebRTC WebSocket Signaling API Server

Build Status Coverage Status

Installation

npm install giovannicalo/node-wrtc-ws-api-server

Not yet published to NPM. This will install it from GitHub.

Usage

const Server = require("wrtc-ws-api-server");

new Server(8080);

API

new Server(port: number, options?: Options)

Starts a WebSocket server listening on port.

Options are:

  • authenticate?(data: JsonSerializable): boolean | Promise<boolean>: a function to authenticate clients, which must return true if valid and false if not, defaults to undefined.
  • heartbeatGracePeriod?: number: how long to keep unresponsive clients alive, in milliseconds, should be greater than heartbeatInterval, defaults to 15000.
  • heartbeatInterval?: number: how often to send ping events to clients, in milliseconds, should be less than heartbeatGracePeriod, defaults to 5000.
  • log?(level: "error" | "info" | "warning", message: string): void: a logging function that will be called when certain events occur, defaults to undefined.
  • socketOptions?: WebSocket.ServerOptions: custom options to pass to the WebSocketServer constructor, except port.

authenticate?: (data: JsonSerializable) => boolean | Promise<boolean>

The authenticate function passed to the Server constructor.

clients: Map<string, Client>

A Map of Client objects, one for each client connected to the server.

close(): void

Shuts down the server.

heartbeatGracePeriod: number

The value of heartbeatGracePeriod, passed to the Server constructor.

heartbeatInterval: number

The value of heartbeatInterval, passed to the Server constructor.

log?: (level: "error" | "info" | "warning", message: string) => void

The log function passed to the Server constructor.

socket: WebSocketServer

The WebSocketServer instance used by the Server.

Client

Each of the clients connected to the Server.

Clients cannot be created manually, but they can be accessed via Server.clients.

address: string

The Client's IP address.

addClient(client: Client): void

Assigns a client Client to the current Client. Only makes sense for worker Clients. It should not be used manually.

chooseWorker(): void

Forces the Client to choose a worker Client. Only makes sense for client Clients. It should not be used manually.

clients: Map<string, Client>

A Map of client Clients assigned to the current Client. Only makes sense for worker Clients.

close(): void

Closes the Client's connection.

firstSeen: number

The time at which the Client connected.

id: string

The Client's ID.

lastSeen: number

The time at which the Client last sent a message (pong or otherwise).

latency: number

The Client's latency, in milliseconds, sampled every heartbeatInterval milliseconds using ping events.

removeClient(client: Client): void

Removes a client Client from the current Client. Only makes sense for worker Clients. It should not be used manually.

removeWorker(): void

Removes the worker Client assigned to the current Client. Only makes sense for client Clients. It should not be used manually.

role: "client" | "worker"

The Client's role.

send(message: JsonSerializable): void

Sends a message to the client.

worker: Client | null

The worker Client used by the current Client. Only makes sense for client Clients.

node-wrtc-ws-api-server's People

Contributors

giovannicalo avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.