Publish
Extends: BaseWebRTC
Source: Publish.js:47
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: String,
tokenGenerator: tokenGeneratorCallback,
autoReconnect?: Boolean,
): PublishParameters
streamName(String) — Deprecated: Millicast existing stream name.tokenGenerator(tokenGeneratorCallback) — Callback function executed when a new token is needed.autoReconnect(Boolean, optional, default: true) — Enable auto reconnect to stream.
Instance Methods
connect(options: Object): Promise.<void>
Starts broadcast to an existing stream name.
In the example, getYourMediaStream and getYourPublisherConnection is your own implementation.
Parameters
options(Object) — General broadcast options.options.sourceId(String) — Source unique id. Only avialable if stream is multisource.options.stereo(Boolean, optional, default: false) — True to modify SDP for support stereo. Otherwise False.options.dtx(Boolean, optional, default: false) — True to modify SDP for supporting dtx in opus. Otherwise False.options.absCaptureTime(Boolean, optional, default: false) — True to modify SDP for supporting absolute capture time header extension. Otherwise False.options.dependencyDescriptor(Boolean, optional, default: false) — True to modify SDP for supporting aom dependency descriptor header extension. Otherwise False.options.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.options.bandwidth(Number, optional, default: 0) — Broadcast bandwidth. 0 for unlimited.options.metadata(Boolean, optional, default: false) — Enable metadata insertion if stream is compatible.options.disableVideo(Boolean, optional, default: false) — Disable the opportunity to send video stream.options.disableAudio(Boolean, optional, default: false) — Disable the opportunity to send audio stream.options.codec(VideoCodec, optional, default: "'h264'") — Codec for publish stream.options.simulcast(Boolean, optional, default: false) — Enable simulcast. Only available in Chromium based browsers and with H.264 or VP8 video codecs.options.scalabilityMode(String, optional, default: null) — Selected scalability mode. You can get the available capabilities using PeerConnection.getCapabilities method. Only available in Google Chrome.options.peerConfig(PeerConnectionConfig, optional, default: null) — Options to configure the new RTCPeerConnection.options.record(Boolean, optional, default: false) — Enable stream recording. If record is not provided, use default Token configuration. Only available in Tokens with recording enabled.options.events(Array.<String>, optional, default: null) — Specify which events will be delivered by the server (any of "active" | "inactive" | "viewercount").*options.priority(Number, optional, default: 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.
Returns
Promise.<void>— Promise object which resolves when the broadcast started successfully.
Fires
PeerConnection#event:connectionStateChangeSignaling#event:broadcastEvent
Example
await publish.connect(options)import Publish from '@millicast/sdk'
//Define callback for generate new token
const tokenGenerator = () => getYourPublisherConnection(token, streamName)
//Create a new instance
// streamName is not necessary in the constructor anymore, could be null or undefined
const streamName = "My Millicast Stream Name"
const millicastPublish = new Publish(undefined, 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)
}record()
Initialize recording in an active stream and change the current record option.
unrecord()
Finalize recording in an active stream and change the current record option.
sendMetadata(message: String | Object, uuid?: String)
Send SEI user unregistered data as part of the frame being streamed. Only available for H.264 codec.
Parameters
message(String | Object) — The data to be sent as SEI user unregistered data.uuid(String, optional, default: "\"d40e38ea-d419-4c62-94ed-20ac37b4e4fa\"") — String with UUID format as hex digit (XXXX-XX-XX-XX-XXXXXX).
getRTCPeerConnection(): RTCPeerConnection
Inherited from BaseWebRTC#getRTCPeerConnection
Get current RTC peer connection.
Returns
RTCPeerConnection— Object which represents the RTCPeerConnection.
stop()
Inherited from BaseWebRTC#stop
Overrides: BaseWebRTC#stop
Stops connection.
isActive(): Boolean
Inherited from BaseWebRTC#isActive
Get if the current connection is active.
Returns
Boolean
setReconnect()
Inherited from BaseWebRTC#setReconnect
Sets reconnection if autoReconnect is enabled.
reconnect(data?: Object)
Inherited from BaseWebRTC#reconnect
Overrides: BaseWebRTC#reconnect
Reconnects to last broadcast.
Parameters
data(Object, optional) — This object contains the error property. It may be expanded to contain more information in the future.
Properties
error(String) — The value sent in the first reconnect event within the error key of the payload
Fires
BaseWebRTC#event:reconnect
Events
reconnect: Object
Inherited from BaseWebRTC#event:reconnect
Emits with every reconnection attempt made when an active stream stopped unexpectedly.
Properties
timeout(Number) — Next retry interval in milliseconds.error(Error) — Error object with cause of failure. Possible errors are: