Skip to content

Commit

Permalink
Merge pull request #566 from share/docs-null-presence
Browse files Browse the repository at this point in the history
馃摑 Update presence documentation
  • Loading branch information
alecgibson committed Jul 12, 2022
2 parents 5302bc7 + 8ec5279 commit 8950626
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/api/presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions docs/presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 %}):
Expand Down

0 comments on commit 8950626

Please sign in to comment.