hermes-chat-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-D42PTTYC.js +1 -0
- package/dist/chunk-D42PTTYC.js.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +166 -0
- package/dist/index.d.ts +166 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +1935 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +343 -0
- package/dist/react.d.ts +343 -0
- package/dist/react.js +1887 -0
- package/dist/react.js.map +1 -0
- package/package.json +53 -0
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
export { ConnectResponse, ConnectionStatus, CreateDirectRoomInput, CreateGroupRoomInput, DeliveryStatus, HermesConfig, HermesEvents, HermesUser, LastSeenEvent, Message, MessageHistoryResult, MessageType, PresenceEvent, Reaction, ReactionEvent, ReceiptEvent, Room, RoomType, SendMessageInput, TypingEvent, UploadResult } from './index.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
interface HermesConfig {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
apiKey: string;
|
|
7
|
+
secret: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
}
|
|
10
|
+
interface HermesUser {
|
|
11
|
+
userId: string;
|
|
12
|
+
displayName: string;
|
|
13
|
+
avatar?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
}
|
|
16
|
+
type RoomType = "direct" | "group";
|
|
17
|
+
interface Room {
|
|
18
|
+
_id: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
type: RoomType;
|
|
21
|
+
createdBy: string;
|
|
22
|
+
members: string[];
|
|
23
|
+
admins: string[];
|
|
24
|
+
avatar?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
lastMessage?: Message;
|
|
27
|
+
lastActivity: string;
|
|
28
|
+
unreadCount: number;
|
|
29
|
+
isMuted: boolean;
|
|
30
|
+
isPinned: boolean;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
}
|
|
34
|
+
interface CreateDirectRoomInput {
|
|
35
|
+
targetUserId: string;
|
|
36
|
+
}
|
|
37
|
+
interface CreateGroupRoomInput {
|
|
38
|
+
name: string;
|
|
39
|
+
memberIds: string[];
|
|
40
|
+
description?: string;
|
|
41
|
+
avatar?: string;
|
|
42
|
+
}
|
|
43
|
+
type MessageType = "text" | "link" | "image" | "video" | "audio" | "document";
|
|
44
|
+
type DeliveryStatus = "sent" | "delivered" | "seen";
|
|
45
|
+
interface Reaction {
|
|
46
|
+
emoji: string;
|
|
47
|
+
users: string[];
|
|
48
|
+
}
|
|
49
|
+
interface Message {
|
|
50
|
+
_id: string;
|
|
51
|
+
roomId: string;
|
|
52
|
+
senderId: string;
|
|
53
|
+
type: MessageType;
|
|
54
|
+
text?: string;
|
|
55
|
+
url?: string;
|
|
56
|
+
fileName?: string;
|
|
57
|
+
fileSize?: number;
|
|
58
|
+
mimeType?: string;
|
|
59
|
+
thumbnail?: string;
|
|
60
|
+
replyTo?: string;
|
|
61
|
+
reactions: Reaction[];
|
|
62
|
+
deliveryStatus: DeliveryStatus;
|
|
63
|
+
seenBy: string[];
|
|
64
|
+
isDeleted: boolean;
|
|
65
|
+
deletedAt?: string;
|
|
66
|
+
editedAt?: string;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
updatedAt: string;
|
|
69
|
+
}
|
|
70
|
+
interface SendMessageInput {
|
|
71
|
+
roomId: string;
|
|
72
|
+
type: MessageType;
|
|
73
|
+
text?: string;
|
|
74
|
+
url?: string;
|
|
75
|
+
fileName?: string;
|
|
76
|
+
fileSize?: number;
|
|
77
|
+
mimeType?: string;
|
|
78
|
+
thumbnail?: string;
|
|
79
|
+
replyTo?: string;
|
|
80
|
+
}
|
|
81
|
+
interface MessageHistoryResult {
|
|
82
|
+
messages: Message[];
|
|
83
|
+
hasMore: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface PresenceEvent {
|
|
86
|
+
userId: string;
|
|
87
|
+
displayName: string;
|
|
88
|
+
roomId?: string;
|
|
89
|
+
}
|
|
90
|
+
interface LastSeenEvent {
|
|
91
|
+
userId: string;
|
|
92
|
+
lastSeen: string;
|
|
93
|
+
}
|
|
94
|
+
interface TypingEvent {
|
|
95
|
+
userId: string;
|
|
96
|
+
displayName: string;
|
|
97
|
+
roomId: string;
|
|
98
|
+
}
|
|
99
|
+
interface ReceiptEvent {
|
|
100
|
+
roomId: string;
|
|
101
|
+
userId: string;
|
|
102
|
+
lastMessageId: string;
|
|
103
|
+
seenAt: string;
|
|
104
|
+
}
|
|
105
|
+
interface ReactionEvent {
|
|
106
|
+
messageId: string;
|
|
107
|
+
roomId: string;
|
|
108
|
+
reactions: Reaction[];
|
|
109
|
+
}
|
|
110
|
+
interface UploadResult {
|
|
111
|
+
type: MessageType;
|
|
112
|
+
url: string;
|
|
113
|
+
thumbnail?: string;
|
|
114
|
+
fileName: string;
|
|
115
|
+
fileSize: number;
|
|
116
|
+
mimeType: string;
|
|
117
|
+
}
|
|
118
|
+
interface HermesEvents {
|
|
119
|
+
connected: () => void;
|
|
120
|
+
disconnected: (reason: string) => void;
|
|
121
|
+
error: (error: Error) => void;
|
|
122
|
+
"message:receive": (message: Message) => void;
|
|
123
|
+
"message:deleted": (data: {
|
|
124
|
+
messageId: string;
|
|
125
|
+
roomId: string;
|
|
126
|
+
}) => void;
|
|
127
|
+
"message:edited": (message: Message) => void;
|
|
128
|
+
"room:created": (room: Room) => void;
|
|
129
|
+
"room:deleted": (data: {
|
|
130
|
+
roomId: string;
|
|
131
|
+
}) => void;
|
|
132
|
+
"room:member:joined": (data: {
|
|
133
|
+
roomId: string;
|
|
134
|
+
userId: string;
|
|
135
|
+
}) => void;
|
|
136
|
+
"room:member:left": (data: {
|
|
137
|
+
roomId: string;
|
|
138
|
+
userId: string;
|
|
139
|
+
}) => void;
|
|
140
|
+
"user:online": (event: PresenceEvent) => void;
|
|
141
|
+
"user:offline": (event: LastSeenEvent) => void;
|
|
142
|
+
"typing:started": (event: TypingEvent) => void;
|
|
143
|
+
"typing:stopped": (event: TypingEvent) => void;
|
|
144
|
+
"receipt:updated": (event: ReceiptEvent) => void;
|
|
145
|
+
"reaction:updated": (event: ReactionEvent) => void;
|
|
146
|
+
}
|
|
147
|
+
type ConnectionStatus = "idle" | "connecting" | "connected" | "disconnected" | "error";
|
|
148
|
+
|
|
149
|
+
type EventKey = keyof HermesEvents;
|
|
150
|
+
type EventCallback<K extends EventKey> = HermesEvents[K];
|
|
151
|
+
declare class EventEmitter {
|
|
152
|
+
private listeners;
|
|
153
|
+
on<K extends EventKey>(event: K, callback: EventCallback<K>): this;
|
|
154
|
+
off<K extends EventKey>(event: K, callback: EventCallback<K>): void;
|
|
155
|
+
once<K extends EventKey>(event: K, callback: EventCallback<K>): this;
|
|
156
|
+
emit<K extends EventKey>(event: K, ...args: Parameters<EventCallback<K>>): this;
|
|
157
|
+
removeAllListeners<K extends EventKey>(event?: K): this;
|
|
158
|
+
listenerCount<K extends EventKey>(event: K): number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare class HermesClient extends EventEmitter {
|
|
162
|
+
private config;
|
|
163
|
+
private socket;
|
|
164
|
+
private token;
|
|
165
|
+
user: HermesUser | null;
|
|
166
|
+
status: ConnectionStatus;
|
|
167
|
+
constructor(config: HermesConfig);
|
|
168
|
+
connect(): Promise<HermesUser>;
|
|
169
|
+
private _connectSocket;
|
|
170
|
+
disconnect(): void;
|
|
171
|
+
private _wireSocketEvents;
|
|
172
|
+
_emit<T = any>(event: string, data?: any): Promise<T>;
|
|
173
|
+
sendMessage(input: SendMessageInput): Promise<Message>;
|
|
174
|
+
getHistory(roomId: string, before?: string, limit?: number): Promise<MessageHistoryResult>;
|
|
175
|
+
deleteMessage(messageId: string, roomId: string): Promise<void>;
|
|
176
|
+
editMessage(messageId: string, roomId: string, text: string): Promise<Message>;
|
|
177
|
+
createDirectRoom(input: CreateDirectRoomInput): Promise<Room>;
|
|
178
|
+
createGroupRoom(input: CreateGroupRoomInput): Promise<Room>;
|
|
179
|
+
deleteRoom(roomId: string): Promise<void>;
|
|
180
|
+
getRooms(): Promise<Room[]>;
|
|
181
|
+
addMember(roomId: string, newMemberId: string): Promise<void>;
|
|
182
|
+
removeMember(roomId: string, targetId: string): Promise<void>;
|
|
183
|
+
pingPresence(roomId: string): void;
|
|
184
|
+
startTyping(roomId: string): void;
|
|
185
|
+
stopTyping(roomId: string): void;
|
|
186
|
+
markSeen(roomId: string, lastMessageId: string): Promise<void>;
|
|
187
|
+
addReaction(messageId: string, roomId: string, emoji: string): Promise<void>;
|
|
188
|
+
uploadFile(file: File): Promise<UploadResult>;
|
|
189
|
+
get isConnected(): boolean;
|
|
190
|
+
get currentUser(): HermesUser | null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
declare const useMessages: (client: HermesClient, roomId: string | null) => {
|
|
194
|
+
messages: Message[];
|
|
195
|
+
loading: boolean;
|
|
196
|
+
loadingMore: boolean;
|
|
197
|
+
hasMore: boolean;
|
|
198
|
+
error: string | null;
|
|
199
|
+
typingUsers: {
|
|
200
|
+
userId: string;
|
|
201
|
+
displayName: string;
|
|
202
|
+
}[];
|
|
203
|
+
sendMessage: (input: Omit<SendMessageInput, "roomId">) => Promise<Message>;
|
|
204
|
+
editMessage: (messageId: string, text: string) => Promise<Message>;
|
|
205
|
+
deleteMessage: (messageId: string) => Promise<void>;
|
|
206
|
+
addReaction: (messageId: string, emoji: string) => Promise<void>;
|
|
207
|
+
loadMore: () => Promise<void>;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
declare const useRooms: (client: HermesClient) => {
|
|
211
|
+
rooms: Room[];
|
|
212
|
+
loading: boolean;
|
|
213
|
+
error: string | null;
|
|
214
|
+
createDirect: (input: CreateDirectRoomInput) => Promise<Room>;
|
|
215
|
+
createGroup: (input: CreateGroupRoomInput) => Promise<Room>;
|
|
216
|
+
deleteRoom: (roomId: string) => Promise<void>;
|
|
217
|
+
addMember: (roomId: string, userId: string) => Promise<void>;
|
|
218
|
+
removeMember: (roomId: string, userId: string) => Promise<void>;
|
|
219
|
+
refetch: () => Promise<void>;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
declare const usePresence: (client: HermesClient) => {
|
|
223
|
+
isOnline: (userId: string) => boolean;
|
|
224
|
+
onlineUsers: string[];
|
|
225
|
+
onlineMap: Map<string, boolean>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
declare const useTyping: (client: HermesClient, roomId: string | null) => {
|
|
229
|
+
typingUsers: Map<string, string>;
|
|
230
|
+
typingText: string | null;
|
|
231
|
+
isAnyoneTyping: boolean;
|
|
232
|
+
startTyping: () => void;
|
|
233
|
+
stopTyping: () => void;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
declare const useReadReceipts: (client: HermesClient, roomId: string | null) => {
|
|
237
|
+
markSeen: (lastMessageId: string) => Promise<void>;
|
|
238
|
+
seenBy: (messageId: string) => string[];
|
|
239
|
+
receipts: Map<string, Set<string>>;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
declare const useReactions: (client: HermesClient, roomId: string | null) => {
|
|
243
|
+
react: (messageId: string, emoji: string) => Promise<void>;
|
|
244
|
+
hasReacted: (reactions: Reaction[], emoji: string) => boolean;
|
|
245
|
+
getCount: (reactions: Reaction[], emoji: string) => number;
|
|
246
|
+
getEmojis: (reactions: Reaction[]) => string[];
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
declare const useUpload: (client: HermesClient) => {
|
|
250
|
+
upload: (file: File) => Promise<UploadResult | null>;
|
|
251
|
+
sendFile: (roomId: string, file: File, replyTo?: string) => Promise<Message | null>;
|
|
252
|
+
validate: (file: File, maxMb?: number) => string | null;
|
|
253
|
+
uploading: boolean;
|
|
254
|
+
error: string | null;
|
|
255
|
+
lastUpload: UploadResult | null;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
interface MessageListProps {
|
|
259
|
+
messages: Message[];
|
|
260
|
+
currentUser: HermesUser;
|
|
261
|
+
loading?: boolean;
|
|
262
|
+
loadingMore?: boolean;
|
|
263
|
+
hasMore?: boolean;
|
|
264
|
+
onLoadMore?: () => void;
|
|
265
|
+
onEdit?: (messageId: string, text: string) => void;
|
|
266
|
+
onDelete?: (messageId: string) => void;
|
|
267
|
+
onReact?: (messageId: string, emoji: string) => void;
|
|
268
|
+
onReply?: (message: Message) => void;
|
|
269
|
+
renderMessage?: (message: Message, isOwn: boolean) => React.ReactNode;
|
|
270
|
+
renderAvatar?: (senderId: string) => React.ReactNode;
|
|
271
|
+
className?: string;
|
|
272
|
+
autoScroll?: boolean;
|
|
273
|
+
typingUsers?: {
|
|
274
|
+
userId: string;
|
|
275
|
+
displayName: string;
|
|
276
|
+
}[];
|
|
277
|
+
}
|
|
278
|
+
declare const MessageList: React.FC<MessageListProps>;
|
|
279
|
+
|
|
280
|
+
interface ChatInputProps {
|
|
281
|
+
onSendText: (text: string) => Promise<void> | void;
|
|
282
|
+
onSendFile?: (file: File) => Promise<void> | void;
|
|
283
|
+
onTypingStart?: () => void;
|
|
284
|
+
onTypingStop?: () => void;
|
|
285
|
+
replyingTo?: Message | null;
|
|
286
|
+
onCancelReply?: () => void;
|
|
287
|
+
disabled?: boolean;
|
|
288
|
+
placeholder?: string;
|
|
289
|
+
maxLength?: number;
|
|
290
|
+
className?: string;
|
|
291
|
+
inputClassName?: string;
|
|
292
|
+
renderAttachIcon?: () => React.ReactNode;
|
|
293
|
+
renderSendIcon?: () => React.ReactNode;
|
|
294
|
+
}
|
|
295
|
+
declare const ChatInput: React.FC<ChatInputProps>;
|
|
296
|
+
|
|
297
|
+
interface RoomListProps {
|
|
298
|
+
rooms: Room[];
|
|
299
|
+
activeRoomId?: string | null;
|
|
300
|
+
currentUserId: string;
|
|
301
|
+
loading?: boolean;
|
|
302
|
+
onSelectRoom: (room: Room) => void;
|
|
303
|
+
onCreateDirect?: () => void;
|
|
304
|
+
onCreateGroup?: () => void;
|
|
305
|
+
renderRoomItem?: (room: Room, isActive: boolean) => React.ReactNode;
|
|
306
|
+
renderAvatar?: (room: Room) => React.ReactNode;
|
|
307
|
+
renderEmpty?: () => React.ReactNode;
|
|
308
|
+
className?: string;
|
|
309
|
+
itemClassName?: string;
|
|
310
|
+
}
|
|
311
|
+
declare const RoomList: React.FC<RoomListProps>;
|
|
312
|
+
|
|
313
|
+
interface TypingIndicatorProps {
|
|
314
|
+
typingText: string | null;
|
|
315
|
+
className?: string;
|
|
316
|
+
}
|
|
317
|
+
declare const TypingIndicator: React.FC<TypingIndicatorProps>;
|
|
318
|
+
|
|
319
|
+
interface OnlineBadgeProps {
|
|
320
|
+
isOnline: boolean;
|
|
321
|
+
size?: number;
|
|
322
|
+
className?: string;
|
|
323
|
+
}
|
|
324
|
+
declare const OnlineBadge: React.FC<OnlineBadgeProps>;
|
|
325
|
+
|
|
326
|
+
interface ReactionPickerProps {
|
|
327
|
+
onSelect: (emoji: string) => void;
|
|
328
|
+
currentReactions?: Reaction[];
|
|
329
|
+
currentUserId?: string;
|
|
330
|
+
emojis?: string[];
|
|
331
|
+
className?: string;
|
|
332
|
+
align?: "left" | "right";
|
|
333
|
+
}
|
|
334
|
+
declare const ReactionPicker: React.FC<ReactionPickerProps>;
|
|
335
|
+
|
|
336
|
+
interface MediaMessageProps {
|
|
337
|
+
message: Message;
|
|
338
|
+
className?: string;
|
|
339
|
+
maxWidth?: number | string;
|
|
340
|
+
}
|
|
341
|
+
declare const MediaMessage: React.FC<MediaMessageProps>;
|
|
342
|
+
|
|
343
|
+
export { ChatInput, MediaMessage, MessageList, OnlineBadge, ReactionPicker, RoomList, TypingIndicator, useMessages, usePresence, useReactions, useReadReceipts, useRooms, useTyping, useUpload };
|