AI-generated Key Takeaways
- 
          The CastSession class manages a cast session. 
- 
          It allows adding and removing event listeners and message listeners. 
- 
          You can get information about the session, application, device, and media. 
- 
          Media can be loaded, and messages can be sent to the receiver. 
- 
          Receiver volume and mute status can be controlled. 
cast.framework. CastSession
            Manages a cast session.
Constructor
CastSession
new CastSession(sessionObj, state)
| Parameter | |
|---|---|
| sessionObj | Session data. Value must not be null. | 
| state | Session state. Value must not be null. | 
Methods
addEventListener
addEventListener(type, handler)
Adds an event listener.
| Parameter | |
|---|---|
| type | cast.framework.SessionEventType Event type. Value must not be null. | 
| handler | (function(non-null cast.framework.ApplicationStatusEventData), function(non-null cast.framework.ApplicationMetadataEventData), function(non-null cast.framework.ActiveInputStateEventData), function(non-null cast.framework.MediaSessionEventData), or function(non-null cast.framework.VolumeEventData)) | 
addMessageListener
addMessageListener(namespace, listener)
Adds a listener that is invoked when a message is received from the receiver application. The listener is invoked with the namespace as the first argument and the message as the second argument.
| Parameter | |
|---|---|
| namespace | string The namespace to listen on, e.g. 'urn:x-cast:com.example.namespace'. | 
| listener | function(string, string) The listener to add. | 
endSession
endSession(stopCasting)
Ends the current session.
| Parameter | |
|---|---|
| stopCasting | boolean Should the receiver application be stopped when ending the current session. | 
getActiveInputState
getActiveInputState() returns cast.framework.ActiveInputState
- Returns
- 
                  non-null cast.framework.ActiveInputStateReceiver active input state.
getApplicationMetadata
getApplicationMetadata() returns cast.framework.ApplicationMetadata
- Returns
- 
                  non-null cast.framework.ApplicationMetadataApplication metadata.
getApplicationStatus
getApplicationStatus() returns string
- Returns
- 
                  nullable stringApplication status string.
getCastDevice
getCastDevice() returns chrome.cast.Receiver
- Returns
- 
                  non-null chrome.cast.ReceiverCast device metadata.
getMediaSession
getMediaSession() returns chrome.cast.media.Media
Returns current media session if available.
- Returns
- 
                  nullable chrome.cast.media.MediaCurrent media session.
getSessionId
getSessionId() returns string
- Returns
- 
                  stringUnique ID for this session.
getSessionObj
getSessionObj() returns chrome.cast.Session
- Returns
- 
                  non-null chrome.cast.SessionSession data.
getSessionState
getSessionState() returns cast.framework.SessionState
- Returns
- 
                  cast.framework.SessionStateCurrent session state.
getVolume
getVolume() returns number
- Returns
- 
                  nullable numberReceiver volume if available.
isMute
isMute() returns boolean
- Returns
- 
                  nullable booleanReceiver muted status if available.
loadMedia
loadMedia(loadRequest) returns Promise containing nullable chrome.cast.ErrorCode
Loads media into a running receiver application.
| Parameter | |
|---|---|
| loadRequest | Value must not be null. | 
- Returns
- 
                  non-null Promise containing nullable chrome.cast.ErrorCodePromise to indicate the load succeeded or failed to be sent to the receiver (the session is passed in to media_session event).
removeEventListener
removeEventListener(type, handler)
Removes an event listener.
| Parameter | |
|---|---|
| type | cast.framework.SessionEventType Event type. Value must not be null. | 
| handler | (function(non-null cast.framework.ApplicationStatusEventData), function(non-null cast.framework.ApplicationMetadataEventData), function(non-null cast.framework.ActiveInputStateEventData), function(non-null cast.framework.MediaSessionEventData), or function(non-null cast.framework.VolumeEventData)) | 
removeMessageListener
removeMessageListener(namespace, listener)
Removes a previously added listener for messages.
| Parameter | |
|---|---|
| namespace | string The namespace that is listened to, e.g. 'urn:x-cast:com.example.namespace'. | 
| listener | function(string, string) The listener to remove. | 
sendMessage
sendMessage(namespace, data) returns Promise containing nullable chrome.cast.ErrorCode
Sends a message to the receiver.
| Parameter | |
|---|---|
| namespace | string The namespace to send the message on, e.g. 'urn:x-cast:com.example.namespace'. | 
| data | (non-null Object or string) Data to be sent. | 
- Returns
- 
                  non-null Promise containing nullable chrome.cast.ErrorCodeResolved promise when message was sent, or rejected with error code if failed.
setMute
setMute(isMute) returns Promise containing nullable chrome.cast.ErrorCode
Mute or umute the receiver.
| Parameter | |
|---|---|
| isMute | boolean The new muted status. | 
- Returns
- 
                  non-null Promise containing nullable chrome.cast.ErrorCodeResolved promise receiver was updated, or rejected with error code if failed.
setVolume
setVolume(volume) returns Promise containing nullable chrome.cast.ErrorCode
Sets the receiver volume.
| Parameter | |
|---|---|
| volume | number The new volume level between 0.0 and 1.0. | 
- Returns
- 
                  non-null Promise containing nullable chrome.cast.ErrorCodeResolved promise receiver was updated, or rejected with error code if failed.