Constructor
new WebRTCClient(signallingServeropt)
Creates a new instance of WebRTCClient.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
signallingServer |
Object |
<optional> |
null | A reference to the signalling server or mechanism for this instance to use during connection attempts and negotiations. If null, the router property must be set manually prior to attempting a connection. |
- Source:
Extends
Members
(readonly) channelName
Properties:
Name | Type | Default | Description |
---|---|---|---|
channelName |
String | "p2pchannel" | The default data channel name used by this instance. |
- Source:
(readonly) connectionConfig
Properties:
Name | Type | Description |
---|---|---|
connectionConfig |
Object | A RTCPeerConnection configuration
object used to configure the instance. |
- Source:
(readonly) dataChannel
Properties:
Name | Type | Description |
---|---|---|
dataChannel |
RTCDataChannel | The main data channel used to communicate
with a connected peer. Returns null if no data channel has been established. |
- Source:
(readonly) iceServers
Properties:
Name | Type | Description |
---|---|---|
iceServers |
Array | RTCIceServer | An indexed list of ICE/STUN servers
to use when creating a new connection. Additional servers: https://gist.github.com/zziuni/3741933 http://olegh.ftp.sh/public-stun.txt https://gist.github.com/mondain/b0ec1cf5f60ae726202e |
- Source:
(readonly) peerConnection
Properties:
Name | Type | Default | Description |
---|---|---|---|
peerConnection |
RTCPeerConnection | null | The peer connection object being
used by this instance. This property is set either when createPeerConnection
is invoked or when setRemoteDescription is invoked. Returns null
if no connection object currently exists. |
- Source:
peerPID
Properties:
Name | Type | Description |
---|---|---|
peerID |
String | The private ID of the remote peer to which this instance is connecting or connected. |
- Source:
router
Properties:
Name | Type | Default | Description |
---|---|---|---|
router |
Object | null | The P2P router instance to use as a signalling mechanism for exchanging messages during connection and negotiation attempts. |
- Source:
Methods
addEventListener(type, listener, contextopt)
Registers a new event listener with the extending class instance.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String | The event type to register. | ||
listener |
function | The listening function to invoke on the event. | ||
context |
Object |
<optional> |
null | Unlike the traditional addEventListener parameter, this is
the context or scope in which to invoke the listening function (since we can't use capture phases).
If null, the listener is invoked in the context of the EventDispatcher or extending instance. |
- Inherited From:
- Source:
(async) broadcast(data, excludeRecipientsopt) → {Promise}
Sends a peer-to-peer "broadcast" message to the connected peer.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
* | The data / message to broadcast. | ||
excludeRecipients |
Object | Array |
<optional> |
null | NOT CURRENTLY IMPLEMENTED. |
- Source:
- To Do:
-
- Update functionality to support message signing and forwarding for peer-to-peer meshes
Returns:
An asynchronous Promise that will contain the result of
the send or reject with an
Error
object on failure.
- Type
- Promise
buildSignalMessage(messageType) → {Object}
Builds a WebRTCClient signalling message.
Parameters:
Name | Type | Description |
---|---|---|
messageType |
String | The signalling message type to create. |
- Source:
Returns:
A signalling message object containing the
webRTCSignalMsg
property which contains the message type.
- Type
- Object
(async) changePrivateID(newPrivateID) → {Promise}
Changes the private ID associated with this connection. Any attached
peer is notified of this changed via a
session
message.
Parameters:
Name | Type | Description |
---|---|---|
newPrivateID |
String | The new private ID to set for this connection. |
- Source:
Returns:
The promise resolves with
true
if the private
ID was successfully changed, otherwise it rejects with false
.
- Type
- Promise
(async) connect(privateID, configopt)
Attempts to establish a direct peer connection over WebRTC.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
privateID |
String | The private ID of the peer to connect to, as assigned by the P2PRouter or other external ID manager. | ||
config |
Object |
<optional> |
null | A RTCPeerConnection configuration object. If omitted or null, the connectionConfig object is used. |
- Source:
createMessageSentEvent() → {Event}
Creates a message-sent response event that mimics one received
when messages are sent to peers over WebSocket Sessions.
- Source:
Returns:
A message-sent event mimicking that received from
a WebSocket Sessions server after a peer message was sent.
- Type
- Event
(async) disconnect()
Disconnects the WebRTC client connection and removes any event listeners.
- Source:
getListeners(type) → {Array}
Returns all registered listeners for a specific event type.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | The event type to return registered listeners for. |
- Inherited From:
- Source:
Returns:
A list of registered event listener objects for the specific event.
Each object contains a
listener
function reference and an
execution context
reference.
- Type
- Array
removeEventListener(type, listener, contextopt)
Removes an event listener from the extending instance.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String | The event type to remove the function from. | ||
listener |
function | The listening function to remove. | ||
context |
Object |
<optional> |
null | The context or scope in which the listener exists. |
- Inherited From:
- Source:
request(requestObj) → {Promise}
Sends an API request using the dataChannel.
NOT YET IMPLEMENTED
Parameters:
Name | Type | Description |
---|---|---|
requestObj |
Object | The JSON-RPC 2.0 request to send. |
- Source:
Returns:
An asynchronous promise that will resolve with the JSON-RPC 2.0
API response.
- Type
- Promise
(async) send(data, recipients) → {Promise}
Sends a peer-to-peer "direct" message to the connected peer.
Parameters:
Name | Type | Default | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
* | The data / message to send. | |||||||||
recipients |
Object | Array | null | An object or an array of recipient private
IDs. If this parameter is an object, one or more additional properties are
expected:
Properties
|
- Source:
- To Do:
-
- Update functionality to support message signing and forwarding for peer-to-peer meshes.
Returns:
An asynchronous Promise that will contain the result of
the send or reject with an
Error
object on failure.
- Type
- Promise
sendSignalMessage(messageType, dataopt, internal)
Sends a signalling message to the potential peer using the P2PRouter.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
messageType |
String | The type of signalling message to send. See the onSignalMessage function for supported message types. | ||
data |
* |
<optional> |
null | Optional data to include with the signalling message. |
internal |
Boolean | true | If true, the message is handled by this WebRTCClient instance. If false, it's handled by the P2PRouter instance (typically this is just the negotiation-start message). |
- Source:
sendUpdate(data)
Sends a peer-originating "update" message to the connected peer,
mimicking an API server "update" message.
Parameters:
Name | Type | Description |
---|---|---|
data |
String | Object | The message to send. If the message is not a string it is stringified into JSON string data. |
- Source:
- To Do:
-
- Test this functionality
Events
answer
A received answer generated by an responding peer has been received and processed.
Type:
- Event
Properties:
Name | Type | Description |
---|---|---|
answer |
Object | The received answer generated by the responding peer. |
- Source:
icecandidate
An ICE candidate has been received from one of the STUN servers,
Type:
- Event
Properties:
Name | Type | Description |
---|---|---|
candidate |
RTCIceCandidate | The received candidate. |
description |
RTCSessionDescription | The local session description including
the candidate data. |
- Source:
message
The data channel (dataChannel) has received a message from a
connected peer.
Type:
- Event
Properties:
Name | Type | Description |
---|---|---|
message |
* | The received message. |
- Source:
offer
A received offer generated by an initiating peer has been received, processed,
and an answer has been generated.
Type:
- Event
Properties:
Name | Type | Description |
---|---|---|
offer |
Object | The received offer as sent by the initiating peer. |
answer |
Object | The generated answer. |
- Source:
peerconnect
The data channel (dataChannel) has been successfully connected and
bi-directional communication can now take place (e.g. using the sendMessage
function).
Type:
- Event
- Source:
peerdisconnect
The peer connection (peerConnection) or data channel (dataChannel)
has disconnected.
Type:
- Event
- Source:
privateid
The private ID of this connection has changed and a notification
has been sent to the connected peer.
Type:
- Event
Properties:
Name | Type | Description |
---|---|---|
privateID |
String | The new private ID for this connection. |
- Source:
remotechannel
The data channel (dataChannel) created by the initiating peer has been created
locally. Note that this even will not be dispatched if this instance is the initiating peer.
Type:
- Event
- Source: