Skip to main content

useEffectiveUrl()

useEffectiveUrl(): null | string

Returns the effective URL: the URL the stream is actually loaded from.

This hook provides a reactive way to observe the URL reported by Player.getEffectiveUrl. It is the URL of the current source unless the Broadpeak plugin redirected the stream to a Broadpeak session URL. It updates on every EventType.EffectiveUrlChanged event.

Only the redirect performed by the Broadpeak plugin is supported; see the Broadpeak guide. Without the plugin the value is the configured source URL.

⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.

Returns​

null | string

string | null The effective URL, or null until content is loaded.

Example​

import React from 'react';
import { Text } from 'react-native';
import { useEffectiveUrl } from '@castlabs/react-native-prestoplay';

export default function SessionUrlLabel() {
const effectiveUrl = useEffectiveUrl();

if (effectiveUrl === null) {
return <Text>Loading…</Text>;
}

return <Text>Loading from {effectiveUrl}</Text>;
}