使用逐帧消息传递
本页介绍了如何在客户端上将消息从在侧边栏 iframe 中运行的插件发送到在主舞台 iframe 中运行的插件。帧到帧消息传递仅在客户端进行,因此消息传递几乎是即时的。
如需发送邮件,请按以下步骤操作:
await sidePanelClient.notifyMainStage("YOUR_MESSAGE");
await mainStageClient.notifySidePanel("YOUR_MESSAGE");
payload
的长度必须符合其指定的大小限制。
如需接收消息,该插件必须订阅 frameToFrameMessage
回调。以下代码示例展示了如何订阅 frameToFrameMessage
回调:
sidePanelClient.on('frameToFrameMessage', (arg: FrameToFrameMessage) => {
// YOUR_CODE
});
GitHub 上的“Animation”示例插件包含一个帧到帧消息传递的完整示例。activity 启动后,侧边栏会在用户每次更改输入时通知主舞台。主舞台还订阅 frameToFrameMessage
回调,以接收更新后的状态。
备注
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-12-21。
[null,null,["最后更新时间 (UTC):2024-12-21。"],[[["This page explains how Google Meet add-ons can send messages between the side panel and main stage iframes using client-side frame-to-frame messaging."],["Add-ons use `notifyMainStage()` and `notifySidePanel()` methods to send messages and subscribe to the `frameToFrameMessage` callback to receive them."],["Frame-to-frame messages are only visible to the sender and require the receiving panel to be open and subscribed to the callback for delivery."],["For sharing state with other participants, refer to the guide on add-on state collaboration."]]],["Add-ons in different iframes (side panel and main stage) can exchange messages client-side. The side panel sends messages to the main stage using `notifyMainStage()`, while the main stage uses `notifySidePanel()` to send messages to the side panel. To receive messages, add-ons must subscribe to the `frameToFrameMessage` callback. Messages are participant-specific and delivered once; the receiving panel must be open and subscribed. Payload size limitations apply. The Animation sample add-on demonstrates this functionality.\n"]]