Build real-time multiplayer apps with peer-to-peer spaces, state sync, and chat — powered by CollaborationManager.
CollaborationManager lets your app create and join real-time spaces. The platform handles all networking, state synchronization, persistence, and conflict resolution — your app just sends and receives state.This is what powers the built-in Whiteboard and Document Editor, and it’s available to every custom app.
Send messages within the space or directly to a specific peer:
Copy
// Send a message to the space chatfunction sendChatMessage(text) { const collab = getCollab(); collab?.sendChatMessage(text);}// Send a direct message to a specific userasync function sendDirectMessage(toOdid, text) { const collab = getCollab(); await collab?.sendDirectMessage(toOdid, text);}// React to a messagefunction sendReaction(messageId, emoji) { const collab = getCollab(); collab?.sendReaction(messageId, emoji);}
Prevent conflicts when multiple users edit the same field:
Copy
// Request a lock on a field before editingasync function requestLock(fieldKey) { const collab = getCollab(); await collab?.requestLock(fieldKey);}// Release the lock when donefunction releaseLock(fieldKey) { const collab = getCollab(); collab?.releaseLock(fieldKey);}
Locks expire automatically after 30 seconds if not released. See Edit locking for more detail.
Share files with everyone in the space or send privately to a specific user:
Copy
// Share a file with the entire spaceasync function shareFile(file) { const collab = getCollab(); await collab?.shareFile(file);}// Send a file privately to one userasync function sendPrivateFile(toOdid, file, messageId) { const collab = getCollab(); await collab?.sendPrivateFile(toOdid, file, messageId);}
The API is only injected inside the webAI shell. Wrap every call in a null check so your app doesn’t crash during local development or in environments where collaboration isn’t available.
Don't assume space membership
Always check space state before calling space-specific methods. The user might not be in a space yet, or they may have disconnected.
Never expose space passwords
If a space is password-protected, don’t store or display the password in your UI or in localStorage. Let the user enter it each time.
Handle disconnections gracefully
Peers can drop out at any time. Design your app’s state model to handle partial participation — not every user may be present for every update.