forked from jahnvisahni31/DesignDeck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveblocks.config.ts
99 lines (89 loc) · 2.68 KB
/
liveblocks.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { LiveMap, createClient } from "@liveblocks/client";
import { createRoomContext } from "@liveblocks/react";
import { ReactionEvent } from "./types/type";
// Ensure publicApiKey is properly retrieved from the environment
// ex, NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY=your_api_key
//No need to name the env file (in the root directory) just .env will work
if (!process.env.NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY) {
throw new Error("NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY is not defined.");
}
const client = createClient({
throttle: 16, // Keep this setting to control the frequency of updates.
publicApiKey: "pk_dev_a2dfePJpR38agCwN3onDSzLADWtRVRixe4m0gWxzd4ieEVEOmvCIrNYcYQT_26pC", // Public key must be used here.
// Uncomment if using a custom auth backend
// authEndpoint: "/api/liveblocks-auth",
resolveUsers: async ({ userIds }) => {
// For Comments feature, return user data like name and avatar
// Implement this with your own backend or leave it as is if not used
return [];
},
resolveMentionSuggestions: async ({ text, roomId }) => {
// For Comments feature: Suggest userIds when mentioning users by filtering their names
return [];
},
});
// Presence: Properties that are synced for each user
export type Presence = {
cursor: { x: number; y: number } | null;
message: string | null;
};
// Storage: Shared objects across users that persist in the Room
type Storage = {
canvasObjects: LiveMap<string, any>; // Example of shared canvas objects
};
// UserMeta: Optional static metadata for users
type UserMeta = {
// Example: id, name, avatar fetched from your custom auth backend
// id?: string;
// info?: Json;
};
// RoomEvent: Custom events broadcast and listened to within the room
type RoomEvent = ReactionEvent;
// ThreadMetadata: Metadata for Comments threads (for example, in collaborative comments feature)
export type ThreadMetadata = {
resolved: boolean;
zIndex: number;
time?: number;
x: number;
y: number;
};
export const {
suspense: {
RoomProvider,
useRoom,
useMyPresence,
useUpdateMyPresence,
useSelf,
useOthers,
useOthersMapped,
useOthersConnectionIds,
useOther,
useBroadcastEvent,
useEventListener,
useErrorListener,
useStorage,
useObject,
useMap,
useList,
useBatch,
useHistory,
useUndo,
useRedo,
useCanUndo,
useCanRedo,
useMutation,
useStatus,
useLostConnectionListener,
useThreads,
useUser,
useCreateThread,
useEditThreadMetadata,
useCreateComment,
useEditComment,
useDeleteComment,
useAddReaction,
useRemoveReaction,
},
} = createRoomContext<Presence, Storage, UserMeta, RoomEvent, ThreadMetadata>(
client
);