Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Co-Doing API, toplantı katılımcıları arasında rastgele verileri senkronize etmek için kullanılır. Bu, uygulamanızın bağlı olduğu herhangi bir veri olabilir.
Verilerinizi nasıl serileştireceğinizden emin değilseniz aşağıdaki kod örneklerini inceleyin.
Bu kılavuzda, Co-Doing API'nin nasıl uygulanacağı açıklanmaktadır.
Başlayın
Co-Doing API'yi kullanmak için önce Meet eklentisi dağıtmanız gerekir. Bu adımları tamamladıktan sonra yeni eklentinizde Co-Doing API'yi kullanmaya başlayabilirsiniz.
Co-Doing API'yi kullanmak için öncelikle Google Meet'teki ortak etkinliklerin giriş noktası olarak işlev gören bir AddonSession nesnesi alın:
CoDoingDelegate, Co-Doing API'nin yeni bir durum olduğunda uygulamanızı güncelleme yöntemidir. onCoDoingStateChanged() yöntemi çağrıldığında uygulamanızın yeni durumu hemen uygulaması beklenir.
Aşağıdaki kod örneğinde, Co-Doing API'nin nasıl kullanılacağı gösterilmektedir:
TypeScript
interfaceMyState{someString:string;someNumber:number;}/** * Serialize/deserialize using JSON.stringify * You can use any method you want; this is included for as an example */functiontoBytes(state:MyState):Uint8Array{returnnewTextEncoder().encode(JSON.stringify(state));}functionfromBytes(bytes:Uint8Array):MyState{returnJSON.parse(newTextDecoder().decode(bytes))asMyState;}constcoDoingClient=awaitaddonSession.createCoDoingClient({activityTitle:"ACTIVITY_TITLE",onCoDoingStateChanged(coDoingState:CoDoingState){constnewState=fromBytes(coDoingState.bytes);// This function should apply the new state to your ongoing CoDoing activity},});
ACTIVITY_TITLE yerine etkinliğinizin başlığını girin.
Mevcut durumu yönetme
Kullanıcılar uygulamanızda işlem yaptığında uygulamanızın broadcastStateUpdate() yöntemini hemen çağırması beklenir.
Aşağıdaki kod örneğinde, broadcastStateUpdate() yönteminin bir uygulaması gösterilmektedir:
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-08-29 UTC."],[],[],null,["# Implement the Co-Doing API\n\n| **Early Access Program:** This feature was only available in limited preview, through an Early Access Program. This program is now closed to new signups.\n\nThe Co-Doing API is used to synchronize arbitrary data between meeting\nparticipants. This can be any data that your app depends on.\n\nYou must serialize the data to a `Uint8Array` for it to be transmitted. For more\ninformation, see the [JavaScript standard library\nreference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).\n\nIf you aren't sure how to serialize your data, review the code samples\nfollowing.\n\nThis guide explains how to implement the Co-Doing API.\n\nGet started\n-----------\n\nTo use the Co-Doing API, you first must [Deploy a\nMeet add-on](/workspace/meet/add-ons/guides/deploy-add-on). Once\nyou've completed those steps, you can start using the Co-Doing API\nfrom within your new add-on.\n\nTo use the Co-Doing API, start by getting an\n[`AddonSession`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addonsession) object,\nwhich serves as the entry point for Google Meet co-activities: \n\n### TypeScript\n\n const session = await window.meet.addon.createAddonSession({\n cloudProjectNumber: \"\u003cvar translate=\"no\"\u003eCLOUD_PROJECT_NUMBER\u003c/var\u003e\",\n });\n\nReplace \u003cvar translate=\"no\"\u003eCLOUD_PROJECT_NUMBER\u003c/var\u003e with the project number of\nyour Google Cloud project.\n\nCreate a co-doing client\n------------------------\n\nTo get started, create a\n[`CoDoingClient`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.codoingclient)\nobject from your `AddonSession`.\n\nTo create a `CoDoingClient`, call the\n[`createCoDoingClient()`](/workspace/meet/add-ons/reference/websdk/addon_sdk.addonsession.createcodoingclient)\nmethod and provide a\n[`CoDoingDelegate`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.codoingdelegate)\nobject.\n\nThe `CoDoingDelegate` is how the Co-Doing API\nupdates your app whenever it has a new state available. It's expected that, when\nthe\n[`onCoDoingStateChanged()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.codoingdelegate.oncodoingstatechanged)\nmethod is called, your app immediately applies the new state.\n\nThe following code sample shows how to use the Co-Doing API: \n\n### TypeScript\n\n interface MyState {\n someString: string;\n someNumber: number;\n }\n\n /**\n * Serialize/deserialize using JSON.stringify\n * You can use any method you want; this is included for as an example\n */\n function toBytes(state: MyState): Uint8Array {\n return new TextEncoder().encode(JSON.stringify(state));\n }\n\n function fromBytes(bytes: Uint8Array): MyState {\n return JSON.parse(new TextDecoder().decode(bytes)) as MyState;\n }\n\n const coDoingClient = await addonSession.createCoDoingClient({\n activityTitle: \"\u003cvar translate=\"no\"\u003eACTIVITY_TITLE\u003c/var\u003e\",\n onCoDoingStateChanged(coDoingState: CoDoingState) {\n const newState = fromBytes(coDoingState.bytes);\n // This function should apply the new state to your ongoing CoDoing activity\n },\n });\n\nReplace \u003cvar translate=\"no\"\u003eACTIVITY_TITLE\u003c/var\u003e with the title of your activity.\n\nManage current state\n--------------------\n\nWhen users take action in your app, it's expected that your app immediately\ncalls the\n[`broadcastStateUpdate()`](/workspace/meet/add-ons/reference/websdk/live_sharing_sdk.codoingclient.broadcaststateupdate)\nmethod.\n\nThe following code sample shows an implementation of the\n`broadcastStateUpdate()` method: \n\n### TypeScript\n\n const myState: MyState = {\n someString: \"\u003cvar translate=\"no\"\u003eSOME_STRING\u003c/var\u003e\",\n someNumber: 0\n };\n\n document.getElementById('some-button').onClick(() =\u003e {\n myState.someNumber = myState.someNumber + 1;\n coDoingClient.broadcastStateUpdate({ bytes: toBytes(myState) });\n });\n\nReplace \u003cvar translate=\"no\"\u003eSOME_STRING\u003c/var\u003e with the app's current state."]]