Notifications
The collab client comes with browser notification support. Browser notifications are the popups that the browser displays when an event of interest happens (invited to a document, new message, etc).
To enable browser notifications, you must pass a notificationHandler
to the client constructor.
A notificationHandler
handler is a function that accepts an event, and uses that event to display a notification. The events are documented below.
We recommend using our CollabClient.defaultNotificationHandler
, as it has all the functionality needed for browser notifications built right in.
#
EventsCurrently there are 2 types of events: an invite event and a new message event. The type of event can be determined from the event object passed into the notificationHandler
.
#
New invite eventThe invite event comes with the following data:
You can use this data to display a message such as ${invitedBy} has invited you to collaborate on ${document.name}!
#
New message eventThe message event comes with the following data:
annotation.hasMention
will be true if the message mentions the current user.
#
Default handlerThe default notificationHandler is a nice default that implements all the functionality needed for browser notifications (permissions, messaging, etc).
To use it, call the static defaultNotificationHandler
and pass the result to the notificationHandler
constructor option.
defaultNotificationHandler
takes and object with two optional properties, onClick and getText.
#
onClickonClick
is a function that gets called when the browser notification is clicked. It is passed the notification event as a parameter.
This could be used to route your user to a specific document, or load the document in the client when it's clicked.
If onClick
is not passed, nothing will happen when the notification is clicked.
#
getTextgetText
is a function that accepts the notification event as a parameter, and returns what the title and body of the notification should be.
The function should return an object with the following shape:
This allows you to customize the text displayed in the notification.
#
TroubleshootingIf you do not see browser notifications when you think you should, ensure that you have notifications enabled on both your browser and your computer.
Please also note that incognito windows do not show browser notifications.