N2N
Extends:
A peer has an inview and an outview, i.e., tables containing sockets to communicate with remote peers. This module transforms a peer so it can act as a bridge between its direct neighbors. Consequently, these neighbors can create their own communication channels: necessary data to establish the connection travel through the bridge; once the connection is successfully established, they communicate using their own direct connection.
Constructor Summary
Public Constructor | ||
public |
constructor(options: object) |
Member Summary
Public Members | ||
public |
II: * |
|
public |
IO: * |
|
public |
NI: * |
|
public |
NO: * |
|
public |
PEER: * |
|
public |
PID: * |
|
public |
i: * |
|
public |
o: * |
|
public |
options: * |
Method Summary
Public Methods | ||
public |
Create an arc (establishes a WebRTC connection if need be) from 'from' to 'to'. |
|
public |
disconnect(peerId: string) Remove an arc of the outview or all arcs |
|
public |
Getter of the inview. |
|
public |
Getter of the inview ID. |
|
public |
getOutview(): Map Getter of the outview. |
|
public |
Getter of the inview ID. |
|
public |
neighbours(): [Object] Return living neighbours as specified in neighborhood-wrtc |
|
public |
Send a message using either the inview or the outview. |
|
public |
Send a MediaStream using either the inview or the outview. |
|
public |
uniqNeighbours(transform: Boolean): [type] Return an array of uniq reachable peers without distinction between inview or outview (without -I or -O) if you want to send a message to one of these peers, add either a -I or a -I (or pass a boolean as parameter, default false) |
Private Methods | ||
private |
_bridge(peerId: string, msg: MConnectTo | MForwardTo | MForwarded) |
|
private |
_connected(peerId: string, isOutgoing: boolean) |
|
private |
|
|
private |
_disconnected(peerId: string) |
|
private |
|
|
private |
|
|
private |
|
|
private |
|
Public Constructors
public constructor(options: object) source
Params:
Name | Type | Attribute | Description |
options | object |
|
options represented as an object (refer to neighborhood-wrtc for other options). |
options.pid | string |
|
The unique identifier of the protocol. |
options.retry | number |
|
The number of times it tries to send a message. |
options.inview | Neighborhood |
|
The neighborhood used for inviews, i.e., incoming arcs. |
options.outview | Neighborhood |
|
The neigbhorhood used for outviews, i.e., outgoing arcs. |
Public Members
public II: * source
public IO: * source
public NI: * source
public NO: * source
public PEER: * source
public PID: * source
public i: * source
public o: * source
public options: * source
Public Methods
public connect(from: function | MResponse | string | null, to: MRequest | string | null) source
Create an arc (establishes a WebRTC connection if need be) from 'from' to 'to'. (TODO) explain function args
public disconnect(peerId: string) source
Remove an arc of the outview or all arcs
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the arc to remove. |
public neighbours(): [Object] source
Return living neighbours as specified in neighborhood-wrtc
Return:
[Object] | Object containing living inview and living outview entries |
public send(peerId: string, message: object, retry: number): promise source
Send a message using either the inview or the outview.
Return:
promise | Promise that resolves if the message is sent, reject otherwise. |
public stream(peerId: string, media: MediaStream, retry: number): promise source
Send a MediaStream using either the inview or the outview.
Return:
promise | Promise that resolves if the message is sent, reject otherwise. |
public uniqNeighbours(transform: Boolean): [type] source
Return an array of uniq reachable peers without distinction between inview or outview (without -I or -O) if you want to send a message to one of these peers, add either a -I or a -I (or pass a boolean as parameter, default false)
Params:
Name | Type | Attribute | Description |
transform | Boolean |
|
If true, transform final Id into ids that can be used to send messages |
Return:
[type] | [description] |
Private Methods
private _bridge(peerId: string, msg: MConnectTo | MForwardTo | MForwarded) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the peer that sent us the message |
|
msg | MConnectTo | MForwardTo | MForwarded | The message received. |
private _disconnected(peerId: string) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the peer that removed an arc. |