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 <PresenceObserver />
together with the <PresenceFacepile />
component.
import { PresenceObserver } from "@cord-sdk/react";
export const Example = () => (
<>
// The PresenceObserver tracks and marks users as present in the
// location when user interaction is detected
<PresenceObserver location={{ "page": "index", "section": "content" }} groupId="my-group">
<div id="content">
<p>lorem ipsum</p>
</div>
</PresenceObserver>
// The PresenceFacepile displays who is present at the location
<PresenceFacepile
location={{ "page": "index", "section": "content" }}
excludeViewer={false}
maxUsers={7}
/>
</>
);
<PresenceObserver>
, they will be marked as present at this
location in Cord's backend. This value defaults to the current URL.true
, every user will be able to see
the presence indicator for any user (within the same group) who has
ever been at this location at any point in the past.false
, Cord will only show the users who are
present at the same location at the same time.false
.location
.mouseenter
. To do this, Cord uses a set of default event
listeners that cover the majority of cases. You may find that
you need to set additional event listeners to correctly capture
a user's presence within your app.addEventListener(<event type>, ()
=> { ... })
). When these events fire, Cord will pick up the
event and mark the user as present in the current location.['scroll', 'mousemove']
.['mouseenter', 'focusin']
.location
.addEventListener(<event type>, ()
=> { ... })
). When these events fire, Cord will pick up the
event and mark the user as absent in the current location.['blur']
.['mouseleave', 'focusout']
.true
or false
value to tell Cord whether
or not the viewing user is present in the location
.<PresenceObserver>
elements in the page and you want to
surface that the user is present in a particular one at page load.true
, presence will be determined by whether
or not the current document is visible, rather than based on the
"present" and "absent" DOM events. Setting this to true
means
that presentEvents
, absentEvents
, and initialState
value will be ignored.<PagePresence>
component instead, because it provides both
a <PresenceObserver>
and a <PresenceFacepile>
in a
single component.<PresenceObserver>
with observeDocument
set to true
if you want to record presence on a page but not
surface it. That is to say – you want to observe presence, but
you don't want to show a facepile. This is sometimes the case
when you want to record presence in one place but surface it in another place.false
.true
or false
value as an argument
indicating whether or not the user is present at the location
.Not finding the answer you need? Ask our Developer Community