Quản lý tương tác truyền. Một đối tượng singleton được tìm nạp bằng getInstance.
Quản lý trạng thái – cung cấp trạng thái của biểu tượng truyền và đối tượng phiên.
Hoạt động tương tác truyền không được hỗ trợ cho đến khi các tuỳ chọn truyền được cung cấp bởi setOptions.
Mở giao diện người dùng chọn chế độ truyền để cho phép người dùng bắt đầu hoặc dừng phiên.
Gửi
Error Nếu các lựa chọn về bối cảnh chưa được cung cấp.
Trả bóng
non-null Promise containing nullable chrome.cast.ErrorCodeLời hứa xác định phiên đang bắt đầu hoặc không thành công (bị từ chối kèm mã lỗi).
setLaunchCredentialsData
setLaunchCredentialsData(credentialsData)
Đặt dữ liệu thông tin xác thực của người dùng. Sẽ bị bỏ qua nếu được gọi trước setOptions. Việc gọi setOptions sau setLaunchCredentialsData sẽ
xoá giá trị đã đặt trong setLaunchCredentialsData.
[null,null,["Cập nhật lần gần đây nhất: 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."]]