Publish

Publish

Manages connection with a secure WebSocket path to signal the Wowza 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

The name of the Wowza Video real-time stream.

tokenGenerator tokenGeneratorCallback

The callback function executed when a new token is needed.

autoReconnect Boolean <optional>
true

Enable automatic reconnection to the stream.

Source:

Extends

Methods

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

Start broadcasting to an existing stream name.

In the following example, getYourMediaStream and getYourPublisherConnection are your own implementation.

Parameters:
Name Type Description
options Object

Available broadcast options.

Properties
Name Type Attributes Default Description
sourceId String

The unique source ID. Only available if the stream is multi-source.

stereo Boolean <optional>
false

Enable SDP support for stereo.

dtx Boolean <optional>
false

Enable SDP support for DTX in Opus.

absCaptureTime Boolean <optional>
false

Enable SDP support for an absolute capture time header extension.

dependencyDescriptor Boolean <optional>
false

Enable SDP support for AOM dependency descriptor header extension.

mediaStream MediaStream | Array.<MediaStreamTrack>

The MediaStream to offer in a stream. This object must have one audio track or one video track. Alternatively, you can provide both tracks in an array.

bandwidth Number <optional>
0

The broadcast bandwidth. Use 0 for unlimited bandwidth.

disableVideo Boolean <optional>
false

Disable sending a video stream.

disableAudio Boolean <optional>
false

Disable sending an audio stream.

codec VideoCodec <optional>
'h264'

The video codec for the published stream.

simulcast Boolean <optional>
false

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

scalabilityMode String <optional>
null

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

peerConfig RTCConfiguration <optional>
null

The new RTCPeerConnection configuration.

record Boolean <optional>
false

Enable stream recording. If this property is not provided, the default token configuration is used. Only available in tokens with recording enabled.

events Array.<String> <optional>
null

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

priority Number <optional>
null

When multiple ingest streams are provided by the customer, add the ability to specify a priority between all ingest streams. Decimal integer between the range [-2^31, +2^31 - 1]. For more information, visit our documentation.

Source:
Returns:

A promise object that resolves when the broadcast started successfully.

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

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

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

//Get MediaStream
const mediaStream = getYourMediaStream()

//Options
const broadcastOptions = {
   mediaStream: mediaStream
 }

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

# getRTCPeerConnection() → {RTCPeerConnection}

Get the current RTC peer connection.

Returns:

The RTCPeerConnection.

Type
RTCPeerConnection

# isActive() → {Boolean}

Get whether the current connection is active.

Inherited From:
Returns:

True if connected or false if not connected.

Type
Boolean

# (async) reconnect(dataopt)

Reconnect to the 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()

Set up reconnection if autoReconnect is enabled.

Inherited From:

# stop()

Stop the connection.

Inherited From:

# (async) unrecord()

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

Source:

Events

# reconnect

Emit with every reconnection attempt made when an active stream stops unexpectedly.

Type:
  • Object
Properties
Name Type Description
timeout Number

The 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: