使用逐帧消息传递
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了如何从在侧边栏 iframe 中运行的插件向在主舞台 iframe 中运行的插件发送客户端消息。帧到帧消息传递仅发生在客户端,因此消息传递几乎是即时的。
如需发送邮件,请按以下步骤操作:
await sidePanelClient.notifyMainStage("YOUR_MESSAGE");
await mainStageClient.notifySidePanel("YOUR_MESSAGE");
payload
的长度必须符合其指定的大小限制。
如需接收消息,插件必须订阅 frameToFrameMessage
回调。以下代码示例展示了如何订阅 frameToFrameMessage
回调:
sidePanelClient.on('frameToFrameMessage', (arg: FrameToFrameMessage) => {
// YOUR_CODE
});
GitHub 上的“动画”示例插件包含帧到帧消息传递的完整示例。在 activity 启动后,侧边栏会在用户更改输入时通知主舞台。主阶段还订阅了 frameToFrameMessage
回调以接收更新后的状态。
备注
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Use frame-to-frame messaging\n\nThis page describes how to send messages on the client side from an\nadd-on running in the\n[side-panel](/workspace/meet/add-ons/guides/overview#side-panel) iframe to an\nadd-on running in the [main\nstage](/workspace/meet/add-ons/guides/overview#main-stage) iframe. Frame-to-frame\nmessaging only occurs on the client side, so message delivery is near\ninstantaneous.\n\nTo send a message:\n\n- From the side panel to the main stage, use the [`notifyMainStage()`](/workspace/meet/add-ons/reference/websdk/addon_sdk.meetsidepanelclient.notifymainstage) method.\n\n await sidePanelClient.notifyMainStage(\"\u003cvar translate=\"no\"\u003eYOUR_MESSAGE\u003c/var\u003e\");\n\n- From the main stage to the side panel, use the [`notifySidePanel()`](/workspace/meet/add-ons/reference/websdk/addon_sdk.meetmainstageclient.notifysidepanel) method.\n\n await mainStageClient.notifySidePanel(\"\u003cvar translate=\"no\"\u003eYOUR_MESSAGE\u003c/var\u003e\");\n\nThe [`payload`](/workspace/meet/add-ons/reference/websdk/addon_sdk.frametoframemessage.payload)\nlength must conform to its specified size limit.\n\nTo receive the message, the add-on must subscribe to\nthe\n[`frameToFrameMessage`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addoncallbacks.frametoframemessage)\ncallback. The following code sample shows how to subscribe to a\n`frameToFrameMessage` callback: \n\n sidePanelClient.on('frameToFrameMessage', (arg: FrameToFrameMessage) =\u003e {\n // YOUR_CODE\n });\n\nThe [\"Animation\" sample add-on on GitHub](https://github.com/googleworkspace/meet/tree/3311b735550b8927c8b7ef2c6d06f768d9fe0476/addons-web-sdk/samples/animation-next-js)\nincludes a full example of frame-to-frame messaging. After the activity starts,\nthe side panel [notifies the main stage whenever the user changes an input](https://github.com/googleworkspace/meet/blob/3311b735550b8927c8b7ef2c6d06f768d9fe0476/addons-web-sdk/samples/animation-next-js/src/app/activitysidepanel/page.tsx#L27).\nThe main stage also [subscribes to the `frameToFrameMessage` callback](https://github.com/googleworkspace/meet/blob/3311b735550b8927c8b7ef2c6d06f768d9fe0476/addons-web-sdk/samples/animation-next-js/src/app/mainstage/page.tsx#L43)\nto receive updated state.\n\nNotes\n-----\n\n- Frame-to-frame messages sent by a given participant are *only* visible by\n that same participant. To send messages or state to other participants,\n learn how to [share add-on\n state](/workspace/meet/add-ons/guides/collaborate-in-the-add-on#collaboration).\n\n- Message delivery is only attempted once. To receive messages, the receiving\n panel must be open and the app must subscribe to the callback before the\n message is sent.\n\nRelated topics\n--------------\n\n- [Implement the Co-Doing API](/workspace/meet/add-ons/guides/use-CoDoingAPI)"]]