Class: FCollaboration
The Facade API object for the Collaboration module. It provides methods to interact with the Univer Collaboration backend server, such as loading Univer Sheets and subscribing to collaborators.
Extends
FBase
Methods
getCollaborationStatus()
getCollaborationStatus(): CollaborationStatusGet the synchronization status of the currently focused unit (workbook or document).
Returns
CollaborationStatus
The current synchronization status of the focused unit. Returns CollaborationStatus.NOT_COLLAB if no unit is focused or collaboration is not enabled.
Possible status values:
NOT_COLLAB: Not in collaboration modeSYNCED: All changes are synchronizedPENDING: Local changes waiting to be sentAWAITING: Changes sent, waiting for server acknowledgementAWAITING_WITH_PENDING: Awaiting acknowledgement with new local changesFETCH_MISS: Fetching missing changesets from serverCONFLICT: Conflict detected and being resolvedOFFLINE: Network is offline
Example
const collaboration = univerAPI.getCollaboration();
const status = collaboration.getCollaborationStatus();
// Check if synchronized
if (status === univerAPI.Enum.CollaborationStatus.SYNCED) {
console.log('All changes are synced!');
}loadActiveSheet()
loadActiveSheet(): Promise<FWorkbook>Returns
Promise<FWorkbook>
The FWorkbook or null if the active Univer Sheet cannot be loaded.
Deprecated
Use loadActiveSheetAsync instead.
loadActiveSheetAsync()
loadActiveSheetAsync(): Promise<FWorkbook>Load the active Univer Sheet. It should be associated with the Uniscript Node.js Runtime.
Returns
Promise<FWorkbook>
The FWorkbook or null if the active Univer Sheet cannot be loaded.
Throws
If the method is not overridden.
Example
const collaboration = univerAPI.getCollaboration();
const workbook = await collaboration.loadActiveSheetAsync();loadSheet()
loadSheet(unitId): Promise<FWorkbook>Parameters
| Parameter | Type | Description |
|---|---|---|
unitId | string | The Id of the Univer Sheet that you would like to load. |
Returns
Promise<FWorkbook>
The FWorkbook or null if the Univer Sheet cannot be loaded.
Deprecated
Use loadSheetAsync instead.
loadSheetAsync()
loadSheetAsync(unitId, context?): Promise<FWorkbook>Load a Univer Sheet from the server with a unit ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
unitId | string | ID of the Univer Sheet that you would like to load. |
context? | ILogContext$1 | Optional context. |
Returns
Promise<FWorkbook>
The FWorkbook or null if ID cannot be associated with a Univer Sheet.
Example
const collaboration = univerAPI.getCollaboration();
const workbook = await collaboration.loadSheetAsync('your-unit-id');subscribeCollaborators()
subscribeCollaborators(unitId, callback): IDisposableSubscribe collaborators of a Univer file.
Parameters
| Parameter | Type | Description |
|---|---|---|
unitId | string | ID of the Univer file. |
callback | (members) => void | A callback function that will be called when the collaborators change. |
Returns
IDisposable
A handler to dispose the subscription.
Example
const collaboration = univerAPI.getCollaboration();
collaboration.subscribeCollaborators('your-unit-id', (members) => {
console.log(members);
});