API Docs for:
Show:

rtc.PeerConnection Class

Extends events.EventEmitter
Module: rtc

Wrapper around native RTCPeerConnection

Provides events for new streams and data channels. Signaling information has to be forwarded from events emitted by this object to the remote PeerConnection.

Constructor

rtc.PeerConnection

(
  • offering
  • options
)

Parameters:

  • offering Boolean

    True if the local peer should initiate the connection

  • options Object

    Options object passed on from Room

Methods

_connectError

(
  • err
)
private

Mark connection attempt as failed

Parameters:

  • err Error

    Error causing connection to fail

_oaOptions

() Object private

Returns the options for the offer/answer

Returns:

Object:

_offer

() private

Create offer, set it on local description and emit it

_offer

() private

Create answer, set it on local description and emit it

_processLocalSdp

(
  • sdp
)
Promise private

Set local description and emit it

Parameters:

  • sdp Object

    The local SDP

Returns:

Promise:

Promise which will be resolved once the local description was set successfully

_setRemoteDescription

(
  • sdp
)
Promise private

Set the remote description

Parameters:

  • sdp Object

    The remote SDP

Returns:

Promise:

Promise which will be resolved once the remote description was set successfully

addDataChannel

(
  • name
  • desc
)

Add DataChannel. Will only actually do something if offering is true.

Parameters:

  • name String

    Name of the data channel

  • desc Object

    Options passed to RTCPeerConnection.createDataChannel()

addIceCandidate

(
  • desc
)

Add a remote ICE candidate

Parameters:

  • desc Object

    The candidate

addStream

(
  • stream
)

Add local stream

Parameters:

close

()

Close the connection to the remote peer

connect

() Promise

Establish connection with remote peer. Connection will be established once both peers have called this functio

Returns:

Promise:

Promise which will be resolved once the connection is established

removeStream

(
  • stream
)

Remove local stream

Parameters:

signaling

(
  • data
)

Add new signaling information received from remote peer

Parameters:

  • data Object

    The signaling information

Events

closed

()

The PeerConnection was closed

data_channel_ready

(
  • channel
)

New DataChannel to the remote peer is ready to be used

Parameters:

ice_candiate

(
  • candidate
)

New local ICE candidate which should be signaled to remote peer

Parameters:

  • candidate Object

    The ice candidate

signaling

(
  • obj
)

New offer or answer which should be signaled to the remote peer

Parameters:

  • obj Object

    The signaling message

stream_added

(
  • stream
)

New remote stream was added to the PeerConnection

Parameters: