Implement the Co-Watching API

The Google Meet Live Sharing Co-Watching API manages the meeting experience of multiple participants watching or listening to content in your app.

This guide explains how to implement the Co-Watching API.

Create a CoWatchingClient

To get started, create a createCoWatchingClient from the AddonSession you created in Get started.

To create a CoWatchingCient, call the AddonSession.createCoWatchingClient method and provide a CoWatchingDelegate.

The CoWatchingDelegate is how the Co-Watching API updates your application whenever it has a new state available. It's expected that, when the CoWatchingDelegate.onCoWatchingStateChanged method is called, your application will immediately apply the new state.

The following code sample shows how to use the 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
    },
  });

Replace ACTIVITY_TITLE with the media title of your activity.

Manage current state

When users take action in your application, it's expected that your application immediately calls the provided API methods.

You should only call these methods in response to significant events. For example, you don't need to call them every time your app advances a playing video. The CoWatchingDelegate you created above handles getting updated playout positions in these circumstances.

You can control the co-watching state using these methods: