שימוש בהעברת הודעות מהפריים למסגרת
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
בדף הזה מוסבר איך לשלוח הודעות בצד הלקוח מתוסף שפועל ב-iframe של החלונית הצדדית לתוסף שפועל ב-iframe של האזור הראשי. העברת הודעות בין פריימים מתרחשת רק בצד הלקוח, ולכן מסירת ההודעות היא כמעט מיידית.
כדי לשלוח הודעה:
await sidePanelClient.notifyMainStage("YOUR_MESSAGE");
await mainStageClient.notifySidePanel("YOUR_MESSAGE");
האורך של payload
חייב להיות בהתאם למגבלת הגודל שצוינה.
כדי לקבל את ההודעה, התוסף צריך להירשם לקריאה חוזרת (callback) של frameToFrameMessage
. דוגמת הקוד הבאה מראה איך להירשם לקריאה חוזרת (callback) של frameToFrameMessage
:
sidePanelClient.on('frameToFrameMessage', (arg: FrameToFrameMessage) => {
// YOUR_CODE
});
התוסף לדוגמה 'אנימציה' ב-GitHub
כולל דוגמה מלאה להעברת הודעות בין פריים לפריים. אחרי שהפעילות מתחילה, החלונית הצדדית שולחת הודעה לבמה הראשית בכל פעם שהמשתמש משנה קלט.
הבמה הראשית גם נרשמת לקריאה חוזרת (callback) של frameToFrameMessage
כדי לקבל עדכונים על הסטטוס.
הערות
הודעות שנשלחות על ידי משתתף מסוים ומוצגות בפריים מסוים רק המשתתף הזה יכול לראות אותן. כדי לשלוח הודעות או מצב למשתתפים אחרים, צריך ללמוד איך משתפים את מצב התוסף.
מערכת הניסיון למסור את ההודעה מתבצעת רק פעם אחת. כדי לקבל הודעות, החלונית המקבלת צריכה להיות פתוחה והאפליקציה צריכה להירשם לקריאה חוזרת לפני שההודעה נשלחת.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-29 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-29 (שעון UTC)."],[],[],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)"]]