Class: CastSession

Constructor

CastSession

new CastSession(sessionObj, state)

Parameter

sessionObj

chrome.cast.Session

Session data.

Value must not be null.

state

cast.framework.SessionState

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.ActiveInputState Receiver active input state.

getApplicationMetadata

getApplicationMetadata() returns cast.framework.ApplicationMetadata

Returns

non-null cast.framework.ApplicationMetadata Application metadata.

getApplicationStatus

getApplicationStatus() returns string

Returns

nullable string Application status string.

getCastDevice

getCastDevice() returns chrome.cast.Receiver

Returns

non-null chrome.cast.Receiver Cast device metadata.

getMediaSession

getMediaSession() returns chrome.cast.media.Media

Returns current media session if available.

Returns

nullable chrome.cast.media.Media Current media session.

getSessionId

getSessionId() returns string

Returns

string Unique ID for this session.

getSessionObj

getSessionObj() returns chrome.cast.Session

Returns

non-null chrome.cast.Session Session data.

getSessionState

getSessionState() returns cast.framework.SessionState

Returns

cast.framework.SessionState Current session state.

getVolume

getVolume() returns number

Returns

nullable number Receiver volume if available.

isMute

isMute() returns boolean

Returns

nullable boolean Receiver muted status if available.

loadMedia

loadMedia(loadRequest) returns Promise containing nullable chrome.cast.ErrorCode

Loads media into a running receiver application.

Parameter

loadRequest

chrome.cast.media.LoadRequest

Value must not be null.

Returns

non-null Promise containing nullable chrome.cast.ErrorCode Promise 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.ErrorCode Resolved 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.ErrorCode Resolved 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.ErrorCode Resolved promise receiver was updated, or rejected with error code if failed.