CastSession
Cast sessions are created and managed automatically by the SessionManager, for example when the user selects a Cast device from the media route controller dialog. The current active CastSession can be accessed by {@link CastContext.getCurrentCastSession}.
example
import { useCastSession } from 'react-native-google-cast'
function MyComponent() {
const castSession = useCastSession()
if (castSession) {
// ...
}
}
Hierarchy
- CastSession
Index
Constructors
Properties
Methods
- addChannel
- getActiveInputState
- getApplicationMetadata
- getApplicationStatus
- getCastDevice
- getClient
- getStandbyState
- getVolume
- isMute
- onActiveInputStateChanged
- onStandbyStateChanged
- setMute
- setVolume
Constructors
constructor
+ new CastSession(args
: object): CastSession
Parameters:
▪ args: object
Name | Type |
---|---|
id? | undefined | string |
Returns: CastSession
Properties
client
• client: RemoteMediaClient‹› = new RemoteMediaClient()
Optional
id
• id? : undefined | string
Unique session ID.
Methods
addChannel
▸ addChannel(namespace
: string): Promise‹CastChannel›
Creates a channel for sending custom messages between this sender and the Cast receiver. Use when you've built a custom receiver and want to communicate with it.
Parameters:
Name | Type | Description |
---|---|---|
namespace | string | A custom channel identifier starting with urn:x-cast: , for example urn:x-cast:com.reactnative.googlecast.example . The namespace name is arbitrary; just make sure it's unique. |
Returns: Promise‹CastChannel›
getActiveInputState
▸ getActiveInputState(): Promise‹ActiveInputState›
Indicates whether a receiver device is currently the active video input. Active input state can only be reported when the Google cast device is connected to a TV or AVR with CEC support.
Returns: Promise‹ActiveInputState›
getApplicationMetadata
▸ getApplicationMetadata(): Promise‹ApplicationMetadata›
Returns the metadata for the currently running receiver application, or null
if the metadata is unavailable.
Returns: Promise‹ApplicationMetadata›
getApplicationStatus
▸ getApplicationStatus(): Promise‹string›
Returns the current receiver application status, if any. Message text is localized to the Google Cast device's locale.
see
Android | iOS deviceStatusText | Chrome
Returns: Promise‹string›
getCastDevice
▸ getCastDevice(): Promise‹Device | null›
Returns: Promise‹Device | null›
getClient
▸ getClient(): RemoteMediaClient
Returns: RemoteMediaClient
getStandbyState
▸ getStandbyState(): Promise‹StandbyState›
Indicates whether a receiver device's connected TV or AVR is currently in "standby" mode.
Returns: Promise‹StandbyState›
getVolume
▸ getVolume(): Promise‹number›
Returns the device's volume.
Returns: Promise‹number›
Volume in the range [0.0, 1.0].
isMute
▸ isMute(): Promise‹boolean›
see
Android
Returns: Promise‹boolean›
onActiveInputStateChanged
▸ onActiveInputStateChanged(listener
: function): EmitterSubscription
Listen for changes to the active input state.
example
const subscription = session.onActiveInputStateChanged(state => { ... })
// later, to stop listening
subscription.remove()
Parameters:
▪ listener: function
▸ (state
: ActiveInputState): void
Parameters:
Name | Type |
---|---|
state | ActiveInputState |
Returns: EmitterSubscription
onStandbyStateChanged
▸ onStandbyStateChanged(listener
: function): EmitterSubscription
Listen for changes to the standby state.
example
const subscription = session.onStandbyStateChanged(state => { ... })
// later, to stop listening
subscription.remove()
Parameters:
▪ listener: function
▸ (state
: StandbyState): void
Parameters:
Name | Type |
---|---|
state | StandbyState |
Returns: EmitterSubscription
setMute
▸ setMute(mute
: boolean): void
Mutes or unmutes the device's audio.
Note that this method doesn't currently resolve a promise. You may instead call client.setStreamMuted()
which handles promises correctly.
Parameters:
Name | Type | Description |
---|---|---|
mute | boolean | The new mute state. |
Returns: void
setVolume
▸ setVolume(volume
: number): void
Sets the device volume.
Note that this method doesn't currently resolve a promise. You may instead call client.setStreamVolume()
which handles promises correctly.
Parameters:
Name | Type | Description |
---|---|---|
volume | number | If volume is outside of the range [0.0, 1.0], then the value will be clipped. |
Returns: void