Director

Source: Director.js:24

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.


Instance Methods

setEndpoint(url: String): void

Set Director API endpoint where requests will be sent.

Parameters

  • url (String) — New Director API endpoint

Returns

  • void

getEndpoint(): String

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

Returns

  • String — API base url

setLiveDomain(domain: String): void

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

Parameters

  • domain (String) — New Websocket Live domain

Returns

  • void

getLiveDomain(): String

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

Returns

  • String — Websocket Live domain

getPublisher( options: DirectorPublisherOptions, ): Promise.<MillicastDirectorResponse>

Get publisher connection data.

Parameters

Returns

  • Promise.<MillicastDirectorResponse> — Promise object which represents the result of getting the publishing connection path.

Example

CODE
const response = await Director.getPublisher(options)
CODE
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(undefined, tokenGenerator)

//Get MediaStream
const mediaStream = getYourMediaStreamImplementation()

//Options
const broadcastOptions = {
   mediaStream: mediaStream
 }

//Start broadcast
await millicastPublish.connect(broadcastOptions)

getSubscriber( options: DirectorSubscriberOptions, ): Promise.<MillicastDirectorResponse>

Get subscriber connection data.

Parameters

Returns

  • Promise.<MillicastDirectorResponse> — Promise object which represents the result of getting the subscribe connection data.

Example

CODE
const response = await Director.getSubscriber(options)
CODE
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(undefined, 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)

Other

DRMObject: Object

Properties

  • fairPlayCertUrl (String) — URL of the FairPlay certificate server.
  • fairPlayUrl (String) — URL of the FairPlay license server.
  • widevineUrl (String) — URL of the Widevine license server.