Co-Doing API는 회의 일정 간에 임의 데이터를 동기화하는 데 있습니다. 앱이 사용하는 모든 데이터가 될 수 있습니다.
데이터를 전송하려면 데이터를 Uint8Array
으로 직렬화해야 합니다. 대상
자세한 내용은 JavaScript 표준 라이브러리
참조
데이터를 직렬화하는 방법을 잘 모르겠다면 코드 샘플을 검토하세요. 있습니다.
이 가이드에서는 Co-Doing API를 구현하는 방법을 설명합니다.
시작하기
Co-Doing API를 사용하려면 먼저 Co-Doing API를 Meet 부가기능을 참조하세요. 한 번 해당 단계를 완료했다면 Co-Doing API를 사용하여 새 부가기능 내에서 액세스할 수 있습니다
Co-Doing API를 사용하려면 먼저
AddonSession
공동 활동의 진입점 역할을 합니다.
TypeScript
const session = await window.meet.addon.createAddonSession({
cloudProjectNumber: "CLOUD_PROJECT_NUMBER",
});
CoDoing 클라이언트 만들기
시작하려면
CoDoingClient
드림
AddonSession
에서 가져옴
CoDoingClient
를 만들려면 다음을 호출합니다.
AddonSession.createCoDoingClient
메서드를 사용하고
CoDoingDelegate
입니다.
CoDoingDelegate
는 Co-Doing API가
새 상태를 사용할 수 있을 때마다 애플리케이션을 업데이트합니다. 이것은 정상입니다
광고가
CoDoingDelegate.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 newState to your ongoing CoDoing activity
},
});
ACTIVITY_TITLE을 활동의 제목으로 바꿉니다.
현재 상태 관리
사용자가 애플리케이션에서 액션을 취할 때는 애플리케이션이
즉시
CoDoingClient.broadcastStateUpdate
드림
메서드를 사용하여 축소하도록 요청합니다.
다음 코드 샘플은
CoDoingClient.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를 앱의 현재 상태로 바꿉니다.