Neighborhood
Extends:
Easy-to-use interface to establish multiple WebRTC connections using SimplePeer (npm: simple-peer)
Constructor Summary
Public Constructor | ||
public |
constructor(options: object) |
Member Summary
Public Members | ||
public |
PEER: * |
|
public |
decode: * |
|
public |
dying: * |
|
public |
encode: * |
|
public |
living: * |
|
public |
options: {"socketClass": *, "peer": *, "config": *, "timeout": *, "pendingTimeout": *, "encoding": *, "decoding": *} |
|
public |
pending: * |
Method Summary
Public Methods | ||
public |
Create a WebRTC connection. |
|
public |
disconnect(peerId: string | undefined): * Remove an arc. |
|
public |
neighbours(): [ELiving] return an array of living sockets |
|
public |
Send a message to a remote peer. |
|
public |
|
Private Methods | ||
private |
|
|
private |
_checkPendingEntry(entry: *) |
|
private |
|
|
private |
|
|
private |
_receiveInternalMessage(msg: *) |
|
private |
_sendRenegociateRequest(request: *, to: *, retry: number): * |
|
private |
_sendRenegociateResponse(response: *, to: *, retry: number): * |
Public Constructors
public constructor(options: object) source
Params:
Name | Type | Attribute | Description |
options | object |
|
the options available to the connections, e.g. timeout before |
options.socketClass | object |
|
simple-peer default socket class (usefull if you need to change the type of socket) |
options.config | object |
|
simple-peer options |
options.timeout | number |
|
Time to wait (in milliseconds) for dying socket |
options.pendingTimeout | number |
|
Time to wait (in milliseconds) for pending socket before neighborhood-wrtc assumes that a connection establishment failed, or before an unused connection is removed. |
options.encoding | function |
|
Method to customize message sent, default: return JSON.stringify(data); |
options.decoding | function |
|
Method to decode a received message, default: return JSON.parse(data); |
Public Members
public PEER: * source
public decode: * source
public dying: * source
public encode: * source
public living: * source
public options: {"socketClass": *, "peer": *, "config": *, "timeout": *, "pendingTimeout": *, "encoding": *, "decoding": *} source
public pending: * source
Public Methods
public connect(arg1: function | object, arg2: object): * source
Create a WebRTC connection.
Params:
Name | Type | Attribute | Description |
arg1 | function | object | Either a callback function to send the message to the remote peer (for instance, it can use a signaling server or the already created WebRTC connexions), or a message received from the remote peer. |
|
arg2 | object | The message received from a peer that initialized a WebRTC connection. |
Return:
* |
public disconnect(peerId: string | undefined): * source
Remove an arc. If it was the last arc, the WebRTC connexion is downgraded to the dying table. In this table, the connexion will be closed if none create it.
Return:
* |
public neighbours(): [ELiving] source
return an array of living sockets
Return:
[ELiving] | a living entry with socket, peer id and number of occurences (arcs) |
public send(peerId: string, message: object, retry: number): promise source
Send a message to a remote peer.
Return:
promise | Resolved when the message is sent, reject otherwise. Note that loss of messages is not handled by default. |
public stream(peerId: *, media: *, retry: number): * source
Params:
Name | Type | Attribute | Description |
peerId | * | ||
media | * | ||
retry | number |
|
Return:
* |
Private Methods
private _checkPendingEntry(entry: *) source
Params:
Name | Type | Attribute | Description |
entry | * |
private _finalize(msg: MResponse) source
Params:
Name | Type | Attribute | Description |
msg | MResponse | The message containing an offer, a peerId etc. |
private _receiveInternalMessage(msg: *) source
Params:
Name | Type | Attribute | Description |
msg | * |