實作 Co-Watching API

Co-Watching API 可用來管理 經常觀看或聆聽您應用程式內容的使用者

本指南說明如何實作 Co-Watching API。

開始使用

如要使用 Co-Watching API,您必須先建立 Meet 外掛程式。一次 完成這些步驟後,即可開始使用 Co-Watching API 開啟新的外掛程式

如要使用 Co-Watching API,請先取得 AddonSession, 做為共同活動的進入點:

TypeScript

const session = await window.meet.addon.createAddonSession({
    cloudProjectNumber: "CLOUD_PROJECT_NUMBER",
});

建立 CoWatchingClient

首先,請建立 createCoWatchingClient敬上 來自你的「AddonSession」。

如要建立 CoWatchingCient,請呼叫 AddonSession.createCoWatchingClient 方法,並提供 CoWatchingDelegate

CoWatchingDelegate 是 Co-Watching API 如何更新您的 新的狀態就會影響應用程式這種情況下 CoWatchingDelegate.onCoWatchingStateChanged敬上 方法,應用程式會立即套用新狀態。

以下程式碼範例說明如何使用 Co-Watching API:

TypeScript

 const coWatchingClient = await addonSession.createCoWatchingClient({
    activityTitle: "ACTIVITY_TITLE",
    onCoWatchingStateQuery() {
      // This function should return the current state of your CoWatching activity
      return getMyApplicationCoWatchingState();
    },
    onCoWatchingStateChanged(coWatchingState: CoWatchingState) {
      // This function should apply newState to your ongoing CoWatching activity
    },
  });

ACTIVITY_TITLE 替換成活動的媒體標題。

管理目前狀態

當使用者在您的應用程式中採取行動時,應用程式應該也會 會立即呼叫所提供的 API 方法。

您只能在回應重大事件時呼叫這些方法。適用對象 因此,您不需要在每次應用程式進入 影片。您在上方建立的 CoWatchingDelegate 帳號代碼即將更新 在這些情況下凸顯排名

您可以使用下列方法控制共同觀看狀態: