# hyperpeer-node
**Repository Path**: mirrors_crs4/hyperpeer-node
## Basic Information
- **Project Name**: hyperpeer-node
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: GPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-08
- **Last Updated**: 2026-02-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# hyperpeer-node
hyperpeer-node is a Node.js module for implementing the signaling server in applications based on Hyperpeer.
This module provides a single class called [`HyperpeerServer`](#HyperpeerServer) which manages the connection,
pairing and WebRTC signals exchange of Hyperpeer peers.
# Example
```js
const HpServer = require('hyperpeer-node')
// Function used to validate and authorize peers
const verifyPeer = function(type, peerId, peerKey) {
const validTypes = new Set(['client', 'advisor', 'media-server'])
const peerIds = new Map([['client01', 'key001'], ['advisor01', 'key002'])
if (!validTypes.has(type)) return false
if (!peerIds.has(peerId)) return false
if (peerKey != peerIds.key(peerId)) return false
return true
}
// Instantiate the Hyperpeer server by automatically creating an HTTP server
const hpServer = new HpServer({ port: 3000, verifyPeer: verifyPeer })
// And that's it
console.log((new Date()) + ' Hyperpeer Server is listening on port 3000')
// Hyperpeer instances are also WebSocket.Server instances so you can listen to its events like the 'connection' event
hpServer.on('connection', () => {
const peers = hpServer.getPeers()
console.log('New peer connection. Connected peers: ' + peers.map((peer) => peer.id))
})
```
# API Reference
## HyperpeerServer ⇐ WebSocket.Server
**Kind**: global class
**Extends**: WebSocket.Server
* [HyperpeerServer](#HyperpeerServer) ⇐ WebSocket.Server
* [new HyperpeerServer(options)](#new_HyperpeerServer_new)
* _instance_
* [.getPeers()](#HyperpeerServer+getPeers) ⇒ [Array.<peer>](#HyperpeerServer..peer)
* _inner_
* [~verifyPeer](#HyperpeerServer..verifyPeer) : function
* [~peer](#HyperpeerServer..peer) : Object
### new HyperpeerServer(options)
Creates an instance of HyperpeerServer which is a wrapper of the [WebSocket.Server](https://github.com/websockets/ws/blob/HEAD/doc/ws.md) class. HyperpeerServer instances manages the connection of peers, the pairing between peers, and relay messages between paired peers.
| Param | Type | Description |
| --- | --- | --- |
| options | object | Websocket server options (see [ ws API](https://github.com/websockets/ws/blob/HEAD/doc/ws.md)) |
| options.verifyPeer | [verifyPeer](#HyperpeerServer..verifyPeer) | A function that can be used to validate peers. If set, it replaces verifyClient attribute of WebSocket.Server |
### hyperpeerServer.getPeers() ⇒ [Array.<peer>](#HyperpeerServer..peer)
Returns the list of connected peers
**Kind**: instance method of [HyperpeerServer](#HyperpeerServer)
### HyperpeerServer~verifyPeer : function
Funcition to verify the connection of a peer
**Kind**: inner typedef of [HyperpeerServer](#HyperpeerServer)
| Param | Type | Description |
| --- | --- | --- |
| peerType | string | Can be used to verify the category of the peer |
| peerId | string | Unique identifier of the peer |
| peerKey | string | Token that can be used to authenticate and authorize the peer |
### HyperpeerServer~peer : Object
Element of the list of peers.
**Kind**: inner typedef of [HyperpeerServer](#HyperpeerServer)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| id | string | id of the peer. |
| type | string | type of the peer. |
| busy | boolean | Indicates whether the peer is paired with another peer. |