Home Reference Source
import NetworkManager from 'foglet-core/src/network/network-manager.js'
public class | source

NetworkManager

Extends:

* → NetworkManager

A NetworkManager manage several distinct Network instances, i.e. a RPS and a set of overlays, and allow peers to choose which network they want to interact with.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Constructor

Member Summary

Private Members
private
private
private

_rps: *

Method Summary

Public Methods
public

Select and get an overlay to use for communication using its name.

public

registerMiddleware(middleware: Object, priority: Number): void

Register a middleware, with an optional priority

Private Methods
private

_buildOverlay(overlayConfig: OverlayConfig): void

Build and add an overlay

private

_buildOverlays(overlays: OverlayConfig[]): void

Construct all overlays

private

_buildRPS(type: string, options: Object): Network

Construct the RPS by its type and options For the moment(spray-wrtc as default)

private

_chooseRps(type: string, options: Object): function

this method was deprecated. As only Spray is available as RPS, there is only one possible choice...

Get a RPS constructor given its type in string format

Public Constructors

public constructor(options: Object) source

Constructor

Params:

NameTypeAttributeDescription
options Object

Options used to build the networks

options.rps Object

Options used to configure the Random Peer Sampling (RPS) network

options.rps.type string

The type of RPS (spray-wrtc for Spray or fcn-wrtc for a fully connected network over WebRTC)

options.rps.options Object

Options by the type of RPS choosed

options.rps.options.protocol string

Name of the protocol run by the application

options.rps.options.webrtc Object

WebRTC dedicated options (see WebRTC docs for more details)

options.rps.options.timeout number

RPS timeout before definitively close a WebRTC connection

options.rps.options.delta number

RPS shuffle interval

options.rps.options.signaling Object

Options used to configure the interactions with the signaling server

options.rps.options.signaling.address string

URL of the signaling server

options.rps.options.signaling.room string

Name of the room in which the application run

options.overlay Object

Options used to configure custom overlay in addition of the RPS

options.overlay.options Object

Options propagated to all overlays, same as the options field used to configure the RPS.

options.overlay.overlays OverlayConfig[]

Set of config objects used to build the overlays

Private Members

private _options: * source

private _overlays: * source

private _rps: * source

Public Methods

public overlay(name: string): Network source

Select and get an overlay to use for communication using its name. If no name is specified, the base RPS will be returned.

Params:

NameTypeAttributeDescription
name string
  • optional
  • default: null

(optional) Name of the overlay to get. Default to the RPS.

Return:

Network

Return the selected overlay/rps.

public registerMiddleware(middleware: Object, priority: Number): void source

Register a middleware, with an optional priority

Params:

NameTypeAttributeDescription
middleware Object

The middleware to register

middleware.in function

Function applied on middleware input

middleware.out function

Function applied on middleware output

priority Number
  • optional
  • default: 0

(optional) The middleware priority

Return:

void

Private Methods

private _buildOverlay(overlayConfig: OverlayConfig): void source

Build and add an overlay

Params:

NameTypeAttributeDescription
overlayConfig OverlayConfig

Overlay configuration object

Return:

void

Throw:

SyntaxError

Overlay configuration object must be a valid

Error

An overlay with the same name has laready been registered

private _buildOverlays(overlays: OverlayConfig[]): void source

Construct all overlays

Params:

NameTypeAttributeDescription
overlays OverlayConfig[]

Set of overlay config objetcs

Return:

void

private _buildRPS(type: string, options: Object): Network source

Construct the RPS by its type and options For the moment(spray-wrtc as default)

Params:

NameTypeAttributeDescription
type string

Type of the RPS (spray-wrtc/custom/...)

options Object

Options of the RPS

options.protocol string

Name of the protocol run by the RPS

options.signaling Object

Options used to configure the interactions with the signaling server

options.signaling.address string

URL of the signaling server

options.signaling.room string

Name of the room in which the application run

Return:

Network

The constructed RPS

private _chooseRps(type: string, options: Object): function source

this method was deprecated. As only Spray is available as RPS, there is only one possible choice...

Get a RPS constructor given its type in string format

Params:

NameTypeAttributeDescription
type string

RPS type

options Object

Options to pass to the RPS

Return:

function

The RPS constructor