Skip to main content

Events

The collaboration client has a set of events you can subscribe to. This helps you keep your app's UI in sync with any backend changes that happen.

Currently we provide the following events

Every event can be subscribed to with the client.subscribe API.

The API is the same for each event:

client.subscribe(eventName, callbackFunction): UnsubscribeFunction

The event names and callback functions are documented below.

To cancel a subscription, just call the unsubscribe function that is returned from subscribe.

const unsubscribe = client.subscribe('anyEvent', () => {});
unsubscribe();
Note

These events are not the same as WebViewer's version of these events, so pay attention to the differences!

documentChanged#

The documentChanged event is triggered every time information about a document changes, including when the user is invited to a document, and when annotations are added to the document.

client.subscribe('documentChanged', (document, action) => {
});

The callback function is called with two parameters, document and action.

document is the updated document object, including all its annotations.

action is a string representing the action that took place. It is one of the following: ADD, DELETE, or EDIT

annotationChanged#

The annotationChanged event is called whenever an annotation is changed. This includes its styling, position, permissions, etc.

client.subscribe('annotationChanged', (annotation, action) => {
});

The callback function is called with two parameters, annotation and action.

annotation is the updated annotation object.

action is a string representing the action that took place. It is one of the following: ADD, DELETE, or EDIT

scrollSyncStatusChanged#

The scrollSyncStatusChanged event is triggered when the scroll sync feature for the document becomes available or unavailable. See Scroll Synchronization guide for details.

client.subscribe('scrollSyncStatusChanged', (available) => {
});

The callback function is called with one parameter, available.

available is either true or false.

connectedUsersChanged#

connectedUsersChanged event is trigged when connected users changes their page position or becomes online/offline. See Connected Users guide for details.

Note

The user needs to be the current document's member to receive this event. Please also make sure you set CollabClient.enableConnectedUsers to true.

client.subscribe('connectedUsersChanged', (connectedUsers, action) => {
});

The callback function is called with two parameters, connectedUsers and action.

connectedUsers is an array of connectedUsers: [{userId, currentPage}, ...]

action is a string representing the action that took place. It is one of the following: EDIT, or DELETE

permissionError#

The permissionError event is triggered when a user attempts to perform an action they are not allowed to do. In most scenarios the viewer will not allow the user to perform these actions in the first place, but there are scenarios where this cannot be caught until the request hits the server.

This event is useful for showing error messages when a user tried to do something they are not allowed to do.

client.subscribe('permissionError', (entityType, attemptedAction) => {
});

entityType is the type of entity the action was performed on. It is either Document or Annotation.

attemptedAction is the action the user tried to perform. Is one of read, create, edit, delete, or invite.