Skip to content

Commit

Permalink
Return onlineUsers from useLivePresence
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbliss committed Sep 18, 2024
1 parent cbb4ab7 commit dddcf28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/live-share-react/src/live-hooks/useLivePresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UserMeetingRole,
LiveDataObjectInitializeState,
LivePresenceData,
PresenceStatus,
} from "@microsoft/live-share";
import React from "react";
import {
Expand Down Expand Up @@ -124,6 +125,10 @@ export function useLivePresence<TData extends LivePresenceData = any>(
return allUsers.find((user) => user.isLocalUser);
}, [allUsers]);

const onlineUsers = React.useMemo(() => {
return allUsers.filter((user) => user.status === PresenceStatus.online);
}, [allUsers]);

const { container } = useFluidObjectsContext();

/**
Expand Down Expand Up @@ -191,6 +196,7 @@ export function useLivePresence<TData extends LivePresenceData = any>(
localUser,
otherUsers,
allUsers,
onlineUsers,
livePresence,
updatePresence,
};
Expand Down
4 changes: 4 additions & 0 deletions packages/live-share-react/src/types/ResultTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export interface IUseLivePresenceResults<TData extends LivePresenceData = any> {
* List of non-local user's presence objects.
*/
otherUsers: LivePresenceUser<TData>[];
/**
* List of all online users.
*/
onlineUsers: LivePresenceUser<TData>[];
/**
* List of all user's presence objects.
*/
Expand Down

0 comments on commit dddcf28

Please sign in to comment.