SessionManager
A class that manages sessions.
A session can be created in two ways:
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.
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.
example
import GoogleCast from 'react-native-google-cast'
function MyComponent() {
const sessionManager = GoogleCast.getSessionManager()
}
Hierarchy
- SessionManager
Index
Accessors
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:
Name | Type | Default | Description |
---|---|---|---|
stopCasting | boolean | false | Should 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:
Name | Type |
---|---|
session | CastSession |
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:
Name | Type |
---|---|
session | CastSession |
Returns: EmitterSubscription
onSessionResumed
▸ onSessionResumed(handler
: function): EmitterSubscription
Parameters:
▪ handler: function
▸ (session
: CastSession): void
Parameters:
Name | Type |
---|---|
session | CastSession |
Returns: EmitterSubscription
onSessionResuming
▸ onSessionResuming(handler
: function): EmitterSubscription
Parameters:
▪ handler: function
▸ (session
: CastSession): void
Parameters:
Name | Type |
---|---|
session | CastSession |
Returns: EmitterSubscription
onSessionStartFailed
▸ onSessionStartFailed(handler
: function): EmitterSubscription
Called when a session has failed to start.
Parameters:
▪ handler: function
▸ (session
: CastSession, error
: string): void
Parameters:
Name | Type |
---|---|
session | CastSession |
error | string |
Returns: EmitterSubscription
onSessionStarted
▸ onSessionStarted(handler
: function): EmitterSubscription
Called when a session has been successfully started.
Parameters:
▪ handler: function
▸ (session
: CastSession): void
Parameters:
Name | Type |
---|---|
session | CastSession |
Returns: EmitterSubscription
onSessionStarting
▸ onSessionStarting(handler
: function): EmitterSubscription
Called when a session is about to be started.
Parameters:
▪ handler: function
▸ (session
: CastSession): void
Parameters:
Name | Type |
---|---|
session | CastSession |
Returns: EmitterSubscription
onSessionSuspended
▸ onSessionSuspended(handler
: function): EmitterSubscription
Parameters:
▪ handler: function
▸ (session
: CastSession): void
Parameters:
Name | Type |
---|---|
session | CastSession |
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:
Name | Type |
---|---|
deviceId | string |
Returns: Promise‹boolean›