Gerencia a interação de transmissão. Um objeto singleton que é buscado usando getInstance.
Gerencia estados: forneça o estado do ícone de transmissão e do objeto da sessão.
A interação de transmissão não é compatível até que as opções de transmissão sejam fornecidas por setOptions.
Abre a interface de seleção de transmissão para permitir que o usuário inicie ou pare a sessão.
Gera
Error Se as opções de contexto ainda não foram fornecidas.
Retorna
non-null Promise containing nullable chrome.cast.ErrorCode Uma promessa para indicar que a sessão
está sendo iniciada ou falhou (rejeitada com um código de erro).
setLaunchCredentialsData
setLaunchCredentialsData(credentialsData)
Define os dados das credenciais do usuário. Será ignorado se chamado antes de setOptions. Chamar setOptions após setLaunchCredentialsData
limpará o valor definido em setLaunchCredentialsData.
[null,null,["Última atualização 2025-07-25 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."]]