Home Manual Reference Source Repository
import WebChannel from 'netflux/src/WebChannel.js'
public class | source

WebChannel

This class is an API starting point. It represents a group of collaborators also called peers. Each peer can send/receive broadcast as well as personal messages. Every peer in the WebChannel can invite another person to join the WebChannel and he also possess enough information to be able to add it preserving the current WebChannel structure (network topology).

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

Unique WebChannel identifier.

public

An array of all peer ids except this.

public

Unique peer identifier of you in this WebChannel.

public

onClose: function(closeEvt: CloseEvent)

Is the event handler called when the WebChannel has been closed.

public

onMessage: function(id: number, msg: UserMessage, isBroadcast: boolean)

Is the event handler called when a message is available on the WebChannel.

public

Is the event handler called when a new peer has joined the WebChannel.

public

Is the event handler called when a peer hes left the WebChannel.

Method Summary

Public Methods
public

close()

Prevent clients to join the WebChannel even if they possesses a key.

public

Get the data allowing to join the WebChannel.

public

Invite a peer to join the WebChannel.

public

If the WebChannel is open, the clients can join it through you, otherwise it is not possible.

public

join(keyOrSocket: string | WebSocket, url: string): Promise<undefined, string>

Join the WebChannel.

public

leave()

Leave the WebChannel.

public

open(options: Object): Promise

Enable other peers to join the WebChannel with your help as an intermediary peer.

public

Get the ping of the WebChannel.

public

send(data: UserMessage)

Send the message to all WebChannel members.

public

sendTo(id: number, data: UserMessage)

Send the message to a particular peer in the WebChannel.

Public Constructors

public constructor(settings: WebChannelSettings) source

Params:

NameTypeAttributeDescription
settings WebChannelSettings

Web channel settings

Public Members

public id: number source

Unique WebChannel identifier. Its value is the same for all WebChannel members.

public members: number[] source

An array of all peer ids except this.

public myId: number source

Unique peer identifier of you in this WebChannel. After each join function call this id will change, because it is up to the WebChannel to assign it when you join.

public onClose: function(closeEvt: CloseEvent) source

Is the event handler called when the WebChannel has been closed.

public onMessage: function(id: number, msg: UserMessage, isBroadcast: boolean) source

Is the event handler called when a message is available on the WebChannel.

public onPeerJoin: function(id: number) source

Is the event handler called when a new peer has joined the WebChannel.

public onPeerLeave: function(id: number) source

Is the event handler called when a peer hes left the WebChannel.

Public Methods

public close() source

Prevent clients to join the WebChannel even if they possesses a key.

public getOpenData(): OpenData | null source

Get the data allowing to join the WebChannel. It is the same data which WebChannel#open callback function provides.

Return:

OpenData | null

Data to join the WebChannel or null is the WebChannel is closed

public invite(keyOrSocket: string | WebSocket): Promise<undefined, string> source

Invite a peer to join the WebChannel.

Params:

NameTypeAttributeDescription
keyOrSocket string | WebSocket

public isOpen(): boolean source

If the WebChannel is open, the clients can join it through you, otherwise it is not possible.

Return:

boolean

True if the WebChannel is open, false otherwise

public join(keyOrSocket: string | WebSocket, url: string): Promise<undefined, string> source

Join the WebChannel.

Params:

NameTypeAttributeDescription
keyOrSocket string | WebSocket

The key provided by one of the WebChannel members or a socket

url string
  • optional
  • default: this.settings.signalingURL

Server URL

Return:

Promise<undefined, string>

It resolves once you became a WebChannel member.

public leave() source

Leave the WebChannel. No longer can receive and send messages to the group.

public open(options: Object): Promise source

Enable other peers to join the WebChannel with your help as an intermediary peer.

Params:

NameTypeAttributeDescription
options Object
  • optional

Any available connection service options

Return:

Promise

It is resolved once the WebChannel is open. The callback function take a parameter of type SignalingGate~AccessData.

public ping(): Promise source

Get the ping of the WebChannel. It is an amount in milliseconds which corresponds to the longest ping to each WebChannel member.

Return:

Promise

public send(data: UserMessage) source

Send the message to all WebChannel members.

Params:

NameTypeAttributeDescription
data UserMessage

Message

public sendTo(id: number, data: UserMessage) source

Send the message to a particular peer in the WebChannel.

Params:

NameTypeAttributeDescription
id number

Id of the recipient peer

data UserMessage

Message