本页面介绍如何获取插件与 Google Meet 通信所需的客户端对象。
首先,插件需要建立会话:
const session = await window.meet.addon.createAddonSession({
cloudProjectNumber: "CLOUD_PROJECT_NUMBER",
});
在该会话中,可以创建两个客户端对象:
在主阶段中运行的插件的
MeetMainStageClient
,可使用await session.createMainStageClient()
检索。在侧边栏中运行的插件的
MeetSidePanelClient
,可使用await session.createSidePanelClient()
检索。
请务必为主 Stage 或侧边栏检索正确的客户端对象。如果检索到了错误的客户端,Google Meet 插件 SDK 会抛出异常。如需查看该插件在哪个 iframe(主界面或侧边栏)中运行,请使用 MeetAddon.getFrameType
方法。
以下代码示例展示了如何实例化主 Stage 客户端对象:
const session = await window.meet.addon.createAddonSession({
cloudProjectNumber: "CLOUD_PROJECT_NUMBER",
});
const mainStageClient = await session.createMainStageClient();
共享功能
有些功能在 MeetMainStageClient
和 MeetSidePanelClient
中都可用,而其他功能则特定于某个客户端。
例如,两个客户端中都提供的部分功能包括:
MeetAddonClient.getCollaborationStartingState
方法,用于在参与者接受协作邀请时获取有关插件初始状态的信息。MeetAddonClient.getMeetingInfo
方法,可获取有关运行插件的会议的详细信息。MeetAddonClient.getMeetPlatformInfo
方法,用于获取有关运行插件的会议平台的详细信息。MeetAddonClient.setCollaborationStartingState
,用于在参与者接受协作邀请时设置插件的初始状态。- 如需查看这两个客户端的完整功能列表,请参阅
MeetAddonClient
对象。
特定于客户端的功能
仅在 MeetMainStageClient
中提供的功能:
MeetMainStageClient.notifySidePanel
会向侧边栏发送消息。您可以通过订阅侧边栏中的 frameToFrameMessage 回调来接收消息。MeetMainStageClient.loadSidePanel
方法可打开侧边栏 iframe。iframe 来源被设为清单文件中的侧边栏网址。MeetMainStageClient.unloadSidePanel
方法可关闭侧边栏 iframe。调用此方法时,插件状态不会在 Meet 中保留。在调用此方法之前,插件要负责保留任何插件状态。
仅在 MeetSidePanelClient
中提供的功能:
MeetSidePanelClient.notifyMainStage
会向 mainStage 发送消息。您可以通过在主阶段订阅 frameToFrameMessage 回调来接收消息。