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
Properties
Methods
Constructors
Private
constructor
+ new CastChannel(data
: CastChannel, onMessage?
: undefined | function): CastChannel
Parameters:
Name | Type |
---|---|
data | CastChannel |
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:
Name | Type |
---|---|
message | Record‹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:
Name | Type |
---|---|
message | Record‹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:
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. |
onMessage? | undefined | function | function to be invoked when we receive a message from the connected Cast receiver. |
Returns: Promise‹CastChannel›