DiscoveryManager
A class that manages the device discovery process.
The framework automatically starts the discovery process when the application moves to the foreground and suspends it when the application moves to the background. On iOS, it is possible to use startDiscovery
/stopDiscovery
, as an optimization measure to reduce network traffic and CPU utilization in areas of the application that do not use Cast functionality.
If the application is using the framework's Cast dialog, then that dialog will use DiscoveryManager
to populate its list of available devices. If however the application is providing its own device selection/control dialog UI, then it should use getDevices
and onDevicesUpdated
to populate and update its list of available devices.
example
import GoogleCast from 'react-native-google-cast'
function MyComponent() {
const discoveryManager = GoogleCast.getDiscoveryManager()
discoveryManager.startDiscovery()
}
Hierarchy
- DiscoveryManager
Index
Methods
Methods
getDevices
▸ getDevices(): Promise‹Device[]›
List currently available devices.
Returns: Promise‹Device[]›
isPassiveScan
▸ isPassiveScan(): Promise‹boolean›
(iOS only) A flag indicating whether discovery should employ a "passive" scan. Passive scans are less resource-intensive but do not provide results that are as fresh as active scans.
Returns: Promise‹boolean›
isRunning
▸ isRunning(): Promise‹boolean›
(iOS only) Check whether discovery is currently running, i.e. it either started automatically, or user initially pressed a Cast button, or startDiscovery
has been called.
Returns: Promise‹boolean›
onDevicesUpdated
▸ onDevicesUpdated(listener
: function): EmitterSubscription
Listen for changes to the list of devices.
Hint Use the useDevices
hook instead that manages getDevices
and onDevicesUpdated
for you.
example
const subscription = GoogleCast.getDiscoverManager().onDevicesUpdated(devices => {
// ... display a list of devices
})
// later, to stop listening
subscription.remove()
Parameters:
▪ listener: function
▸ (devices
: Device[]): void
Parameters:
Name | Type |
---|---|
devices | Device[] |
Returns: EmitterSubscription
setPassiveScan
▸ setPassiveScan(on
: boolean): Promise‹void›
(iOS only)* Set whether to use "passive" scan for discovery.
Parameters:
Name | Type |
---|---|
on | boolean |
Returns: Promise‹void›
startDiscovery
▸ startDiscovery(): Promise‹void›
(iOS only) Starts the device discovery process.
Returns: Promise‹void›
stopDiscovery
▸ stopDiscovery(): Promise‹void›
(iOS only) Stops the device discovery process.
Returns: Promise‹void›