2.2.0 • Published 5 years ago

peero-server v2.2.0

Weekly downloads
9
License
ISC
Repository
github
Last release
5 years ago

WebSocket server which facilitates discovery between Peero client peers.

What & why

WebRTC peers are unable to connect to each other without exchanging connection data (IP adresses, etc). The way this exchange is performed is not a part of the WebRTC spec, so it's up to the developer to come up with a way to do this. There are already signaling servers which do exactly this, but Peero server is just a different type of implementation that's supposed to be simple and open source.

The only thing the server does is keep a list of online peers, and passes SDP data from one peer to another to make those peers connect. All communication between peers is strictly peer-to-peer. There is also an implementation of a Peero client, which connects to the server and available peers.

Installation

To run the server, you will need to have Node.js and npm installed, so you can:

$ npm install peero-server

Usage

const PeeroServer = require('peero-server')

const server = new PeeroServer({
    port: '80'
})

server.run((port) => {
    console.log('Running on port: ' + port)
})

Options

The constructor accepts the following options:

  • port: The port of the WebSocket server. Default: 8080.

Methods

  • run(callback): Initializes the server. The callback returns the port which has been set in the options.
  • close(callback): Closes the server and exits the process.

Events

The instance emits the following events:

  • on('connection', (socket)): When a client establishes a connection with the server.
  • on('message', (socket, message)): When any WebSocket message is sent to a client.
  • on('offer', (socket, signal)): When an 'offer' signal is sent to all connected clients (except the signaling client).
  • on('answer', (socket, peerId, signal)): When an 'answer' signal is sent to a client. peerId is the ID of the answering client.
  • on('announce', (socket)): When connected clients have been notified of a new connected client.
  • on('peers', (socket, peers)): When the list of connected clients have been sent to a client.
  • on('remove', (peerId)): When a client has been removed from the list of connected clients (due to connectivity issues, for example).
  • on('error', (err, socket)): When a message fails to reach a client (due to connectivity issues, for example). The client is also automatically removed from the list of connected clients when this occurs.
2.2.0

5 years ago

2.1.3

5 years ago

2.1.1

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago