cast.framework. CastReceiverContext
Manages loading of underlying libraries and initializes underlying cast receiver SDK.
- Throws
-
non-null Error
If MediaElement is not created on document body. If multiple media elements are created, developer should set 'castMediaElement' class to one of them, which CAF receiver will use.
Methods
getInstance
getInstance() returns cast.framework.CastReceiverContext
Returns the CastReceiverContext singleton instance.
- Returns
-
non-null cast.framework.CastReceiverContext
addCustomMessageListener
addCustomMessageListener(namespace, listener)
Sets up a message listener for a custom message channel. More than one listener is allowed for a namespace.
Parameter |
|
---|---|
namespace |
string The namespace. Note that a valid namespace has to be prefixed with the string 'urn:x-cast:'. |
listener |
function(non-null cast.framework.system.Message) |
- Throws
-
Error
If system is not ready or the namespace is not supported by this application.
addEventListener
addEventListener(type, handler)
Add listener to cast system events.
Parameter |
|
---|---|
type |
cast.framework.system.EventType Value must not be null. |
handler |
function(non-null cast.framework.system.Event) |
canDisplayType
canDisplayType(mimeType, codecs, width, height, framerate) returns boolean
Checks if the given media params of video or audio streams are supported by the platform.
Parameter |
|
---|---|
mimeType |
string Media MIME type. It consists of a type and subtype separated by a '/'. It can be either video or audio mime types. |
codecs |
Optional string Quoted-string contains a comma-separated list of formats, where each format specifies a media sample type that is present in the stream. |
width |
Optional number Describes the stream horizontal resolution in pixels. |
height |
Optional number Describes the stream vertical resolution in pixels. |
framerate |
Optional number Describes the frame rate of the stream. |
- Returns
-
boolean
If the stream can be played on chromecast.
getApplicationData
getApplicationData() returns cast.framework.system.ApplicationData
Provides application information once the system is ready, otherwise it will be null.
- Returns
-
nullable cast.framework.system.ApplicationData
The application information or null if the system is not ready.
getDeviceCapabilities
getDeviceCapabilities() returns Object
Provides device capabilities information once the system is ready, otherwise it will be null. If an empty object is returned, the device does not expose any capabilities information.
- Returns
-
nullable Object
The device capabilities information (key/value pairs). It will be null if the system is not ready yet. It may be an empty object if the platform does not expose any device capabilities information.
getPlayerManager
getPlayerManager() returns cast.framework.PlayerManager
Get Player instance that can control and monitor media playback.
- Returns
-
non-null cast.framework.PlayerManager
getSender
getSender(senderId) returns cast.framework.system.Sender
Get a sender by sender id
Parameter |
|
---|---|
senderId |
string The id of the sender to return. |
- Returns
-
nullable cast.framework.system.Sender
getSenders
getSenders() returns Array of non-null cast.framework.system.Sender
Gets a list of currently-connected senders.
- Returns
-
non-null Array of non-null cast.framework.system.Sender
getStandbyState
getStandbyState() returns cast.framework.system.StandbyState
Reports if the cast application's HDMI input is in standby.
- Returns
-
non-null cast.framework.system.StandbyState
Whether the application's HDMI input is in standby or not. If it can not be determined, because the TV does not support CEC commands,for example, the value returned is UNKNOWN.
getSystemState
getSystemState() returns cast.framework.system.SystemState
Provides application information about the system state.
- Returns
-
non-null cast.framework.system.SystemState
The system state.
getVisibilityState
getVisibilityState() returns cast.framework.system.VisibilityState
Reports if the cast application is the HDMI active input.
- Returns
-
non-null cast.framework.system.VisibilityState
Whether the application is the HDMI active input. If it can not be determined, because the TV does not support CEC commands,for example, the value returned is UNKNOWN.
isSystemReady
isSystemReady() returns boolean
When the application calls start, the system will send the ready event to indicate that the application information is ready and the application can send messages as soon as there is one sender connected.
- Returns
-
boolean
Whether or not the system is ready to process messages.
loadPlayerLibraries
loadPlayerLibraries(useLegacyDashSupport)
Start loading player js. This can be used to start loading the players js code in early stage of starting the receiver before calling start. This function is a no-op if players were already loaded (start was called).
Parameter |
|
---|---|
useLegacyDashSupport |
Optional boolean Indicate that MPL should be used for DASH content. |
removeCustomMessageListener
removeCustomMessageListener(namespace, listener)
Removes a message listener previously registered with
CastReceiverContext#addCustomMessageListener
.
Parameter |
|
---|---|
namespace |
string The namespace. Note that a valid namespace has to be prefixed with the string 'urn:x-cast:'. |
listener |
function(non-null cast.framework.system.Message) The message listener function to unregister. |
- Throws
-
Error
If system is not ready or the namespace is not supported by this application.
removeEventListener
removeEventListener(type, handler)
Remove listener to cast system events.
Parameter |
|
---|---|
type |
cast.framework.system.EventType Value must not be null. |
handler |
function(non-null cast.framework.system.Event) |
sendCustomMessage
sendCustomMessage(namespace, senderId, data)
Sends a message to a specific sender.
Parameter |
|
---|---|
namespace |
string The namespace. Note that a valid namespace has to be prefixed with the string 'urn:x-cast:'. |
senderId |
(string or undefined) The senderId, or undefined for broadcast to all senders. |
data |
any type The message payload. Value must not be null. |
- Throws
-
Error
If there was an error preparing the message.
sendFeedbackMessage
sendFeedbackMessage(feedbackMessage)
This function should be called in response to the feedbackstarted event if the application add debug state information to log in the feedback report. It takes in a parameter ‘message’ that is a string that represents the debug information that the application wants to log.
Parameter |
|
---|---|
feedbackMessage |
string |
- Deprecated
- Use cast.framework.CastReceiverContext#setFeedbackHandler
setApplicationState
setApplicationState(statusText)
Sets the application state. The application should call this when its state changes. If undefined or set to an empty string, the value of the Application Name established during application registration is used for the application state by default.
Parameter |
|
---|---|
statusText |
string The status text. |
setFeedbackHandler
setFeedbackHandler(feedbackHandler)
Set a handler to provide additional data to a feedback report. The handler will be called when a feedback reported is created and should return extra data as a string, or a string promise. The return promise should be resolved within 5 seconds for it to be included in the report.
Parameter |
|
---|---|
feedbackHandler |
function() Value may be null. |
setInactivityTimeout
setInactivityTimeout(maxInactivity)
Sets the receiver inactivity timeout. It is recommended to set the maximum inactivity value when calling Start and not changing it. This API is just provided for development/debugging purposes.
Parameter |
|
---|---|
maxInactivity |
number Interval in seconds before closing an unresponsive connection. |
setLoggerLevel
setLoggerLevel(level)
Sets the log verbosity level.
Parameter |
|
---|---|
level |
The logging level. Value must not be null. |
start
start(options) returns cast.framework.CastReceiverContext
Initializes system manager and media manager, so that receiver app can receive requests from senders.
Parameter |
|
---|---|
options |
(non-null cast.framework.CastReceiverOptions or optional non-null Object) |
- Returns
-
non-null cast.framework.CastReceiverContext
stop
stop()
Shutdown receiver application.