CastContext
A root class containing global objects and state for the Cast SDK. It is the default export of this library.
example
import GoogleCast, { CastContext } from 'react-native-google-cast'
// GoogleCast and CastContext are equivalent
Hierarchy
- CastContext
Index
Properties
Methods
- getCastState
- getDiscoveryManager
- getPlayServicesState
- getSessionManager
- onCastStateChanged
- showCastDialog
- showExpandedControls
- showIntroductoryOverlay
- showPlayServicesErrorDialog
Properties
Static
discoveryManager
▪ discoveryManager: DiscoveryManager‹› = new DiscoveryManager()
The DiscoveryManager to manage device discovery.
Static
sessionManager
▪ sessionManager: SessionManager‹› = new SessionManager()
The SessionManager that manages cast sessions.
Methods
Static
getCastState
▸ getCastState(): Promise‹CastState | null›
The current casting state for the application.
Returns: Promise‹CastState | null›
Static
getDiscoveryManager
▸ getDiscoveryManager(): DiscoveryManager
Get the DiscoveryManager to manage device discovery.
Returns: DiscoveryManager
Static
getPlayServicesState
▸ getPlayServicesState(): Promise‹PlayServicesState | null›
(Android only) Verifies that Google Play services is installed and enabled on this device, and that the version installed on this device is no older than the one required by this client. Can be used to determine if the Cast framework is available.
see
Android
Returns: Promise‹PlayServicesState | null›
Static
getSessionManager
▸ getSessionManager(): SessionManager
Get the SessionManager to manage cast sessions.
Returns: SessionManager
Static
onCastStateChanged
▸ onCastStateChanged(listener
: function): EmitterSubscription
Listen for changes of the Cast State.
example
const subscription = CastContext.onCastStateChanged(castState => {
if (castState === 'connected') {
// ... ready to go
}
})
// later, to stop listening
subscription.remove()
Parameters:
▪ listener: function
▸ (castState
: CastState): void
Parameters:
Name | Type |
---|---|
castState | CastState |
Returns: EmitterSubscription
Static
showCastDialog
▸ showCastDialog(): Promise‹boolean›
Displays the Cast Dialog programmatically. Users can also open the Cast Dialog by clicking on a Cast Button.
Notes:
- on Android, the Cast Button needs to be rendered somewhere on the screen (can be hidden) in order for this method to work.
- on iOS 14+, the user has to first press the Cast Button manually and grant permissions (once per app install). Until then, this method will not work.
Returns: Promise‹boolean›
true
if the Cast Dialog was shown, false
if it was not shown.
Static
showExpandedControls
▸ showExpandedControls(): Promise‹boolean›
Displays the Expanded Controls screen programmatically. Users can also open it by clicking on Mini Controls.
Returns: Promise‹boolean›
true
if the Expanded Controls were shown, false
if it was not shown.
Static
showIntroductoryOverlay
▸ showIntroductoryOverlay(options?
: undefined | object): Promise‹boolean›
If it has not been shown before, presents a fullscreen modal view controller that calls attention to the Cast button and displays some brief instructional text about its use.
By default, the overlay is only displayed once. To change this, pass once: false
in the options.
Parameters:
Name | Type |
---|---|
options? | undefined | object |
Returns: Promise‹boolean›
Promise that becomes true
if the view controller was shown, false
if it was not shown because it had already been shown before, or if the Cast Button was not found.
Static
showPlayServicesErrorDialog
▸ showPlayServicesErrorDialog(playServicesState
: PlayServicesState): Promise‹boolean›
(Android only) Show a dialog with a localized message about the error state. Upon user confirmation (by tapping on dialog) will direct them to the Play Store if Google Play services is out of date or missing, or to system settings if Google Play services is disabled on the device.
see
Android
Parameters:
Name | Type | Description |
---|---|---|
playServicesState | PlayServicesState | state returned from CastContext.getPlayServicesState. If it's success , the dialog will not be shown. |
Returns: Promise‹boolean›