React Native Google Cast

React Native Google Cast

  • Docs
  • GitHub

›API

Getting Started

  • Installation
  • Setup
  • Usage
  • Troubleshooting

Guides

  • Custom Channels
  • Customize UI
  • Events
  • Hooks
  • Media Tracks
  • Queueing
  • Volume

Components

  • CastButton
  • ExpandedController

API

  • CastChannel
  • CastContext
  • CastSession
  • DiscoveryManager
  • RemoteMediaClient
  • SessionManager

Types

  • ApplicationMetadata
  • Device
  • MediaInfo
  • MediaLiveSeekableRange
  • MediaLoadRequest
  • MediaMetadata
    • Generic
    • Movie
    • MusicTrack
    • Photo
    • TvShow
    • User
  • MediaQueueContainerMetadata
  • MediaQueueData
  • MediaQueueItem
  • MediaSeekOptions
  • MediaStatus
  • MediaTrack
  • TextTrackStyle
  • UseCastSessionOptions
  • VideoInfo
  • WebImage

Enums

  • ActiveInputState
  • CastState
  • MediaHlsSegmentFormat
  • MediaHlsVideoSegmentFormat
  • MediaPlayerIdleReason
  • MediaPlayerState
  • MediaQueueContainerType
  • MediaQueueType
  • MediaRepeatMode
  • MediaStreamType
  • PlayServicesState
  • StandbyState

SessionManager

A class that manages sessions.

A session can be created in two ways:

  1. A user opens the Cast dialog by pressing the CastButton and selects a device to cast to. An instance of CastSession is created automatically by the SessionManager.

  2. A session is created manually by calling SessionManager.startSession

SessionManager handles automatic resumption of suspended sessions (that is, resuming sessions that were ended when the application went to the background, or in the event that the application crashed or was forcibly terminated by the user). When the application resumes or restarts, the session manager will wait for a short time for the device provider of the suspended session's device to discover that device again, and if it does, it will attempt to reconnect to that device and re-establish the session automatically.

Whether or not the application uses the SessionManager to control sessions, it can attach listeners to be notified of session events, such as onSessionStarted or onSessionEnded.

see Android | iOS

example

import GoogleCast from 'react-native-google-cast'

function MyComponent() {
  const sessionManager = GoogleCast.getSessionManager()
}

Hierarchy

  • SessionManager

Index

Accessors

  • eventEmitter

Methods

  • endCurrentSession
  • getCurrentCastSession
  • onSessionEnded
  • onSessionEnding
  • onSessionResumed
  • onSessionResuming
  • onSessionStartFailed
  • onSessionStarted
  • onSessionStarting
  • onSessionSuspended
  • startSession

Accessors

eventEmitter

• get eventEmitter(): NativeEventEmitter‹›

Returns: NativeEventEmitter‹›

Methods

endCurrentSession

▸ endCurrentSession(stopCasting: boolean): Promise‹void›

End current session. This disconnects the sender from the receiver but the receiver will continue playing (unless stopCasting is set to true).

Parameters:

NameTypeDefaultDescription
stopCastingbooleanfalseShould the receiver application be stopped?

Returns: Promise‹void›


getCurrentCastSession

▸ getCurrentCastSession(): Promise‹CastSession | null›

Returns: Promise‹CastSession | null›


onSessionEnded

▸ onSessionEnded(handler: function): EmitterSubscription

Called when a session has ended, either by request or due to an error.

Parameters:

▪ handler: function

▸ (session: CastSession, error?: undefined | string): void

Parameters:

NameType
sessionCastSession
error?undefined | string

Returns: EmitterSubscription


onSessionEnding

▸ onSessionEnding(handler: function): EmitterSubscription

Called when a session is about to be ended, either by request or due to an error.

Parameters:

▪ handler: function

▸ (session: CastSession): void

Parameters:

NameType
sessionCastSession

Returns: EmitterSubscription


onSessionResumed

▸ onSessionResumed(handler: function): EmitterSubscription

Parameters:

▪ handler: function

▸ (session: CastSession): void

Parameters:

NameType
sessionCastSession

Returns: EmitterSubscription


onSessionResuming

▸ onSessionResuming(handler: function): EmitterSubscription

Parameters:

▪ handler: function

▸ (session: CastSession): void

Parameters:

NameType
sessionCastSession

Returns: EmitterSubscription


onSessionStartFailed

▸ onSessionStartFailed(handler: function): EmitterSubscription

Called when a session has failed to start.

Parameters:

▪ handler: function

▸ (session: CastSession, error: string): void

Parameters:

NameType
sessionCastSession
errorstring

Returns: EmitterSubscription


onSessionStarted

▸ onSessionStarted(handler: function): EmitterSubscription

Called when a session has been successfully started.

Parameters:

▪ handler: function

▸ (session: CastSession): void

Parameters:

NameType
sessionCastSession

Returns: EmitterSubscription


onSessionStarting

▸ onSessionStarting(handler: function): EmitterSubscription

Called when a session is about to be started.

Parameters:

▪ handler: function

▸ (session: CastSession): void

Parameters:

NameType
sessionCastSession

Returns: EmitterSubscription


onSessionSuspended

▸ onSessionSuspended(handler: function): EmitterSubscription

Parameters:

▪ handler: function

▸ (session: CastSession): void

Parameters:

NameType
sessionCastSession

Returns: EmitterSubscription


startSession

▸ startSession(deviceId: string): Promise‹boolean›

Start a casting session with a specific device. You can get a list of available devices from DiscoveryManager.getDevices.

Parameters:

NameType
deviceIdstring

Returns: Promise‹boolean›

← RemoteMediaClientApplicationMetadata →
  • Hierarchy
  • Index
    • Accessors
    • Methods
  • Accessors
    • eventEmitter
  • Methods
    • endCurrentSession
    • getCurrentCastSession
    • onSessionEnded
    • onSessionEnding
    • onSessionResumed
    • onSessionResuming
    • onSessionStartFailed
    • onSessionStarted
    • onSessionStarting
    • onSessionSuspended
    • startSession