new P2PClient(configuration, signalingChannel)
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
configuration |
Owt.P2P.P2PClientConfiguration |
<nullable> |
Configuration for Owt.P2P.P2PClient. |
signalingChannel |
Object | A channel for sending and receiving signaling messages. |
Extends
Members
-
allowedRemoteIds :array
-
Only allowed remote endpoint IDs are able to publish stream or send message to current endpoint. Removing an ID from allowedRemoteIds does stop existing connection with certain endpoint. Please call stop to stop the PeerConnection.
Type:
- array
Methods
-
addEventListener(eventType, listener)
-
This function registers a callback function as a handler for the corresponding event. It's shortened form is on(eventType, listener). See the event description in the following table.
Parameters:
Name Type Description eventType
string Event string.
listener
function Callback function.
- Inherited From:
-
clearEventListener(eventType)
-
This function removes all event listeners for one type.
Parameters:
Name Type Description eventType
string Event string.
- Inherited From:
-
connect(token)
-
Connect to signaling server. Since signaling can be customized, this method does not define how a token looks like. SDK passes token to signaling channel without changes.
Parameters:
Name Type Description token
string A token for connecting to signaling server. The format of this token depends on signaling server's requirement.
Returns:
It returns a promise resolved with an object returned by signaling channel once signaling channel reports connection has been established.
- Type
- Promise.<object, Error>
-
disconnect()
-
Disconnect from the signaling channel. It stops all existing sessions with remote endpoints.
Returns:
- Type
- Promise.<undefined, Error>
-
getStats(remoteId)
-
Get stats of underlying PeerConnection.
Parameters:
Name Type Description remoteId
string Remote endpoint's ID.
Returns:
It returns a promise resolved with an RTCStatsReport or reject with an Error if there is no connection with specific user.
- Type
- Promise.<RTCStatsReport, Error>
-
publish(remoteId, stream)
-
Publish a stream to a remote endpoint.
Parameters:
Name Type Description remoteId
string Remote endpoint's ID.
stream
Owt.Base.LocalStream An Owt.Base.LocalStream to be published.
Returns:
A promised that resolves when remote side received the certain stream. However, remote endpoint may not display this stream, or ignore it.
- Type
- Promise.<Owt.Base.Publication, Error>
-
removeEventListener(eventType, listener)
-
This function removes a registered event listener.
Parameters:
Name Type Description eventType
string Event string.
listener
function Callback function.
- Inherited From:
-
send(remoteId, message)
-
Send a message to remote endpoint.
Parameters:
Name Type Description remoteId
string Remote endpoint's ID.
message
string Message to be sent. It should be a string.
Returns:
It returns a promise resolved when remote endpoint received certain message.
- Type
- Promise.<undefined, Error>
-
stop(remoteId)
-
Clean all resources associated with given remote endpoint. It may include RTCPeerConnection, RTCRtpTransceiver and RTCDataChannel. It still possible to publish a stream, or send a message to given remote endpoint after stop.
Parameters:
Name Type Description remoteId
string Remote endpoint's ID.
Returns:
- Type
- undefined