Enable presence on specific areas
The PresenceObserver
component observes user interaction on its DOM subtree, and marks the current user as present in the location when interaction is detected. The observer has no visual effect on the page.
The observer always registers the user as absent if the document is not currently visible per the Document.visibilityState
API.
This component pairs well with:
By itself this component does not show who is present. To display this use together with the PresenceFacepile component.
import { PresenceObserver } from "@cord-sdk/react";
export const Example = () => (
<PresenceObserver location={{ "page": "index", "section": "content" }}>
<div id="content">
<p>lorem ipsum</p>
</div>
</PresenceObserver>
);
<cord-presence-observer location='{ "page": "index", "section": "content" }'>
<div id="content">
<p>lorem ipsum</p>
</div>
</cord-presence-observer>
optional
default: current URL
The location in which to mark the user as present when the relevant DOM events are observed.
optional
default: false
Whether to send durable presence updates. Ephemeral presence updates are always sent.
optional
default: ['mouseenter']
An array of event types that, when seen, indicate the user is present in this observer’s location.
optional
default: ['mouseleave']
An array of event types that, when seen, indicate the user has left this observer’s location.
optional
default: undefined
When provided, sets the initial presence state of the user in this observer, subject to future modification from events. This is necessary if the user is present within the observer at page load, and so no event from present-events
will be fired to initialize their presence.
optional
default: false
When true, ignores the present-events
, absent-events
, and initial-state
attributes and registers presence solely based on whether the document is currently visible.
optional
Callback invoked when presence state changes.
optional
default: current URL
The location in which to mark the user as present when the relevant DOM events are observed.
optional
default: false
Whether to send durable presence updates. Ephemeral presence updates are always sent.
optional
default: ['mouseenter']
An array of event types that, when seen, indicate the user is present in this observer’s location.
optional
default: ['mouseleave']
An array of event types that, when seen, indicate the user has left this observer’s location.
optional
default: undefined
When provided, sets the initial presence state of the user in this observer, subject to future modification from events. This is necessary if the user is present within the observer at page load, and so no event from present-events
will be fired to initialize their presence.
optional
default: false
When true, ignores the present-events
, absent-events
, and initial-state
attributes and registers presence solely based on whether the document is currently visible.
This event is fired when presence state changes.