Manages cast interaction. A singleton object that is fetched using
getInstance.
Manages states - provide the state of the cast icon, and session object.
Cast interaction is not supported till the cast options are provided by
setOptions.
Opens the cast selection UI, to allow user to start or stop session.
Throws
Error If the context options were not provided yet.
Returns
non-null Promise containing nullable chrome.cast.ErrorCode A promise to indicate session
is starting, or failed (rejected with error code).
setLaunchCredentialsData
setLaunchCredentialsData(credentialsData)
Sets the user credentials data. Will be ignored if called before
setOptions. Calling setOptions after setLaunchCredentialsData will
clear the value set in setLaunchCredentialsData.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["\u003cp\u003e\u003ccode\u003ecast.framework.CastContext\u003c/code\u003e is a singleton object that manages cast interactions and states, including the cast icon and session object.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for managing sessions, such as starting and ending them, retrieving the current session state, and adding or removing event listeners.\u003c/p\u003e\n"],["\u003cp\u003eCast interaction requires setting cast options using \u003ccode\u003esetOptions\u003c/code\u003e, and credentials can be optionally set using \u003ccode\u003esetLaunchCredentialsData\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve the \u003ccode\u003eCastContext\u003c/code\u003e instance using \u003ccode\u003egetInstance\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003erequestSession\u003c/code\u003e method initiates the cast selection UI, enabling users to select a device and start a casting session.\u003c/p\u003e\n"]]],["The `CastContext` class manages cast interactions via a singleton instance. Key actions include: fetching the instance via `getInstance`, setting options with `setOptions`, and setting user credentials using `setLaunchCredentialsData`. It provides session management, allowing users to start sessions with `requestSession` and end them with `endCurrentSession`. It allows to manage event listeners via `addEventListener` and `removeEventListener` methods. `getCastState`, `getCurrentSession`, and `getSessionState` provide the current cast icon, session, and session states.\n"],null,["# Class: CastContext\n\ncast.[framework](/cast/docs/reference/web_sender/cast.framework).CastContext\n============================================================================\n\nclass static\n\nManages cast interaction. A singleton object that is fetched using\ngetInstance.\nManages states - provide the state of the cast icon, and session object.\nCast interaction is not supported till the cast options are provided by\nsetOptions.\n\nConstructor\n-----------\n\n### CastContext\n\nnew\nCastContext()\n\nMethods\n-------\n\n### getInstance\n\nstatic\n\ngetInstance() returns [cast.framework.CastContext](/cast/docs/reference/web_sender/cast.framework.CastContext)\n\nReturns the CastContext singleton instance.\n\nReturns\n\n: [cast.framework.CastContext](/cast/docs/reference/web_sender/cast.framework.CastContext) A singleton instance\n of the CastContext.\n\n### addEventListener\n\naddEventListener(type, handler)\n\nAdds an event listener.\n\n| #### Parameter ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| type | [cast.framework.CastContextEventType](/cast/docs/reference/web_sender/cast.framework#.CastContextEventType) Event type. Value must not be null. |\n| handler | (non-null function(non-null [cast.framework.CastStateEventData](/cast/docs/reference/web_sender/cast.framework.CastStateEventData)) or non-null function(non-null [cast.framework.SessionStateEventData](/cast/docs/reference/web_sender/cast.framework.SessionStateEventData))) |\n\n### endCurrentSession\n\nendCurrentSession(stopCasting)\n\nEnds current session.\n\n| #### Parameter ||\n|-------------|--------------------------------------------------------------------------|\n| stopCasting | boolean Should the receiver application be stopped or just disconnected. |\n\n### getCastState\n\ngetCastState() returns [cast.framework.CastState](/cast/docs/reference/web_sender/cast.framework#.CastState)\n\nReturns\n\n: `non-null `[cast.framework.CastState](/cast/docs/reference/web_sender/cast.framework#.CastState) Current cast icon state.\n\n### getCurrentSession\n\ngetCurrentSession() returns [cast.framework.CastSession](/cast/docs/reference/web_sender/cast.framework.CastSession)\n\nReturns\n\n: `nullable `[cast.framework.CastSession](/cast/docs/reference/web_sender/cast.framework.CastSession) Current session.\n\n### getSessionState\n\ngetSessionState() returns [cast.framework.SessionState](/cast/docs/reference/web_sender/cast.framework#.SessionState)\n\nReturns\n\n: `non-null `[cast.framework.SessionState](/cast/docs/reference/web_sender/cast.framework#.SessionState) Current session state.\n\n### removeEventListener\n\nremoveEventListener(type, handler)\n\nRemoves an event listener.\n\n| #### Parameter ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| type | [cast.framework.CastContextEventType](/cast/docs/reference/web_sender/cast.framework#.CastContextEventType) Event type. Value must not be null. |\n| handler | (non-null function(non-null [cast.framework.CastStateEventData](/cast/docs/reference/web_sender/cast.framework.CastStateEventData)) or non-null function(non-null [cast.framework.SessionStateEventData](/cast/docs/reference/web_sender/cast.framework.SessionStateEventData))) |\n\n### requestSession\n\nrequestSession() returns Promise containing nullable [chrome.cast.ErrorCode](/cast/docs/reference/web_sender/chrome.cast#.ErrorCode)\n\nOpens the cast selection UI, to allow user to start or stop session.\n\nThrows\n\n: `Error` If the context options were not provided yet.\n\nReturns\n\n: `non-null Promise containing nullable `[chrome.cast.ErrorCode](/cast/docs/reference/web_sender/chrome.cast#.ErrorCode) A promise to indicate session\n is starting, or failed (rejected with error code).\n\n### setLaunchCredentialsData\n\nsetLaunchCredentialsData(credentialsData)\n\nSets the user credentials data. Will be ignored if called before\nsetOptions. Calling setOptions after setLaunchCredentialsData will\nclear the value set in setLaunchCredentialsData.\n\n| #### Parameter ||\n|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| credentialsData | [chrome.cast.CredentialsData](/cast/docs/reference/web_sender/chrome.cast.CredentialsData) Credentials data used to identify the credentials of the sender. Value must not be null. |\n\n### setOptions\n\nsetOptions(options)\n\nSets the cast options.\nEvents will only be sent once config was provided.\n\n| #### Parameter ||\n|---------|---------------------------------------------------------------------------------------------------------------------------------------------|\n| options | [cast.framework.CastOptions](/cast/docs/reference/web_sender/cast.framework.CastOptions) Cast options for the page. Value must not be null. |\n\nThrows\n\n: `non-null Error` If the options are missing application id."]]