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

CastChannel

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.

see Custom Channels

example

import { CastChannel } from 'react-native-google-cast'

const channel = await castSession.addChannel('urn:x-cast:com.example.custom')

channel.sendMessage('...')

Hierarchy

  • CastChannel

Index

Constructors

  • constructor

Properties

  • channelListener
  • connected
  • messageListener
  • namespace
  • writable

Methods

  • offMessage
  • offUpdate
  • onMessage
  • onUpdate
  • remove
  • sendMessage
  • add

Constructors

Private constructor

+ new CastChannel(data: CastChannel, onMessage?: undefined | function): CastChannel

Parameters:

NameType
dataCastChannel
onMessage?undefined | function

Returns: CastChannel

Properties

Private channelListener

• channelListener: EventSubscription | undefined


Optional connected

• connected? : undefined | false | true

A flag indicating whether this channel is currently connected.


Private messageListener

• messageListener: EventSubscription | undefined


namespace

• namespace: string

A custom channel identifier starting with urn:x-cast:.


Optional writable

• writable? : undefined | false | true

A flag indicating whether this channel is currently writable.

Methods

offMessage

▸ offMessage(): void

Unregister a message listener.

Returns: void


Private offUpdate

▸ offUpdate(): void

Returns: void


onMessage

▸ onMessage(listener: function): void

Register a message listener. If one already exists, it will be replaced.

Parameters:

▪ listener: function

function to be invoked when we receive a message from the connected Cast receiver.

▸ (message: Record‹string, any› | string): void

Parameters:

NameType
messageRecord‹string, any› | string

Returns: void


Private onUpdate

▸ onUpdate(): void

Returns: void


remove

▸ remove(): Promise‹void›

Remove the channel when it's no longer needed. By calling this method, the underlying channel will be destroyed.

Returns: Promise‹void›


sendMessage

▸ sendMessage(message: Record‹string, any› | string): Promise‹void›

Send a message to the connected Cast receiver using this channel. Note that by default you need to send the message as a JSON object, unless you've initialized the namespace on the receiver to be of the string type.

To listen for responses, register an {#onMessage} listener.

Parameters:

NameType
messageRecord‹string, any› | string

Returns: Promise‹void›


Static add

▸ add(namespace: string, onMessage?: undefined | function): Promise‹CastChannel›

Add a custom channel to a connected session. This method is equivalent to {@link CastSession#addChannel}.

Parameters:

NameTypeDescription
namespacestringA 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.
onMessage?undefined | functionfunction to be invoked when we receive a message from the connected Cast receiver.

Returns: Promise‹CastChannel›

← ExpandedControllerCastContext →
  • Hierarchy
  • Index
    • Constructors
    • Properties
    • Methods
  • Constructors
    • Private constructor
  • Properties
    • Private channelListener
    • Optional connected
    • Private messageListener
    • namespace
    • Optional writable
  • Methods
    • offMessage
    • Private offUpdate
    • onMessage
    • Private onUpdate
    • remove
    • sendMessage
    • Static add