Skip to main content

Livestreaming

Introduction

  • Livestreaming is often used for events, such as concerts, conferences, and sports games, as well as for online classes, gaming, and social media platforms.
  • Dyte uses LHLS to deliver low latency one way streams.
  • The Interactive Livestream product delivers interactivity via chat, polls, reactions etc.
  • Viewer can also be pulled in the livestream by the host using Stage Management APIs [ref: here].

This section will guide you through the process of integrating the livestreaming feature into your product.

Properties

Playlist URL:

Livestream playlist URL is accessible via url property of DyteLivestreamData instance:

If the livestream is not active for current room, it'll return null.

final String? url = dyteClient.livestream.data.url;

Livestream Status:

The current livestream status can be accessed from state property of the DyteLivestreamData instance:

final DyteLivestreamStatus? status = dyteClient.livestream.data.state;

There can be 6 livestream statuses:

  • DyteLivestreamStatus.none : When livestream is not active.
  • DyteLivestreamStatus.starting : When livestream is starting.
  • DyteLivestreamStatus.started : When livestream is going on.
  • DyteLivestreamStatus.ending : When livestream is ending.
  • DyteLivestreamStatus.ended : When livestream ended.
  • DyteLivestreamStatus.errored : When livestream encountered an error.

Viewer Count

The current viewer count for livestream can be accessed via viewerCountproperty of DyteLivestreamData instance.

final int? viewerCount = dyteClient.livestream.data.viewerCount;

Room Name

The room name of current livestream can be accessed via roomName property of DyteLivestreamData instance.

final String? roomName = dyteClient.livestream.data.roomName;

Methods

Use the following methods to start and stop livestreaming.

Note

You'll be able to start/stop livestream if your preset allows it.

Start Livestream

You can start a livestream with the following method:

dyteClient.livestream.start();

Stop Livestream

You can stop a livestream with the following method:

dyteClient.livestream.stop();

LivestreamView

LivestreamView widget returns the view for the current livestream. It takes String? url as an argument of the livestream which is accessible via dyteMobileClient.livestream.url method or Future<String?> getUrl() method on DyteLivestream instance, which returns null if there's no livestream url.

final livestreamView = LivestreamView(
url: dyteMobileClient.livestream.url,
);

// or

Future<Widget> fetchLivestreamView () async {
String? url = await dyteMobileClient.livestream.getUrl();
if (url != null) {
return LivestreamView(
url: url,
);
} else {
return Container();
}

final livestreamView = await fetchLivestreamView();
}

Events

You need to subscribe to LivestreamEventListener to be able to listen livestream events. You can do it as follows:

class LivestreamListener implements DyteLivestreamEventsListener{
...
void onLiveStreamStateUpdate(DyteLivestreamData data) {
// Handle livestream state update
}
...
}

dyteClient.addLivestreamEventsListener(LivestreamListener());

Here are a list of events the livestream listener emits:

EventDescription
onLiveStreamStateUpdateEmitted when a livestream state is updated. It contains the updated livestream state in the payload.
onViewerCountUpdatedEmitted when a viewer count of a livestream is updated. It contains the updated viewer count in the payload.
onStageCountUpdatedEmitted when a participants on stage changes. It contains the updated viewer count in the payload.
onLiveStreamStartingEmitted when livestream state is updated to DyteLivestreamStatus.Starting
onLiveStreamStartedEmitted when livestream state is updated to DyteLivestreamStatus.Started
onLiveStreamEndingEmitted when livestream state is updated to DyteLivestreamStatus.Ending
onLiveStreamEndedEmitted when livestream state is updated to DyteLivestreamStatus.Ended
onLiveStreamErroredEmitted when livestream state is updated to DyteLivestreamStatus.Errored