Broadcast Events

Receiving Broadcast Events During a Real-time Stream Real-time Streaming supports broadcastEvents, sometimes called viewer events, which allow you to add functionality that triggers when various events occur during the stream. This functionality can be helpful for detecting active feeds, changes in simulcast layers, or even the viewer count of a stream.

This guide outlines what events are available and how to use them for your app or platform.

List of events

Currently, there are seven events that can be listened to when connected to the Millicast Viewer:

  • Active: Fires when a live stream is or has started broadcasting.
  • Inactive: Triggers when the stream has stopped broadcasting but is still connected to the publisher.
  • Stopped: Fires when the live stream has been disconnected from the publisher.
  • Vad: Fires when the live stream is mixing and layering audio with Audio Multiplexing.
  • Layers: When streaming with Simulcast, this event fires when there is an update of the state of the layers in the live stream.
  • Migrate: Fires when the server is having problems, is shutting down, or when viewers need to move for load balancing purposes.
  • Viewercount: Triggers when the number of viewers changes in the stream published.

Using events


Not familar with our SDKs?

Learn more about the Millicast streaming SDKs by following the Getting Started guide or by leanring about our Client SDKs.

To use or "listen" for these events, you first must authenticate and connect to the CDN using one of our Client SDKs. When calling the connect function you can include a list of all events to listen for:

import { Director, View } from '@millicast/sdk';

// Create callback to generate a new token
const tokenGenerator = () => Director.getSubscriber({
  streamName: 'publish-stream-name',
  streamAccountId: 'publish-account-id',
  subscriberToken: 'subscriber-token' // Optional: This token is needed if you're subscribing to a secure stream.
// Create a new instance
const millicastView = new View(streamName, tokenGenerator);

// Start connection to publisher listening to as few or many events as you need
await millicastView.connect({
  events: ['active', 'inactive', 'vad', 'layers']

By default, if no event list is included, the connect function will listen for active,inactive, and stopped events.

Once connected, the event listener becomes available, allowing your app to listen for events and trigger accordingly:

millicastView.on('broadcastEvent', (event) => {
	// Get event name and data
	const { name, data } = event;

	switch (name)
		case 'active':
			// A source has been started on the stream
		case 'inactive':
			// A source has been stopped on the stream
		case 'vad':
			// A new source was multiplexed over the vad tracks
		case 'layers':
			// Updated layer information for each simulcast/svc video track

Learn more

Learn more by exploring the developer blog and code samples.