Node.js 빠른 시작

이 가이드에서는 샘플을 설정하고 실행하는 방법을 설명합니다. Google Meet 부가기능

목표

  • 샘플을 설정합니다.
  • 샘플을 실행합니다.

기본 요건

샘플 설정

  1. 작업 디렉터리에서 다음 명령어를 실행하여 프로젝트:

     npm init
    
  2. 작업 디렉터리에 Express.js를 설치합니다.

     npm install express --save
    
  3. Meet 부가기능 웹 SDK를 설치합니다.

     npm install @googleworkspace/meet-addons --save
    
  4. 작업 디렉터리에 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);
    
  5. 작업 디렉터리에 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>
    
  6. 작업 디렉터리에 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>
    
  7. mainstage.htmlsidepanel.html 파일에서 다음을 모두 바꿉니다.

    • CLOUD_PROJECT_NUMBER: 프로젝트의 프로젝트 번호입니다. Google Cloud 프로젝트
  8. 작업 디렉터리에 https-localhost를 설치합니다. 패키지:

     npm install https-localhost --save
    
  9. 작업 디렉터리에서 샘플을 실행합니다.

     node index.js
    
  10. 브라우저에서 https://localhost:3000/mainstage.html로 이동한 다음 https://localhost:3000/sidepanel.html하여 웹페이지를 인증합니다.

Meet 부가기능 만들기

다음 단계에 따라 부가기능 배포를 설정합니다. Meet 부가기능 빌드 방법에 대한 안내를 따르세요.

샘플 실행

  1. Meet으로 이동합니다.

  2. 활동 활동 아이콘입니다.을 클릭합니다.

  3. 내 부가기능 섹션에 Google Meet Add-ons Quickstart입니다. 이를 선택하여 부가기능