با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Co-Watching API تجربه جلسه چندین شرکت کننده را که محتوای برنامه شما را تماشا یا گوش می دهند مدیریت می کند.
این راهنما نحوه پیاده سازی Co-Watching API را توضیح می دهد.
شروع کنید
برای استفاده از Co-Watching API، ابتدا باید افزونه Meet را مستقر کنید . پس از تکمیل این مراحل، میتوانید از API Co-Watching از داخل افزونه جدید خود استفاده کنید.
برای استفاده از Co-Watching API، با دریافت یک شی AddonSession شروع کنید، که به عنوان نقطه ورود برای فعالیت های مشترک Google Meet عمل می کند:
CoWatchingDelegate روشی است که Co-Watching API برنامه شما را هر زمان که وضعیت جدیدی در دسترس باشد به روز می کند. انتظار می رود زمانی که متد onCoWatchingStateChanged() فراخوانی می شود، برنامه شما بلافاصله حالت جدید را اعمال کند.
نمونه کد زیر نحوه استفاده از Co-Watching API را نشان می دهد:
TypeScript
constcoWatchingClient=awaitaddonSession.createCoWatchingClient({activityTitle:"ACTIVITY_TITLE",onCoWatchingStateQuery(){// This function should return the current state of your CoWatching activityreturngetMyApplicationCoWatchingState();},onCoWatchingStateChanged(coWatchingState:CoWatchingState){// This function should apply newState to your ongoing CoWatching activity},});
عنوان رسانه فعالیت خود را جایگزین ACTIVITY_TITLE کنید.
وضعیت فعلی را مدیریت کنید
هنگامی که کاربران در برنامه شما اقدامی انجام می دهند، انتظار می رود که برنامه شما بلافاصله متدهای API ارائه شده را فراخوانی کند.
شما فقط باید این روش ها را در پاسخ به رویدادهای مهم فراخوانی کنید. به عنوان مثال، لازم نیست هر بار که برنامه شما یک ویدیو در حال پخش را پیش می برد، با آنها تماس بگیرید. CoWatchingDelegate که ایجاد میکنید، در این شرایط موقعیتهای پخش بازی را بهروزرسانی میکند.
با استفاده از این روش ها می توانید وضعیت تماشای مشترک را کنترل کنید:
notifyBuffering() : هنگامی که برنامه کاربر به دلیل بافر شدن از سوییچ رسانه قبلی، جستجوی رسانه یا تراکم شبکه شروع به بافر می کند، تماس می گیرد.
notifyPauseState() : تماس زمانی که کاربر رسانه در حال پخش را متوقف یا لغو مکث کند.
notifyPlayoutRate() : زمانی که کاربر سرعت پخش را به یک مقدار جدید (مثلاً 1.25x) به روز می کند، تماس می گیرد.
notifyReady() : وقتی بافر کامل شد و رسانه اکنون برای پخش آماده است، تماس بگیرید.
notifySwitchToMedia() : هر زمان که رسانه در حال پخش فعال تغییر کرد، تماس بگیرید. به عنوان مثال، کاربر یک ویدیوی جدید را انتخاب می کند، یا پخش خودکار ویدیوی بعدی را شروع می کند.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Implement the Co-Watching API\n\n| **Early Access Program:** This feature was only available in limited preview, through an Early Access Program. This program is now closed to new signups.\n\nThe Co-Watching API manages the meeting experience of multiple\nparticipants watching or listening to content in your app.\n\nThis guide explains how to implement the Co-Watching API.\n\nGet started\n-----------\n\nTo use the Co-Watching API, you first must [Deploy a\nMeet add-on](/workspace/meet/add-ons/guides/deploy-add-on). Once\nyou've completed those steps, you can start using the Co-Watching API\nfrom within your new add-on.\n\nTo use the Co-Watching API, start by getting an\n[`AddonSession`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addonsession) object,\nwhich serves as the entry point for Google Meet co-activities: \n\n### TypeScript\n\n const session = await window.meet.addon.createAddonSession({\n cloudProjectNumber: \"\u003cvar translate=\"no\"\u003eCLOUD_PROJECT_NUMBER\u003c/var\u003e\",\n });\n\nReplace \u003cvar translate=\"no\"\u003eCLOUD_PROJECT_NUMBER\u003c/var\u003e with the project number of\nyour Google Cloud project.\n\nCreate a co-watching client\n---------------------------\n\nTo get started, create a\n[`CoWatchingClient`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient)\nobject from your `AddonSession`.\n\nTo create a `CoWatchingCient`, call the\n[`createCoWatchingClient()`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addonsession.createcowatchingclient)\nmethod and provide a\n[`CoWatchingDelegate`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingdelegate)\nobject.\n\nThe `CoWatchingDelegate` is how the Co-Watching API updates your app\nwhenever it has a new state available. It's expected that, when the\n[`onCoWatchingStateChanged()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingdelegate.oncowatchingstatechanged)\nmethod is called, your app immediately applies the new state.\n\nThe following code sample shows how to use the Co-Watching API: \n\n### TypeScript\n\n const coWatchingClient = await addonSession.createCoWatchingClient({\n activityTitle: \"\u003cvar translate=\"no\"\u003eACTIVITY_TITLE\u003c/var\u003e\",\n onCoWatchingStateQuery() {\n // This function should return the current state of your CoWatching activity\n return getMyApplicationCoWatchingState();\n },\n onCoWatchingStateChanged(coWatchingState: CoWatchingState) {\n // This function should apply newState to your ongoing CoWatching activity\n },\n });\n\nReplace \u003cvar translate=\"no\"\u003eACTIVITY_TITLE\u003c/var\u003e with your activity's media title.\n\nManage current state\n--------------------\n\nWhen users take action in your application, it's expected that your application\nimmediately calls the provided API methods.\n\nYou should only call these methods in response to significant events. For\nexample, you don't need to call them every time your app advances a playing\nvideo. The `CoWatchingDelegate` you create handles getting updated playout\npositions in these circumstances.\n\nYou can control the co-watching state using these methods:\n\n- [`notifyBuffering()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifybuffering):\n Call when a user's app starts buffering due to buffering from a prior media\n switch, media seek, or network congestion.\n\n- [`notifyPauseState()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifypausestate):\n Call when a user pauses or unpauses the playing media.\n\n- [`notifyPlayoutRate()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyplayoutrate):\n Call when a user updates the playback speed to a new value (for example,\n 1.25x).\n\n- [`notifyReady()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyready):\n Call when buffering completes and the media is now ready to be played.\n\n- [`notifySeekToTimestamp()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyseektotimestamp):\n Call when a user explicitly changes the play out position.\n\n- [`notifySwitchToMedia()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.cowatchingclient.notifyswitchedtomedia):\n Call whenever the actively playing media changes. For example, the user\n selects a new video, or autoplay starts the next video."]]