Simplify API calls to find the best server and region to publish and subscribe to. For security reasons all calls will return a JWT token for authentication including the required socket path to connect with.

You will need your own Publishing token and Stream name, please refer to Managing Your Tokens.

Methods

(inner) getEndpoint() → {String}

Get current Director API endpoint where requests will be sent. Default endpoint is 'https://director.millicast.com'.

Returns:

API base url

Type: 
String

(inner) getLiveDomain() → {String}

Get current Websocket Live domain. By default is empty which corresponds to not parse the Director response.

Returns:

Websocket Live domain

Type: 
String

(inner) getPublisher(options) → {Promise.<MillicastDirectorResponse>}

Get publisher connection data.

Parameters:
NameTypeDescription
optionsDirectorPublisherOptions

Millicast options.

Returns:

Promise object which represents the result of getting the publishing connection path.

Type: 
Promise.<MillicastDirectorResponse>
Examples
const response = await Director.getPublisher(options)
import { Publish, Director } from '@millicast/sdk'

//Define getPublisher as callback for Publish
const streamName = "My Millicast Stream Name"
const token = "My Millicast publishing token"
const tokenGenerator = () => Director.getPublisher({token, streamName})

//Create a new instance
const millicastPublish = new Publish(streamName, tokenGenerator)

//Get MediaStream
const mediaStream = getYourMediaStreamImplementation()

//Options
const broadcastOptions = {
   mediaStream: mediaStream
 }

//Start broadcast
await millicastPublish.connect(broadcastOptions)

(inner) getSubscriber(options) → {Promise.<MillicastDirectorResponse>}

Get subscriber connection data.

Parameters:
NameTypeDescription
optionsDirectorSubscriberOptions

Millicast options.

Returns:

Promise object which represents the result of getting the subscribe connection data.

Type: 
Promise.<MillicastDirectorResponse>
Examples
const response = await Director.getSubscriber(options)
import { View, Director } from '@millicast/sdk'

//Define getSubscriber as callback for Subscribe
const streamName = "My Millicast Stream Name"
const accountId = "Millicast Publisher account Id"
const tokenGenerator = () => Director.getSubscriber({streamName, accountId})
//... or for an secure stream
const tokenGenerator = () => Director.getSubscriber({streamName, accountId, subscriberToken: '176949b9e57de248d37edcff1689a84a047370ddc3f0dd960939ad1021e0b744'})

//Create a new instance
const millicastView = new View(streamName, tokenGenerator)

//Set track event handler to receive streams from Publisher.
millicastView.on('track', (event) => {
  addStreamToYourVideoTag(event.streams[0])
})

//View Options
const options = {
 }

//Start connection to broadcast
await millicastView.connect(options)

(inner) setEndpoint(url) → {void}

Set Director API endpoint where requests will be sent.

Parameters:
NameTypeDescription
urlString

New Director API endpoint

Returns:
Type: 
void

(inner) setLiveDomain(domain) → {void}

Set Websocket Live domain from Director API response. If it is set to empty, it will not parse the response.

Parameters:
NameTypeDescription
domainString

New Websocket Live domain

Returns:
Type: 
void