Skip to content

Commit

Permalink
updated IReceiveLiveEvent response (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbliss authored May 23, 2023
1 parent a438384 commit a0aab1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
* Licensed under the Microsoft Live Share SDK License.
*/

/**
* Object response for a received event
*/
export interface IReceiveLiveEvent<TEvent = any> {
/**
* The value of the event that was sent
*/
value: TEvent;
/**
* True if the local client was the one to send this event
*/
local: boolean;
/**
* Client ID of the user that sent the event
*/
clientId: string;
/**
* Server timestamp at which the event was sent
*/
timestamp: number;
}
9 changes: 8 additions & 1 deletion packages/live-share-react/src/live-hooks/useLiveEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,21 @@ export function useLiveEvent<TEvent = any>(
React.useEffect(() => {
if (liveEvent?.isInitialized === undefined) return;
// Register event listener
const onEventReceived = (event: TEvent, local: boolean) => {
const onEventReceived = (
event: TEvent,
local: boolean,
clientId: string,
timestamp: number
) => {
// If developer passed the optional onReceivedEvent callback, we
// call it.
onReceivedEvent?.(event, local);
// Set the received event to our local state
const received: IReceiveLiveEvent<TEvent> = {
value: event,
local,
clientId,
timestamp,
};
allEventsRef.current = [...allEventsRef.current, received];
setLatestReceived(received);
Expand Down

0 comments on commit a0aab1d

Please sign in to comment.