From 8ec52793270ffd2b4c43585b0a3247571650dfcb Mon Sep 17 00:00:00 2001 From: Alec Gibson <12036746+alecgibson@users.noreply.github.com> Date: Tue, 12 Jul 2022 15:58:35 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Update=20presence=20documentatio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change updates our presence documentation to highlight that disconnections can be seen with a `null` value. --- docs/api/presence.md | 3 +++ docs/presence.md | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/api/presence.md b/docs/api/presence.md index 8d55b04c3..d8768a7a9 100644 --- a/docs/api/presence.md +++ b/docs/api/presence.md @@ -143,6 +143,9 @@ presence.on('receive', function(id, value) { ... }); > The presence value. The structure of this object will depend on the [type]({{ site.baseurl }}{% link types/index.md %}) +{: .info } +> A `null` value means the remote client is no longer present in the document (e.g. they disconnected) + ### `'error'` An error has occurred. diff --git a/docs/presence.md b/docs/presence.md index 7555d0994..9567446e2 100644 --- a/docs/presence.md +++ b/docs/presence.md @@ -22,6 +22,14 @@ In this case, clients just need to subscribe to a common channel using [`connect ```js const presence = connection.getPresence('my-channel') presence.subscribe() + +presence.on('receive', (presenceId, update) => { + if (update === null) { + // The remote client is no longer present in the document + } else { + // Handle the new value by updating UI, etc. + } +}) ``` In order to send presence information to other clients, a [`LocalPresence`]({{ site.baseurl }}{% link api/local-presence.md %}) should be created. The presence object can take any arbitrary value @@ -51,6 +59,14 @@ Clients subscribe to a particular [`Doc`]({{ site.baseurl }}{% link api/doc.md % ```js const presence = connection.getDocPresence(collection, id) presence.subscribe() + +presence.on('receive', (presenceId, update) => { + if (update === null) { + // The remote client is no longer present in the document + } else { + // Handle the new value by updating UI, etc. + } +}) ``` The shape of the presence value will be defined by the [type]({{ site.baseurl }}{% link types/index.md %}):