react-native-google-cast
Version:
React Native wrapper for the Google Cast SDK for iOS and Android
25 lines (18 loc) • 610 B
text/typescript
import { useEffect, useState } from 'react'
import Device from '../types/Device'
import CastContext from './CastContext'
/**
* Hook that listens to changes to available devices and returns current list.
*/
export default function useDevices(): Device[] {
const discoveryManager = CastContext.getDiscoveryManager()
const [devices, setDevices] = useState<Device[]>([])
useEffect(() => {
discoveryManager.getDevices().then(setDevices)
const listener = discoveryManager.onDevicesUpdated(setDevices)
return () => {
listener.remove()
}
}, [discoveryManager])
return devices
}