Skip to main content Link Search Menu Expand Document (external link)

API

Table of contents

  1. IceServer
  2. Node
    1. Constructor
    2. Properties
    3. Methods
      1. onMessageReceived()
      2. onConnectedToNetwork()
      3. onDisconnectedFromNetwork()
      4. onConnectedToPeer()
      5. onNetworkChange()
      6. connectToPeer()
      7. sendData()

IceServer

An interface to describe the format of the TURN server configuration.

Signature

export interface IceServer {
    username?: string,
    credential?: string,
    urls: string[]
}

Node

A node on the network.

Constructor

Signature

 constructor(iceServers?: IceServer[])

Parameters

Parameter Type Description
iceServers IceServer The urls of the ice servers to be used for TURN services.

Properties

Property Type Description
address string The address of the node on the network.
networkTopography Map<string, Set<string>> The current network topography as seen by the node.
neighbours string[] The nodes this node is directly connected to.

Methods

onMessageReceived()

Set the callback to execute when a message is received.

onMessageReceived(callback: (source: string, msg: any) => void): void
Parameters
Parameter Type Description
callback (source: string, msg: any) => void The callback to execute.

onConnectedToNetwork()

Set the callback to execute when the node is connected to a network.

onConnectedToNetwork(callback: (address: string) => void): void
Parameters
Parameter Type Description
callback (address: string) => void The callback to execute.

onDisconnectedFromNetwork()

Set the callback to execute when the node is disconnected from the network.

onMessageReceived(callback: (source: string, msg: any) => void): void
Parameters
Parameter Type Description
callback (source: string, msg: any) => void The callback to execute.

onConnectedToPeer()

Set the callback to execute when the node is connected to another node.

onConnectedToPeer(callback: (address: string) => void): void
Parameters
Parameter Type Description
callback (address: string) => void The callback to execute.

onNetworkChange()

Set the callback to execute when there is a change in network topology.

onNetworkChange(callback: () => void): void
Parameters
Parameter Type Description
callback () => void The callback to execute.

connectToPeer()

Connect to the node with the given address.

connectToPeer(address: string): void
Parameters
Parameter Type Description
address string The address of the node.

sendData()

Send data over the network to the node with the given address.
When no destination address is given, the data will be broadcasted over the network.

sendData(data: any, destinationAddress?: string): void
Parameters
Parameter Type Description
data any The data to send over the network.
destinationAddress optional string The address of the node to send the data to.

Copyright © 2019 Tom Van Eyck. Distributed by a MIT license.