Heartbeat
The heartbeat library is a personalization library that facilitates stream concurrency. Playback would be aborted when the concurrent streams reaches allowed limit.
Create HeartbeatManager
Wiring Authorization Response
Once an asset is authorized for Playback (refer Authorize Playback for an Asset), the authorization includes the following heartbeat info, which should be used while setting up the heartbeat.
| Name | Description |
|---|---|
| heartbeatFlag | Indicates whether heartbeat should be attached for the current playback (e.g., heartbeat is not required for blacked-out streams or certain VOD catalog types) |
| heartbeatFreq | The recommended heartbeat sync interval in milli-seconds |
| heartbeatToken | The unique hearbeat token for the current playback |
| liveStartTime | Start time of the current live program/live event. |
| liveEndTime | End Time of the current live program/live event. |
| catalogType | The value of the Catalog type of content. |
| primaryContentId | The unique identifier of the primary content to which the selected content (i.e. secondary angle content) to play is associated with. This is applicable only for multi-camera enabled content. |
| live360StartTime | The start time of the live 360 camera supported content. |
| live360EndTime | The end time of the live 360 camera supported content. |
| freePreview | Free preview allowance metadata (for example, fpMode, totalDuration, remainingDuration). Refer to Free Preview. |
Configuration
| Name | Required | Description |
|---|---|---|
| heartbeatEndPointUrl | true | Heartbeat service end-point url. |
| streamConcurrencyEndPointUrl | false | Stream Concurrency service end-point url. |
| syncIntervalMS | false | The time interval in milliseconds used to periodically update stream state of the currently playing content. Default: 60000ms. |
| maxAllowedFailures | false | The maximum number of failed heartbeat check attempts (network or infrastructure issues) that are allowed to happen in line before the Live content's playback is terminated. Default: 2. |
| recordBookmark | false | Specifies whether to use the heartbeat service to record bookmarks/resume points for VOD contents. Default: false. |
| stopPlayerOnStreamTimelineEvent | false | Specifies whether to stop the player for Live contents on stream timeline events. Default: true. Free-preview expiry and GRACEFUL_STOP stop playback regardless of this setting. |
| showPostEventSlateTimeMs | false | The post-event configuration time in milliseconds used to stop the overflow event after a live event ends. Default: 900000ms (15 minutes). |
| multiStreamMode | false | Indicates if the current device is streaming multiple videos using multiple player instances (for example, in MultiView mode or when swapping between Live and Restart streams). |
| maxRetries | false | The maximum retries for network request failure or timeout. |
| trackViewersCount | false | The flag indicates whether to track the viewers count or not, for the content to play. Default: false. |
| freePreviewExtensionCheckSec | false | The lead time in seconds before preview expiration to check for extensions. Default: 60s. Refer to Free Preview. |
| jitterSec | false | Maximum initial light-preview random offset in seconds, rounded down to 10-second buckets. Default: 60s; 0 disables jitter. Refer to Free Preview. |
| onFreePreviewExtension | false | Callback invoked in light preview mode to request additional preview seconds or decline ((preview: Readonly<FreePreview>) => Promise<number>). Refer to Free Preview. |
| onFreePreviewProgress | false | Callback reporting the initial allowance and changes in displayed whole seconds remaining ((preview: Readonly<FreePreview>) => void). Refer to Free Preview. |
const heartbeatConfiguration = {
heartbeatEndPointUrl: heartbeatEndPointUrl,
streamConcurrencyEndPointUrl: streamConcurrencyEndPointUrl,
syncIntervalMS: heartbeatFreq,
};
return flHeartbeat
.createHeartbeatBuilder(
deviceId,
contentId,
heartbeatConfiguration,
platformAuthorizer,
)
.setHeartbeatToken(heartbeatToken)
.setLiveEndTime(liveEndTime)
.setLiveStartTime(liveStartTime)
.build();
Reserve Stream on Player Load
Call setReserveStreamOnPlayerLoad(true) on the builder when playback
authorization didn't reserve a stream slot, for example for content you
authorized with preload: true (refer to
Prefetch Content). The
HeartbeatManager then reserves the stream itself through
/user/stream/create.
- When it reserves: when the player reaches
LOADED. If the player never emitsLOADED, it reserves on the firstSTARTEDinstead. It reserves only once per load. - Requirements: set
streamConcurrencyEndPointUrlin the configuration. Without it, theHeartbeatManagerdoesn't reserve a stream and doesn't report an error. The request uses theheartbeatTokenyou pass tosetHeartbeatToken(). - On failure: the player aborts playback and emits an
errorevent with the error returned by the stream concurrency service, for example when the concurrent-stream limit is reached. Because the reservation runs atLOADED, a rejected session stops before playback starts.
When the flag is false or not set, the HeartbeatManager doesn't reserve a
stream on load, which is the default behavior.
const heartbeatManager = flHeartbeat
.createHeartbeatBuilder(
deviceId,
contentId,
{
heartbeatEndPointUrl: heartbeatEndPointUrl,
streamConcurrencyEndPointUrl: streamConcurrencyEndPointUrl,
syncIntervalMS: contentAuthorizationData.heartbeatFreq,
},
platformAuthorizer,
)
.setHeartbeatToken(contentAuthorizationData.heartbeatToken)
.setReserveStreamOnPlayerLoad(true)
.build();
player.subscribe('error', error => {
// For example, show a "too many devices streaming" message.
});
setReserveStreamOnPlayerLoad() requires Web SDK 7.1.297 or later.
Attach Heartbeat to Player
HeartbeatManager could be attached to a Player by attaching the exposed processPlayerStateChange, processHeartbeatChange callback to
ComposablePlayer's addStateChangeStep, processHeartbeatChange life-cycle method.
const composablePlayer = flPlatformPlayer.createComposablePlayer(player);
composablePlayer.addStateChangeStep(heartbeatManager.processPlayerStateChange);
composablePlayer.addHeartBeatStep(heartbeatManager.processHeartbeatChange);
Stream Reservation on Resume
When you configure streamConcurrencyEndPointUrl, the HeartbeatManager
releases the stream slot when the player pauses, stops, or goes idle, and
reserves it again through /user/stream/create when playback resumes. In
multiStreamMode, it keeps the slot instead of releasing it.
If the reservation on resume fails, the player aborts playback and emits an
error event with the error returned by the stream concurrency service. For
example, this happens when another device starts streaming while this one is
paused and the account reaches its concurrent-stream limit. Handle the error
event to show your app's concurrency message.
From Web SDK 7.1.297, a failed reservation on resume aborts playback. Earlier
versions ignored the failure and continued playback.
Blackouts
While authorizing an asset for Playback, the server might enforce Blackout rules based on tenent specific configuration. When a playback is attempted from a Blacked-out region, the server would respond with the following:
| Name | Description |
|---|---|
| blackoutAction | Indicates appropriate action for Blackout scenario. Possible Values: ALLOW, DENY, ALLOW_WITH_UPGRADE. |
| blackoutUrl | The alternate blackout slate stream to play while the user is in blackout. |
When receiving a blackoutAction other than ALLOW, the application must play the blackoutUrl instead if the regular contentUrl.
Roaming
Blackouts are also detected and enforced via heartbeat to ensure when the user is roaming to a blacked-out region, they are no longer able to stream the content. When detecting a blackout, the HeartbeatManager would abort the player and player emits a streamtimelineevent event with blackout action. Application could subscribe to this event manage the blackout based on the UX requirements (typically, swap the on-going player with a player playing blacked-out slate).
player.subscribe("streamtimelineevent", async function (streamTimelineEvent, action, metadata) {
switch (streamTimelineEvent) {
case flPlayerInterface.StreamTimelineEvent.BLACKOUT: {
console.log("Blackout Url", blackoutMetadata.blackoutUrl);
// Create a new player instance and play the blackout Url.
break;
}
}
});
Events during Live Streams
All the applicable events for different type of live streams are part of StreamTimelineEvent and can be notified to the client application using Heartbeat.
| Name | Description |
|---|---|
| LIVE_EVENT_START | The start of a one-time Live event. |
| LIVE_EVENT_END | The end of a one-time live event. |
| OVERFLOW_EVENT_END | The end of an overflow event. Applicable only for Overflow events. |
| BLACKOUT | The playback has blacked out. |
| LIVE_360_AVAILABLE | The availability of 360 degree mode |
| LIVE_360_UNAVAILABLE | The unavailability of 360 degree mode |