Manual Reference Source Test
import {WebGroup} from 'netflux/src/WebChannelFacade.js'
public class | source

WebGroup

This class is an API starting point. It represents a peer to peer network, simply called a group. Each group member can send/receive broadcast as well as personal messages, invite other persons or bots (see Bot).

Example:

// Create a WebGroup with full mesh topology, autorejoin feature and
// specified Signaling and ICE servers for WebRTC.

const wg = new WebGroup({
  signalingServer: 'wss://mysignaling.com',
  rtcConfiguration: {
    iceServers: [
      {
        urls: 'stun.l.google.com:19302'
      },
      {
        urls: ['turn:myturn.com?transport=udp', 'turn:myturn?transport=tcp'],
        username: 'user',
        password: 'password'
      }
    ]
  }
})

wg.onMemberJoin = (id) => {
  // YOUR CODE...
}
wg.onMemberLeave = (id) => {
  // YOUR CODE...
}
wg.onMessage = (id, data) => {
  // YOUR CODE...
}
wg.onStateChange = (state) => {
  // YOUR CODE...
}
wg.onSignalingStateChange = (state) => {
  // YOUR CODE...
}

Test:

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

autoRejoin: boolean

Enable/Desable the auto rejoin feature.

public

id: number

The read-only WebGroup identifier.

public

key: string

The read-only group session identifier.

public

members: number[]

The read-only array of all members including yourself (i.e.

public

myId: number

The read-only your unique member identifier in the group.

public

neighbors: number[]

The read-only array of neighbor members (i.e.

public

onMemberJoin: function(id: number)

This handler is called when a new member with id as identifier has joined the group.

public

onMemberLeave: function(id: number)

This handler is called when a member with id as identifier hes left the group.

public

onMessage: function(id: number, data: DataType)

This handler is called when a message has been received from the group.

public

onMyId: function(myId: number)

This handler is called when myId is set.

public

This handler is called when the signaling state has changed.

public

onStateChange: function(state: WebGroupState)

This handler is called when the group state has changed.

public

signalingServer: string

The read-only signaling server URL.

public

The read-only state of the signaling server.

public

The read-only state of the WebGroup connection.

public

The read-only property which is an enum of type Topology indicating the topology used for this WebGroup instance.

Method Summary

Public Methods
public

invite(url: string)

Invite a bot server to join this group.

public

join(key: string)

Join the group identified by a key provided by one of the group member.

public

leave()

Leave the group which means close channels with all members and connection with the Signaling server.

public

send(data: DataType)

Broadcast a message to the group.

public

sendTo(id: number, data: DataType)

Send a message to a particular group member.

Public Constructors

public constructor(options: WebGroupOptions) source

Params:

NameTypeAttributeDescription
options WebGroupOptions
  • optional
options.topology Topology
  • optional
  • default: Topology.FULL_MESH
options.signalingServer string
  • optional
  • default: 'wss://signaling.netflux.coedit.re'
options.rtcConfiguration RTCConfiguration
  • optional
  • default: {iceServers: [{urls: 'stun:stun3.l.google.com:19302'}]}
options.autoRejoin boolean
  • optional
  • default: true

Test:

Public Members

public neighbors: number[] source

The read-only array of neighbor members (i.e. members who are directly connected to you). Hence they are included in the WebGroup#members by definition.

Public Methods

public invite(url: string) source

Invite a bot server to join this group.

Params:

NameTypeAttributeDescription
url string

Bot server URL (See BotOptions)

Test:

public join(key: string) source

Join the group identified by a key provided by one of the group member. If the current WebGroup#state value is not WebGroupState#LEFT or WebGroup#signalingState value is not SignalingState.CLOSED, then do nothing.

Params:

NameTypeAttributeDescription
key string
  • optional

Will be generated if not provided

Test:

public leave() source

Leave the group which means close channels with all members and connection with the Signaling server.

Test: