chrome.
cast
This is the chrome.cast namespace.
Classes
ApiConfig
Holds the configuration for the API when initialized.
CredentialsData
Credentials data used to identify the credentials of the sender.
DialRequest
A request to start a DIAL app.
Error
Describes an error returned by the API. Normally, these objects should not be created by the client.
Image
An image that describes a receiver application or media item. This could be an application icon, cover art, or a thumbnail.
Receiver
Describes the receiver running an application. Normally, these objects should not be created by the client.
ReceiverDisplayStatus
Receiver status shown to the user in the extension UI. Only valid for CUSTOM receivers.
SenderApplication
Describes a sender application. Normally, these objects should not be created by the client.
Session
Describes the state of a currently running Cast application. Normally, these objects should not be created by the client.
SessionRequest
A request to start or connect to a session.
Timeout
Defines default timeout values in milliseconds for API methods.
Volume
The volume of a device or media stream.
Namespace
media
Enumerations
AutoJoinPolicy
string
Auto-join policy determines when the SDK will automatically connect a sender application to an existing session after API initialization.
Value
TAB_AND_ORIGIN_SCOPED
string
Automatically connects when the session was started with the same appId, in the same tab and page origin.
ORIGIN_SCOPED
string
Automatically connects when the session was started with the same appId and the same page origin (regardless of tab).
PAGE_SCOPED
string
No automatic connection.
Capability
string
Capabilities that are supported by the receiver device.
Value
VIDEO_OUT
string
The receiver supports video output.
AUDIO_OUT
string
The receiver supports audio output.
VIDEO_IN
string
The receiver supports video input (camera).
AUDIO_IN
string
The receiver supports audio input (microphone).
MULTIZONE_GROUP
string
The receiver represents a multi-zone group.
DefaultActionPolicy
string
Default action policy determines when the SDK will automatically create a session after initializing the API. This also controls the default action for the tab in the extension popup.
Value
CREATE_SESSION
string
If the tab containing the app is being casted when the API initializes, the SDK stops tab casting and automatically launches the app. The extension popup prompts the user to cast the app.
CAST_THIS_TAB
string
No automatic launch is done after initializing the API, even if the tab is being cast. The extension popup prompts the user to cast the tab.
DialAppState
string
Possible states of a DIAL application.
Value
RUNNING
string
STOPPED
string
ERROR
string
Not part of the spec, used to signal errors.
ErrorCode
string
Errors that may be returned by the SDK.
Value
CANCEL
string
The operation was canceled by the user.
TIMEOUT
string
The operation timed out.
API_NOT_INITIALIZED
string
The API is not initialized.
INVALID_PARAMETER
string
The parameters to the operation were not valid.
EXTENSION_NOT_COMPATIBLE
string
The API script is not compatible with the installed Cast extension.
EXTENSION_MISSING
string
The Cast extension is not available.
RECEIVER_UNAVAILABLE
string
No receiver was compatible with the session request.
SESSION_ERROR
string
A session could not be created, or a session was invalid.
CHANNEL_ERROR
string
A channel to the receiver is not available.
LOAD_MEDIA_FAILED
string
Load media failed.
ReceiverAction
string
Actions that the user can take on a receiver in the extension. These can be used to show a transition in the sender application UI before the casting action has fully completed (or failed).
Value
CAST
string
The user selected a receiver with the intent of casting to it with the sender application. The exact identity of the receiver may not be known.
STOP
string
The user requested to stop the session running on a receiver.
ReceiverAvailability
string
Describes availability of a Cast receiver.
Value
AVAILABLE
string
At least one receiver is available that is compatible with the session request.
UNAVAILABLE
string
No receivers are available.
ReceiverType
string
Value
CAST
string
Cast receiver, e.g. Chromecast
DIAL
string
DIAL device, e.g. smart TV
HANGOUT
string
Hangout
CUSTOM
string
Custom receiver provided by client
SenderPlatform
string
Describes a sender application platform.
Value
CHROME
string
IOS
string
ANDROID
string
SessionStatus
string
Describes status of a Cast session to its receiver application.
Value
CONNECTED
string
The session is connected to the receiver application.
DISCONNECTED
string
The session is disconnected from the receiver application. The receiver application may or may not still be running.
STOPPED
string
The receiver application has been stopped.
VolumeControlType
string
Describes types of volume control.
Value
ATTENUATION
string
Cast device volume can be changed.
FIXED
string
Cast device volume is fixed and cannot be changed.
MASTER
string
Master system volume control, i.e. TV or Audio device volume is changed.
Properties
AutoJoinPolicy
string
Auto-join policy determines when the SDK will automatically connect a sender application to an existing session after API initialization.
Value
TAB_AND_ORIGIN_SCOPED
string
Automatically connects when the session was started with the same appId, in the same tab and page origin.
ORIGIN_SCOPED
string
Automatically connects when the session was started with the same appId and the same page origin (regardless of tab).
PAGE_SCOPED
string
No automatic connection.
Capability
string
Capabilities that are supported by the receiver device.
Value
VIDEO_OUT
string
The receiver supports video output.
AUDIO_OUT
string
The receiver supports audio output.
VIDEO_IN
string
The receiver supports video input (camera).
AUDIO_IN
string
The receiver supports audio input (microphone).
MULTIZONE_GROUP
string
The receiver represents a multi-zone group.
DefaultActionPolicy
string
Default action policy determines when the SDK will automatically create a session after initializing the API. This also controls the default action for the tab in the extension popup.
Value
CREATE_SESSION
string
If the tab containing the app is being casted when the API initializes, the SDK stops tab casting and automatically launches the app. The extension popup prompts the user to cast the app.
CAST_THIS_TAB
string
No automatic launch is done after initializing the API, even if the tab is being cast. The extension popup prompts the user to cast the tab.
DialAppState
string
Possible states of a DIAL application.
Value
RUNNING
string
STOPPED
string
ERROR
string
Not part of the spec, used to signal errors.
ErrorCode
string
Errors that may be returned by the SDK.
Value
CANCEL
string
The operation was canceled by the user.
TIMEOUT
string
The operation timed out.
API_NOT_INITIALIZED
string
The API is not initialized.
INVALID_PARAMETER
string
The parameters to the operation were not valid.
EXTENSION_NOT_COMPATIBLE
string
The API script is not compatible with the installed Cast extension.
EXTENSION_MISSING
string
The Cast extension is not available.
RECEIVER_UNAVAILABLE
string
No receiver was compatible with the session request.
SESSION_ERROR
string
A session could not be created, or a session was invalid.
CHANNEL_ERROR
string
A channel to the receiver is not available.
LOAD_MEDIA_FAILED
string
Load media failed.
isAvailable
boolean
Flag for clients to check whether the API is loaded.
ReceiverAction
string
Actions that the user can take on a receiver in the extension. These can be used to show a transition in the sender application UI before the casting action has fully completed (or failed).
Value
CAST
string
The user selected a receiver with the intent of casting to it with the sender application. The exact identity of the receiver may not be known.
STOP
string
The user requested to stop the session running on a receiver.
ReceiverAvailability
string
Describes availability of a Cast receiver.
Value
AVAILABLE
string
At least one receiver is available that is compatible with the session request.
UNAVAILABLE
string
No receivers are available.
ReceiverType
string
Value
CAST
string
Cast receiver, e.g. Chromecast
DIAL
string
DIAL device, e.g. smart TV
HANGOUT
string
Hangout
CUSTOM
string
Custom receiver provided by client
SenderPlatform
string
Describes a sender application platform.
Value
CHROME
string
IOS
string
ANDROID
string
SessionStatus
string
Describes status of a Cast session to its receiver application.
Value
CONNECTED
string
The session is connected to the receiver application.
DISCONNECTED
string
The session is disconnected from the receiver application. The receiver application may or may not still be running.
STOPPED
string
The receiver application has been stopped.
timeout
non-null chrome.cast.Timeout
Default timeout values in milliseconds for API methods.
VERSION
non-null Array of number
The API version. The first number is the major version, and the second the minor version.
VolumeControlType
string
Describes types of volume control.
Value
ATTENUATION
string
Cast device volume can be changed.
FIXED
string
Cast device volume is fixed and cannot be changed.
MASTER
string
Master system volume control, i.e. TV or Audio device volume is changed.
Methods
addReceiverActionListener
addReceiverActionListener(listener)
Adds a listener function that will be invoked when the user has acted through the UI to start or stop casting. The sender application can use this to show a transition in its user interface (i.e., pause locally playing media) before the casting action has completed or failed.
- The listener is not guaranteed to be invoked and applications should not rely on it to function correctly.
- The listener will be passed the receiver that was acted upon, if available. However the receiver may not be known and null will be passed instead.
- The listener will be called as soon as possible after the user has acted. It should be invoked before the application is notified of the resulting state change through the API.
If using Framework API, use cast.framework.CastContext#addEventListener
instead and listen to
cast.framework.CastContextEventType#CAST_STATE_CHANGED events. listener chrome.cast.ReceiverActionListener
The listener function
to add. The first argument to the listener is the receiver that was acted
on. The second argument to the listener is the action that was requested
(see chrome.cast.ReceiverAction). Value must not be null.Parameter
initialize
initialize(apiConfig, successCallback, errorCallback)
Initializes the API. Note that either successCallback and errorCallback will be invoked once the API has finished initialization. The sessionListener and receiverListener may be invoked at any time afterwards, and possibly more than once.
If using Framework API, use cast.framework.CastContext#setOptions
instead of this function. apiConfig successCallback function() errorCallback function(non-null chrome.cast.Error
) The possible errors are
TIMEOUT, INVALID_PARAMETER, EXTENSION_MISSING.Parameter
logMessage
logMessage(message)
Logs a debug message from the app. This message may be sent in a feedback report to Google if users explicitly choose to include fine logs.
Parameter
message
string
The message to log.
- Deprecated
- Not supported with Presentation API based Cast SDK.
precache
precache(data)
Send a request to precache data. If a session is connected it will send a direct request, otherwise it will send to all devices in the network.
Parameter
data
string
Data to precache.
- Deprecated
- Not supported.
removeReceiverActionListener
removeReceiverActionListener(listener)
Removes a listener function that was previously added with addReceiverActionListener.
Parameter
listener
requestSession
requestSession(successCallback, errorCallback, sessionRequest)
Requests that a receiver application session be created or joined. By default, the SessionRequest passed to the API at initialization time is used; this may be overridden by passing a different session request in sessionRequest.
If using Framework API, use cast.framework.CastContext#requestSession
instead of this function. successCallback function(non-null chrome.cast.Session
) errorCallback function(non-null chrome.cast.Error
) The possible errors are
TIMEOUT, INVALID_PARAMETER, API_NOT_INITIALIZED, CANCEL, CHANNEL_ERROR,
SESSION_ERROR, RECEIVER_UNAVAILABLE, and EXTENSION_MISSING.
Note that the timeout timer starts after users select a receiver.
Selecting a receiver requires user's action, which has no timeout.
If a session request is already in progress, errorCallback is invoked with
INVALID_PARAMETER error code and a description explaining the error. sessionRequestParameter
requestSessionById
requestSessionById(sessionId)
Requests to join an existing session with the given id. Once joined, the session will be passed to the sessionListener set by chrome.cast.initialize.
If the session with the given sessionId is already known when this function is called, then sessionListener is called immediately. Otherwise, once a session with the given sessionId is discovered, sessionListener will be called.
Parameter
sessionId
string
The id of the session to join.
setCustomReceivers
setCustomReceivers(receivers, successCallback, errorCallback)
Sets custom receiver list
Parameter
receivers
successCallback
function()
errorCallback
function(non-null chrome.cast.Error )
The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, and EXTENSION_MISSRING.
- Deprecated
- Not supported with Presentation API based Cast SDK.
setPageContext
setPageContext(win)
Initializes Cast functionality for a page that loads Cast SDK in an iframe. Should be called after the SDK was initialized.
Parameter
win
Window
Page window object.
Value must not be null.
setReceiverDisplayStatus
setReceiverDisplayStatus(receiver, successCallback, errorCallback)
Sets the receiver name and display status. To show the receiver as idle, set displayStatus to null.
Only valid for CUSTOM receivers. The receiver's displayStatus is ignored if this receiver is CAST; Cast receiver status is updated by the receiver application.
Parameter
receiver
successCallback
function()
Callback when setting status succeeds.
errorCallback
function(non-null chrome.cast.Error )
The possible errors are TIMEOUT, INVALID_PARAMETER, API_NOT_INITIALIZED, and EXTENSION_MISSING.
- Deprecated
- Not supported with Presentation API based Cast SDK.
unescape
unescape(escaped) returns string
Utility method to unescape URI-escaped strings. For example, the receiver friendly name is returned as an URI-escaped string. Use this method to unescape that string if needed.
Parameter
escaped
string
A string to unescape
- Returns
-
string
Unescaped string
Abstract type
ReceiverActionListener
ReceiverActionListener()