BaseWebRTC

Base class for common actions about peer connection and reconnect mechanism for Publishers and Viewer instances.

Constructor

new BaseWebRTC(streamName, tokenGenerator, loggerInstance, autoReconnect)

Parameters:
NameTypeDescription
streamNameString

Deprecated: Millicast existing stream name. Use tokenGenerator instead.

tokenGeneratortokenGeneratorCallback

Callback function executed when a new token is needed.

loggerInstanceObject

Logger instance from the extended classes.

autoReconnectBoolean

Enable auto reconnect.

Extends

  • EventEmitter

Methods

getRTCPeerConnection() → {RTCPeerConnection}

Get current RTC peer connection.

Returns:

Object which represents the RTCPeerConnection.

Type: 
RTCPeerConnection

isActive() → {Boolean}

Get if the current connection is active.

Returns:
  • True if connected, false if not.
Type: 
Boolean

(async) reconnect(dataopt)

Reconnects to last broadcast.

Parameters:
NameTypeAttributesDescription
dataObject<optional>

This object contains the error property. It may be expanded to contain more information in the future.

Properties
NameTypeDescription
errorString

The value sent in the first reconnect event within the error key of the payload

setReconnect()

Sets reconnection if autoReconnect is enabled.

stop()

Stops connection.

Events

reconnect

Emits with every reconnection attempt made when an active stream stopped unexpectedly.

Type:
  • Object
Properties
NameTypeDescription
timeoutNumber

Next retry interval in milliseconds.

errorError

Error object with cause of failure. Possible errors are:

  • Signaling error: wsConnectionError if there was an error in the Websocket connection.
  • Connection state change: RTCPeerConnectionState disconnected if there was an error in the RTCPeerConnection.
  • Attempting to reconnect if the reconnect was trigered externally.
  • Or any internal error thrown by either Publish.connect or View.connect methods