Broadpeak

The Broadpeak plugin integrates PRESTOplay for React Native with Broadpeak’s analytics and delivery services. It’s a plugin, so you install and enable it separately.

Setup

First, install the @castlabs/react-native-prestoplay-broadpeak package:

npm install @castlabs/react-native-prestoplay-broadpeak

Once the plugin is installed, set its configuration and enable it when initializing the SDK, by passing the BroadpeakPlugin class. For example:

import { Sdk } from "@castlabs/react-native-prestoplay";
import {
  BroadpeakPlugin,
  StreamingSessionOptions,
  StreamingSessionOptionsValues,
} from '@castlabs/react-native-prestoplay-broadpeak';

BroadpeakPlugin.setConfiguration ({
  analyticsAddress: "analytics_url",
  nanoCDNHost: "nano_cdn_host",
  domainNames: "*",
  streamingSessionOptions: {
    [StreamingSessionOptions.SESSION_REPORTING_MODE]:
      StreamingSessionOptionsValues.SESSION_REPORTING_MODE_METRICS_RECEIVER,
    [StreamingSessionOptions.SESSION_KEEPALIVE_FREQUENCY]: 7000,
    [StreamingSessionOptions.SESSION_PRECACHE]: false,
  },
  logLevel: 'verbose',
})

Sdk.initialize({
  licenseKey: /* Valid license here */,
  plugins: [BroadpeakPlugin],
});

iOS

Add broadpeak repository to the application Podfile:

# broadpeak repository
source 'https://delivery-platform.broadpeak.tv/ios/broadpeak/specs.git'

Web

Add the Broadpeak SmartLib packages to your project dependencies:

"@broadpeak/smartlib": "5.0.1-4c69e21",
"@broadpeak/smartlib-analytics": "5.0.1-4c69e21",

Effective URL

For the domains listed in domainNames, SmartLib opens a Broadpeak session and redirects playback to the session URL it returns, so the stream is not loaded from the URL configured in the player. Player.getEffectiveUrl() returns the URL the stream is actually loaded from, and every change is announced by the EventType.EffectiveUrlChanged event, whose payload carries the new URL:

player.addEventListener(EventType.EffectiveUrlChanged, (event: Event) => {
  const {url} = event.details as EffectiveUrlChangedDetails;
  console.log('Broadpeak session URL:', url);
});
await player.open(playerConfig);

In components, the useEffectiveUrl hook keeps the value up to date:

export default function SessionUrlLabel() {
  const effectiveUrl = useEffectiveUrl(); // null until content is loaded
  return <>{effectiveUrl ?? '-'}</>;
}

The value is null until content is loaded. On iOS/tvOS and web the configured URL is reported first and the session URL once the plugin has resolved it. On Android the session URL is the first value reported. Without the Broadpeak plugin the value is the configured source URL. No other change of the URL the stream is loaded from, such as an HTTP redirect followed by the native network stack, is reflected by this API.

Next topic: Youbora