تعامل بازیگران را مدیریت می کند. یک شی singleton که با استفاده از getInstance واکشی می شود. حالت ها را مدیریت می کند - وضعیت نماد پخش و شی جلسه را ارائه می دهد. تعامل Cast تا زمانی که گزینه های Cast توسط setOptions ارائه نشده باشد، پشتیبانی نمی شود.
رابط کاربری انتخاب بازیگران را باز میکند تا کاربر بتواند جلسه را شروع یا متوقف کند.
پرتاب می کند
Error اگر گزینه های زمینه هنوز ارائه نشده باشد.
برمی گرداند
non-null Promise containing nullable chrome.cast.ErrorCode یک وعده برای نشان دادن شروع یا شکست جلسه (با کد خطا رد شد).
setLaunchCredentialsData
setLaunchCredentialsData(CredentialsData)
داده های اعتبار کاربر را تنظیم می کند. اگر قبل از setOptions فراخوانی شود، نادیده گرفته می شود. فراخوانی setOptions بعد از setLaunchCredentialsData مقدار تنظیم شده در setLaunchCredentialsData را پاک می کند.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\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."]]