本指南說明如何設定及執行範例 Google Meet 外掛程式。
目標
- 設定範例。
- 執行範例。
必要條件
- 擁有可存取 Google Meet 的 Google Workspace 帳戶。
- Google Cloud 專案。
- Node.js 和 npm 已安裝。
設定範例
在工作目錄中,執行下列指令來初始化 專案:
npm init
在工作目錄中安裝 Express.js:
npm install express --save
-
npm install @googleworkspace/meet-addons --save
在工作目錄中,建立名為
index.js
的檔案,然後貼上 下列程式碼:const express = require('express'); const path = require('path'); var app = express(); app = require("https-localhost")(); app.use(express.static(path.join(__dirname, '/'))); app.use('/', express.static(__dirname + '/node_modules/@googleworkspace/meet-addons')); app.get('/sidepanel', function(req, res){ res.render(path.join(__dirname, 'sidepanel.html')); }); app.get('/mainstage', function(req, res){ res.render(path.join(__dirname, 'mainstage.html')); }); app.listen(3000);
在工作目錄中,建立名為
mainstage.html
的檔案,然後貼上 下列程式碼:<html style="width: 100%; height: 100%"> <head> <title>Main Stage Add On</title> <script src="meet.addons.js"></script> </head> <body style="width: 100%; height: 100%; margin: 0; background: white;"> <div style="display: flex; flex-direction: column; height: 100%"> <h1>Main Stage Add-on</h1> <div> <div> <button id="get-collaboration-starting-state"> getCollaborationStartingState </button> </div> <div id="receivedCollaborationStartingState" style="margin-left: 20px; width: 300px; overflow-wrap: anywhere"></div> </div> </div> <script> let mainStageClient; async function init() { const session = await window.meet.addon.createAddonSession({ cloudProjectNumber: "CLOUD_PROJECT_NUMBER", }); console.log("Successfully constructed the add-on session."); const mainStageClient = await session.createMainStageClient(); console.log("Successfully constructed main stage client."); document .getElementById('get-collaboration-starting-state') .addEventListener( 'click', async () => { document.getElementById( 'receivedCollaborationStartingState').textContent = JSON.stringify( await mainStageClient.getCollaborationStartingState()); }); } document.body.onload = () => { init(); }; </script> </body> </html>
在工作目錄中,建立名為
sidepanel.html
的檔案,然後貼上 下列程式碼:<html style="width: 100%; height: 100%"> <head> <title>Side Panel Add-on</title> <script src="meet.addons.js"></script> </head> <body style="width: 100%; height: 100%; margin: 0"> <div style="display: flex; flex-direction: column; height: 100%"> <h1>Side Panel Add-on</h1> <div> <div> <button id="set-collaboration-starting-state"> setCollaborationStartingState </button> </div> <div> <input type="text" id="sidePanelIframeUrl" style="margin-left: 20px" value="https://localhost:3000/sidepanel.html" /> </div> <div> <input type="text" id="mainStageIframeUrl" style="margin-left: 20px" value="https://localhost:3000/mainstage.html" /> </div> <div> <input type="text" id="additionalData" style="margin-left: 20px" value="additional data" /> </div> </div> </div> <script> let sidePanelClient; async function init() { const session = await window.meet.addon.createAddonSession({ cloudProjectNumber: "CLOUD_PROJECT_NUMBER", }); console.log("Successfully constructed the add-on session."); sidePanelClient = await session.createSidePanelClient(); console.log("Successfully constructed side panel client."); document .getElementById('set-collaboration-starting-state') .addEventListener( 'click', async () => { const sidePanelIframeUrlInputElement = document.getElementById('sidePanelIframeUrl'); const mainStageIframeUrlInputElement = document.getElementById('mainStageIframeUrl'); const additionalDataInputElement = document.getElementById('additionalData'); await sidePanelClient.setCollaborationStartingState({ sidePanelUrl: sidePanelIframeUrlInputElement.value, mainStageUrl: mainStageIframeUrlInputElement.value, additionalData: additionalDataInputElement.value, }); }); } document.body.onload = () => { init(); }; </script> </body> </html>
針對
mainstage.html
和sidepanel.html
檔案替換下列內容:CLOUD_PROJECT_NUMBER
:您的專案編號 Google Cloud 專案
在工作目錄中,安裝 https-localhost 套件:
npm install https-localhost --save
在工作目錄中執行範例:
node index.js
透過瀏覽器前往
https://localhost:3000/mainstage.html
,然後https://localhost:3000/sidepanel.html
即可驗證網頁。
建立 Meet 外掛程式
按照 請參閱建立 Meet 外掛程式的操作說明。
執行範例
前往 Meet。
按一下「活動」圖示 。
「您的外掛程式」部分應該會顯示
Google Meet Add-ons Quickstart
。選取該指令碼來執行 外掛程式。