Co-Doing API 구현

Co-Doing API는 회의 일정 간에 임의 데이터를 동기화하는 데 있습니다. 앱이 사용하는 모든 데이터가 될 수 있습니다.

데이터를 전송하려면 데이터를 Uint8Array로 직렬화해야 합니다. 자세한 내용은 자세한 내용은 JavaScript 표준 라이브러리 참조

데이터를 직렬화하는 방법을 잘 모르겠다면 코드 샘플을 검토하세요. 있습니다.

이 가이드에서는 Co-Doing API를 구현하는 방법을 설명합니다.

시작하기

Co-Doing API를 사용하려면 먼저 Meet 부가기능을 빌드해야 합니다. 한 번 해당 단계를 완료했다면 Co-Doing API를 사용하여 새 부가기능 내에서 액세스할 수 있습니다

Co-Doing API를 사용하려면 먼저 AddonSession 객체 Google Meet 공동 활동의 시작점 역할을 합니다.

TypeScript

const session = await window.meet.addon.createAddonSession({
    cloudProjectNumber: "CLOUD_PROJECT_NUMBER",
});

CLOUD_PROJECT_NUMBER를 다음 프로젝트의 프로젝트 번호로 바꿉니다. Google Cloud 프로젝트에 액세스할 수 있습니다

공동 수행 클라이언트 만들기

시작하려면 CoDoingClient 드림 객체를 AddonSession에서 삭제할 수 있습니다.

CoDoingClient를 만들려면 createCoDoingClient() 메서드를 호출하고 CoDoingDelegate 객체를 제공합니다.

CoDoingDelegate는 Co-Doing API가 새로운 상태를 사용할 수 있을 때마다 앱을 업데이트합니다. 예상되는 문제가 onCoDoingStateChanged() 드림 메서드가 호출되면 앱이 즉시 새 상태를 적용합니다.

다음 코드 샘플은 Co-Doing API를 사용하는 방법을 보여줍니다.

TypeScript

interface MyState {
  someString: string;
  someNumber: number;
}

/**
 * Serialize/deserialize using JSON.stringify
 * You can use any method you want; this is included for as an example
 */
function toBytes(state: MyState): Uint8Array {
  return new TextEncoder().encode(JSON.stringify(state));
}

function fromBytes(bytes: Uint8Array): MyState {
  return JSON.parse(new TextDecoder().decode(bytes)) as MyState;
}

  const coDoingClient = await addonSession.createCoDoingClient({
    activityTitle: "ACTIVITY_TITLE",
    onCoDoingStateChanged(coDoingState: CoDoingState) {
      const newState = fromBytes(coDoingState.bytes);
      // This function should apply the new state to your ongoing CoDoing activity
    },
  });

ACTIVITY_TITLE을 활동의 제목으로 바꿉니다.

현재 상태 관리

사용자가 앱에서 액션을 취하는 즉시 앱이 호출 broadcastStateUpdate() 드림 메서드를 사용하여 축소하도록 요청합니다.

다음 코드 샘플은 broadcastStateUpdate() 메서드:

TypeScript

const myState: MyState = {
  someString: "SOME_STRING",
  someNumber: 0
};

document.getElementById('some-button').onClick(() => {
  myState.someNumber = myState.someNumber + 1;
  coDoingClient.broadcastStateUpdate({ bytes: toBytes(myState) });
});

SOME_STRING를 앱의 현재 상태로 바꿉니다.