@hauxir2/capacitor-chromecast
v0.0.7
Published
This is a plugin for Capacitor that enables Chromecast functionality for iOS and Android.
Downloads
114
Maintainers
Readme
@hauxir/capacitor-chromecast
This is a plugin for Capacitor that enables Chromecast functionality for iOS and Android.
Install
npm install @hauxir/capacitor-chromecast
npx cap syncAPI
initialize(...)requestSession()launchMedia(...)loadMedia(...)loadMediaWithHeaders(...)mediaPause()mediaPlay()mediaSeek(...)mediaNext()mediaPrev()sessionStop()sessionLeave()startRouteScan(...)stopRouteScan()selectRoute(...)sendMessage(...)addMessageListener(...)removeMessageListener(...)networkDiagnostic()addListener(string, ...)removeAllListeners()- Interfaces
- Type Aliases
initialize(...)
initialize(options?: InitializeOptions | undefined) => Promise<void>Initialize the Chromecast SDK with optional app ID. If no app ID is provided, the default media receiver is used.
| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | InitializeOptions |
requestSession()
requestSession() => Promise<SessionObject>Request a Chromecast session. This will show the device picker dialog.
Returns: Promise<SessionObject>
launchMedia(...)
launchMedia(options: { mediaUrl: string; }) => Promise<{ success: boolean; }>Simple method to launch media on the current session. For more control, use loadMedia instead.
| Param | Type |
| ------------- | ---------------------------------- |
| options | { mediaUrl: string; } |
Returns: Promise<{ success: boolean; }>
loadMedia(...)
loadMedia(options: LoadMediaOptions) => Promise<MediaObject>Load media with full control over playback options.
| Param | Type |
| ------------- | ------------------------------------------------------------- |
| options | LoadMediaOptions |
Returns: Promise<MediaObject>
loadMediaWithHeaders(...)
loadMediaWithHeaders(options: LoadMediaWithHeadersOptions) => Promise<MediaObject>Load media with authentication headers for protected content.
| Param | Type |
| ------------- | ----------------------------------------------------------------------------------- |
| options | LoadMediaWithHeadersOptions |
Returns: Promise<MediaObject>
mediaPause()
mediaPause() => Promise<void>Pause the current media.
mediaPlay()
mediaPlay() => Promise<void>Play/resume the current media.
mediaSeek(...)
mediaSeek(options: { currentTime: number; }) => Promise<void>Seek to a position in the current media.
| Param | Type |
| ------------- | ------------------------------------- |
| options | { currentTime: number; } |
mediaNext()
mediaNext() => Promise<void>Skip to next item in queue.
mediaPrev()
mediaPrev() => Promise<void>Go to previous item in queue.
sessionStop()
sessionStop() => Promise<void>Stop the current session and stop casting on the receiver.
sessionLeave()
sessionLeave() => Promise<void>Leave the current session but keep the receiver playing.
startRouteScan(...)
startRouteScan(options?: { timeout?: number | undefined; } | undefined) => Promise<{ routes: RouteInfo[]; }>Start scanning for available Chromecast devices.
| Param | Type |
| ------------- | ---------------------------------- |
| options | { timeout?: number; } |
Returns: Promise<{ routes: RouteInfo[]; }>
stopRouteScan()
stopRouteScan() => Promise<void>Stop scanning for devices.
selectRoute(...)
selectRoute(options: { routeId: string; }) => Promise<SessionObject>Connect to a specific device by route ID.
| Param | Type |
| ------------- | --------------------------------- |
| options | { routeId: string; } |
Returns: Promise<SessionObject>
sendMessage(...)
sendMessage(options: { namespace: string; message: string; }) => Promise<SendMessageResult>Send a custom message to the receiver.
| Param | Type |
| ------------- | ---------------------------------------------------- |
| options | { namespace: string; message: string; } |
Returns: Promise<SendMessageResult>
addMessageListener(...)
addMessageListener(options: { namespace: string; }) => Promise<void>Add a listener for messages from the receiver on a specific namespace.
| Param | Type |
| ------------- | ----------------------------------- |
| options | { namespace: string; } |
removeMessageListener(...)
removeMessageListener(options: { namespace: string; }) => Promise<void>Remove a message listener for a specific namespace.
| Param | Type |
| ------------- | ----------------------------------- |
| options | { namespace: string; } |
networkDiagnostic()
networkDiagnostic() => Promise<NetworkDiagnosticResult>Get network diagnostic information.
Returns: Promise<NetworkDiagnosticResult>
addListener(string, ...)
addListener(eventName: string, listenerFunc: ListenerCallback) => Promise<PluginListenerHandle> & PluginListenerHandleAdd a listener for Chromecast events.
Available events:
- SESSION_LISTENER: Fired when a session is rejoined
- SESSION_UPDATE: Fired when session state changes
- SESSION_STARTED: Fired when a new session starts
- SESSION_ENDED: Fired when session ends
- SESSION_RESUMED: Fired when session is resumed
- SESSION_START_FAILED: Fired when session fails to start
- RECEIVER_LISTENER: Fired when receiver availability changes
- MEDIA_LOAD: Fired when media is loaded
- MEDIA_UPDATE: Fired when media state changes
- RECEIVER_MESSAGE: Fired when a custom message is received
- SETUP: Fired when plugin is set up
| Param | Type |
| ------------------ | ------------------------------------------------------------- |
| eventName | string |
| listenerFunc | ListenerCallback |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
removeAllListeners()
removeAllListeners() => Promise<void>Remove all listeners for this plugin.
Interfaces
InitializeOptions
| Prop | Type |
| ------------------------- | ------------------------------------------------------------------------ |
| appId | string |
| autoJoinPolicy | 'tab_and_origin_scoped' | 'origin_scoped' | 'page_scoped' |
| defaultActionPolicy | 'create_session' | 'cast_this_tab' |
SessionObject
| Prop | Type |
| ----------------- | ------------------------------------------------------------------------------------------------- |
| appId | string |
| displayName | string |
| sessionId | string |
| appImages | Array<{ url: string }> |
| receiver | { friendlyName: string; label: string; volume: { level: number; muted: boolean; }; } |
| media | MediaObject[] |
| status | string |
Array
| Prop | Type | Description |
| ------------ | ------------------- | ------------------------------------------------------------------------------------------------------ |
| length | number | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
| Method | Signature | Description | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | toString | () => string | Returns a string representation of an array. | | toLocaleString | () => string | Returns a string representation of an array. The elements are converted to string using their toLocalString methods. | | pop | () => T | undefined | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. | | push | (...items: T[]) => number | Appends new elements to the end of an array, and returns the new length of the array. | | concat | (...items: ConcatArray<T>[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. | | concat | (...items: (T | ConcatArray<T>)[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. | | join | (separator?: string | undefined) => string | Adds all the elements of an array into a string, separated by the specified separator string. | | reverse | () => T[] | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. | | shift | () => T | undefined | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. | | slice | (start?: number | undefined, end?: number | undefined) => T[] | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. | | sort | (compareFn?: ((a: T, b: T) => number) | undefined) => this | Sorts an array in place. This method mutates the array and returns a reference to the same array. | | splice | (start: number, deleteCount?: number | undefined) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | | splice | (start: number, deleteCount: number, ...items: T[]) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | | unshift | (...items: T[]) => number | Inserts new elements at the start of an array, and returns the new length of the array. | | indexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. | | lastIndexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. | | every | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => this is S[] | Determines whether all the members of an array satisfy the specified test. | | every | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether all the members of an array satisfy the specified test. | | some | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether the specified callback function returns true for any element of an array. | | forEach | (callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void | Performs the specified action for each element in an array. | | map | <U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] | Calls a defined callback function on each element of an array, and returns an array that contains the results. | | filter | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => S[] | Returns the elements of an array that meet the condition specified in a callback function. | | filter | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => T[] | Returns the elements of an array that meet the condition specified in a callback function. | | reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | | | reduce | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | | | reduceRight | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
ConcatArray
| Prop | Type |
| ------------ | ------------------- |
| length | number |
| Method | Signature | | --------- | ------------------------------------------------------------------ | | join | (separator?: string | undefined) => string | | slice | (start?: number | undefined, end?: number | undefined) => T[] |
MediaObject
| Prop | Type |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| currentItemId | number |
| currentTime | number |
| customData | Record<string, unknown> |
| mediaSessionId | number |
| playbackRate | number |
| playerState | 'IDLE' | 'PLAYING' | 'PAUSED' | 'BUFFERING' | 'UNKNOWN' |
| idleReason | 'CANCELLED' | 'ERROR' | 'FINISHED' | 'INTERRUPTED' |
| isAlive | boolean |
| volume | { level: number; muted: boolean; } |
| media | { contentId: string; contentType: string; customData: Record<string, unknown>; duration: number; streamType: 'BUFFERED' | 'LIVE' | 'OTHER'; metadata?: MediaMetadata; } |
| sessionId | string |
MediaMetadata
| Prop | Type |
| ------------------ | -------------------------------------------------------------- |
| metadataType | number |
| title | string |
| subtitle | string |
| images | Array<{ url: string }> |
LoadMediaOptions
| Prop | Type |
| -------------------- | ------------------------------------------------------------------------------- |
| contentId | string |
| customData | Record<string, unknown> |
| contentType | string |
| duration | number |
| streamType | 'buffered' | 'live' | 'other' | 'BUFFERED' | 'LIVE' | 'OTHER' |
| autoPlay | boolean |
| currentTime | number |
| metadata | MediaMetadata |
| textTrackStyle | TextTrackStyle |
TextTrackStyle
| Prop | Type |
| ---------------- | ------------------- |
| fontScale | number |
| fontFamily | string |
LoadMediaWithHeadersOptions
| Prop | Type |
| ----------------- | --------------------------------------------------------------- |
| authHeaders | Record<string, string> |
| authToken | string |
RouteInfo
| Prop | Type |
| -------------------- | -------------------- |
| id | string |
| name | string |
| description | string |
| isNearbyDevice | boolean |
SendMessageResult
| Prop | Type |
| ------------- | -------------------- |
| success | boolean |
| error | string |
NetworkDiagnosticResult
| Prop | Type |
| ----------------------------- | -------------------- |
| networkConnected | boolean |
| networkType | string |
| networkState | string |
| isWiFi | boolean |
| warning | string |
| error | string |
| googlePlayServices | boolean |
| gmsError | string |
| castConnectionAvailable | boolean |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
Type Aliases
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
ListenerCallback
(err: any, ...args: any[]): void
