フレーム間メッセージを使用する
このページでは、サイドパネル iframe で実行されているアドオンから、メインステージ iframe で実行されているアドオンにクライアントサイドでメッセージを送信する方法について説明します。フレーム間メッセージはクライアント側でのみ行われるため、メッセージの配信はほぼ瞬時に行われます。
メールを送信するには:
await sidePanelClient.notifyMainStage("YOUR_MESSAGE");
await mainStageClient.notifySidePanel("YOUR_MESSAGE");
payload
の長さは、指定されたサイズの上限に準拠している必要があります。
メッセージを受信するには、アドオンが frameToFrameMessage
コールバックに登録する必要があります。次のコードサンプルは、frameToFrameMessage
コールバックをサブスクライブする方法を示しています。
sidePanelClient.on('frameToFrameMessage', (arg: FrameToFrameMessage) => {
// YOUR_CODE
});
GitHub の「アニメーション」サンプル アドオンには、フレーム間メッセージの完全な例が含まれています。アクティビティの開始後、サイドパネルはユーザーが入力を変更するたびにメインステージに通知します。メインステージは、frameToFrameMessage
コールバックに登録して、更新された状態を受け取ります。
メモ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-12-21 UTC。
[null,null,["最終更新日 2024-12-21 UTC。"],[[["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"]]