Publish

Publish

Manages connection with a secure WebSocket path to signal the Millicast server and establishes a WebRTC connection to broadcast a MediaStream.

Before you can broadcast, you will need:

  • MediaStream which has at most one audio track and at most one video track. This will be used for stream the contained tracks.

  • A connection path that you can get from Director module or from your own implementation.

Constructor

# new Publish(streamName, tokenGenerator, autoReconnectopt)

Parameters:
Name Type Attributes Default Description
streamName String

Millicast existing stream name.

tokenGenerator tokenGeneratorCallback

Callback function executed when a new token is needed.

autoReconnect Boolean <optional>
true

Enable auto reconnect to stream.

Source:

Extends

Methods

# (async) connect(options) → {Promise.<void>}

Starts broadcast to an existing stream name.

In the example, getYourMediaStream and getYourPublisherConnection is your own implementation.

Parameters:
Name Type Description
options Object

General broadcast options.

Properties
Name Type Attributes Default Description
sourceId String

Source unique id. Only avialable if stream is multisource.

stereo Boolean

True to modify SDP for support stereo. Otherwise False.

dtx Boolean

True to modify SDP for supporting dtx in opus. Otherwise False.

absCaptureTime Boolean

True to modify SDP for supporting absolute capture time header extension. Otherwise False.

dependencyDescriptor Boolean

True to modify SDP for supporting aom dependency descriptor header extension. Otherwise False.

mediaStream MediaStream | Array.<MediaStreamTrack>

MediaStream to offer in a stream. This object must have 1 audio track and 1 video track, or at least one of them. Alternative you can provide both tracks in an array.

bandwidth Number <optional>
0

Broadcast bandwidth. 0 for unlimited.

disableVideo Boolean <optional>
false

Disable the opportunity to send video stream.

disableAudio Boolean <optional>
false

Disable the opportunity to send audio stream.

codec VideoCodec

Codec for publish stream.

simulcast Boolean

Enable simulcast. Only available in Google Chrome and with H.264 or VP8 video codecs.

scalabilityMode String

Selected scalability mode. You can get the available capabilities using PeerConnection.getCapabilities method. Only available in Google Chrome.

peerConfig RTCConfiguration

Options to configure the new RTCPeerConnection.

record Boolean <optional>

Enable stream recording. If record is not provided, use default Token configuration. Only available in Tokens with recording enabled.

events Array.<String> <optional>

Specify which events will be delivered by the server (any of "active" | "inactive" | "viewercount").*

Source:
Returns:

Promise object which resolves when the broadcast started successfully.

Type
Promise.<void>
Examples
await publish.connect(options)
import Publish from '@millicast/sdk'

//Define callback for generate new token
const tokenGenerator = () => getYourPublisherInformation(token, streamName)

//Create a new instance
const streamName = "My Millicast Stream Name"
const millicastPublish = new Publish(streamName, tokenGenerator)

//Get MediaStream
const mediaStream = getYourMediaStream()

//Options
const broadcastOptions = {
   mediaStream: mediaStream
 }

//Start broadcast
try {
 await millicastPublish.connect(broadcastOptions)
} catch (e) {
 console.log('Connection failed, handle error', e)
}

# getRTCPeerConnection() → {RTCPeerConnection}

Get current RTC peer connection.

Returns:

Object which represents the RTCPeerConnection.

Type
RTCPeerConnection

# isActive() → {Boolean}

Get if the current connection is active.

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

# (async) reconnect(dataopt)

Reconnects to last broadcast.

Parameters:
Name Type Attributes Description
data Object <optional>

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

Properties
Name Type Description
error String

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

# (async) record()

Initialize recording in an active stream and change the current record option.

Source:

# setReconnect()

Sets reconnection if autoReconnect is enabled.

Inherited From:

# stop()

Stops connection.

Inherited From:

# (async) unrecord()

Finalize recording in an active stream and change the current record option.

Source:

Events

# reconnect

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

Type:
  • Object
Properties
Name Type Description
timeout Number

Next retry interval in milliseconds.

error Error

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

Inherited From: