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 |
constructor(settings: WebChannelSettings) |
Member Summary
Public Members | ||
public |
Unique |
|
public |
An array of all peer ids except this. |
|
public |
Unique peer identifier of you in this |
|
public |
Is the event handler called when the |
|
public |
onMessage: function(id: number, msg: UserMessage, isBroadcast: boolean) Is the event handler called when a message is available on the |
|
public |
onPeerJoin: function(id: number) Is the event handler called when a new peer has joined the |
|
public |
onPeerLeave: function(id: number) Is the event handler called when a peer hes left the |
Method Summary
Public Methods | ||
public |
close() Prevent clients to join the |
|
public |
getOpenData(): OpenData | null Get the data allowing to join the |
|
public |
Invite a peer to join the |
|
public |
If the |
|
public |
Join the |
|
public |
leave() Leave the |
|
public |
Enable other peers to join the |
|
public |
Get the ping of the |
|
public |
send(data: UserMessage) Send the message to all |
|
public |
sendTo(id: number, data: UserMessage) Send the message to a particular peer in the |
Public Constructors
public constructor(settings: WebChannelSettings) source
Params:
Name | Type | Attribute | Description |
settings | WebChannelSettings | Web channel settings |
Public Members
public id: number source
Unique WebChannel
identifier. Its value is the same for all WebChannel
members.
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 Methods
public getOpenData(): OpenData | null source
Get the data allowing to join the WebChannel
. It is the same data which
WebChannel#open callback function provides.
public invite(keyOrSocket: string | WebSocket): Promise<undefined, string> source
Invite a peer to join the WebChannel
.
public isOpen(): boolean source
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> source
Join the WebChannel
.
public open(options: Object): Promise source
Enable other peers to join the WebChannel
with your help as an
intermediary peer.
Params:
Name | Type | Attribute | Description |
options | Object |
|
Any available connection service options |
Return:
Promise | It is resolved once the |
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.
public send(data: UserMessage) source
Send the message to all WebChannel
members.
Params:
Name | Type | Attribute | Description |
data | UserMessage | Message |
public sendTo(id: number, data: UserMessage) source
Send the message to a particular peer in the WebChannel
.
Params:
Name | Type | Attribute | Description |
id | number | Id of the recipient peer |
|
data | UserMessage | Message |