Constructor
new Publish(streamName, tokenGenerator, autoReconnectopt)
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.
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | General broadcast options. Properties
|
- Source
Promise object which resolves when the broadcast started successfully.
- Type:
- Promise.<void>
await publish.connect(options)
import Publish from '@millicast/sdk'
//Define callback for generate new token
const tokenGenerator = () => getYourPublisherConnection(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.
- Inherited From
- Source
Object which represents the RTCPeerConnection.
- Type:
- RTCPeerConnection
isActive() → {Boolean}
Get if the current connection is active.
- Inherited From
- Source
- True if connected, false if not.
- Type:
- Boolean
(async) reconnect(dataopt)
Reconnects to last broadcast.
Name | Type | Attributes | Description |
---|---|---|---|
data | Object | <optional> | This object contains the error property. It may be expanded to contain more information in the future. |
Name | Type | Description |
---|---|---|
error | String | The value sent in the first reconnect event within the error key of the payload |
- Overrides
- Source
(async) record()
Initialize recording in an active stream and change the current record option.
- Source
setReconnect()
Sets reconnection if autoReconnect is enabled.
- Inherited From
- Source
stop()
Stops connection.
- Inherited From
- Source
(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.
- Object
Name | Type | Description |
---|---|---|
timeout | Number | Next retry interval in milliseconds. |
error | Error | Error object with cause of failure. Possible errors are:
|
- Inherited From
- Source