@ethora/chat-component 25.12.2 → 26.1.2
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/README.md +557 -149
- package/dist/components/MainComponents/MessageContainer.d.ts +1 -0
- package/dist/components/MessageBubble/MessageReply.d.ts +2 -2
- package/dist/components/MessageNotification/MessageNotificationToast.d.ts +17 -0
- package/dist/components/MessageNotification/index.d.ts +2 -0
- package/dist/components/Modals/SettingsModals/SharedStyledComponents.d.ts +22 -0
- package/dist/components/Modals/styledModalComponents.d.ts +28 -0
- package/dist/components/styled/Button.d.ts +2 -2
- package/dist/components/styled/DateLabel.d.ts +2 -2
- package/dist/components/styled/StyledComponents.d.ts +10 -10
- package/dist/components/styled/StyledInputComponents/StyledInputComponents.d.ts +6 -6
- package/dist/context/MessageNotificationContext.d.ts +12 -0
- package/dist/firebase-config.d.ts +6 -2
- package/dist/firebase-messaging-sw.js +351 -0
- package/dist/helpers/getDataFromXml.d.ts +1 -0
- package/dist/helpers/initRoomsPresence.d.ts +1 -1
- package/dist/helpers/storeConsole.d.ts +6 -0
- package/dist/hooks/useInAppNotifications.d.ts +18 -0
- package/dist/hooks/usePushNotifications.d.ts +45 -0
- package/dist/hooks/useTabVisibility.d.ts +1 -0
- package/dist/main.css +1 -1
- package/dist/main.d.ts +5 -0
- package/dist/main.js +14686 -11893
- package/dist/main.js.map +1 -1
- package/dist/networking/api-requests/push.api.d.ts +18 -0
- package/dist/networking/stanzaHandlers.d.ts +4 -2
- package/dist/networking/xmpp/allRoomPresences.xmpp.d.ts +11 -1
- package/dist/networking/xmpp/presenceInRoom.xmpp.d.ts +1 -1
- package/dist/networking/xmpp/sendTextMessage.xmpp.d.ts +1 -1
- package/dist/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.d.ts +1 -1
- package/dist/networking/xmpp/subscribeToRoomMessages.xmpp.d.ts +9 -0
- package/dist/networking/xmppClient.d.ts +13 -3
- package/dist/roomStore/chatSettingsSlice.d.ts +1 -0
- package/dist/roomStore/index.d.ts +28 -0
- package/dist/roomStore/roomHeapSlice.d.ts +1 -1
- package/dist/roomStore/roomsSlice.d.ts +11 -1
- package/dist/types/models/config.model.d.ts +35 -1
- package/dist/types/models/room.model.d.ts +4 -1
- package/dist/types/models/xmpp.model.d.ts +3 -1
- package/dist/utils/firebasePushNotifications.d.ts +34 -0
- package/dist/utils/formatError.d.ts +1 -0
- package/dist/utils/messageNotificationManager.d.ts +16 -0
- package/dist/utils/notificationPolicy.d.ts +45 -0
- package/dist/utils/notificationUtils.d.ts +22 -0
- package/dist/utils/pushSubscriptionService.d.ts +12 -0
- package/dist/version.d.ts +1 -1
- package/package.json +7 -4
- package/public/firebase-messaging-sw.js +351 -0
- package/scripts/init-push.js +48 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* push.api.ts
|
|
3
|
+
* API methods for registering / unregistering a push notification subscription
|
|
4
|
+
* with the Ethora backend so the server can target this browser for push events.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Register a push notification/FCM registration token with the backend.
|
|
8
|
+
* Sends a POST to /push/subscription/{userId} with the registration token.
|
|
9
|
+
*
|
|
10
|
+
* @param registrationToken – The FCM token obtained via Firebase Messaging.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerPushToken(registrationToken: string): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Unregister a push endpoint from the backend (e.g. on logout).
|
|
15
|
+
*
|
|
16
|
+
* @param registrationToken – The token to unregister.
|
|
17
|
+
*/
|
|
18
|
+
export declare function unregisterPushToken(registrationToken: string): Promise<any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Element } from 'ltx';
|
|
2
2
|
import { IMessage } from '../types/types';
|
|
3
3
|
import { default as XmppClient } from './xmppClient';
|
|
4
|
-
declare const onRealtimeMessage: (stanza: Element) => Promise<IMessage>;
|
|
4
|
+
declare const onRealtimeMessage: (stanza: Element, xmppClient?: XmppClient) => Promise<IMessage>;
|
|
5
5
|
declare const onReactionMessage: (stanza: Element) => Promise<void>;
|
|
6
6
|
declare const onDeleteMessage: (stanza: Element) => Promise<void>;
|
|
7
7
|
declare const onEditMessage: (stanza: Element) => Promise<void>;
|
|
@@ -27,4 +27,6 @@ export type XMPPErrorInfo = {
|
|
|
27
27
|
message: string;
|
|
28
28
|
};
|
|
29
29
|
export declare const handleErrorMessageStanza: (stanza: Element) => XMPPErrorInfo | null;
|
|
30
|
-
|
|
30
|
+
declare const onUserUpdate: (stanza: Element) => Promise<void>;
|
|
31
|
+
declare const onChatUpdate: (stanza: Element) => Promise<void>;
|
|
32
|
+
export { onRealtimeMessage, onMessageHistory, onPresenceInRoom, onReactionHistory, onGetLastMessageArchive, handleComposing, onGetChatRooms, onNewRoomCreated, onGetMembers, onGetRoomInfo, onDeleteMessage, onEditMessage, onReactionMessage, onChatInvite, onRoomKicked, onMessageError, onUserUpdate, onChatUpdate, };
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { Client } from '@xmpp/client';
|
|
2
|
-
export
|
|
2
|
+
export interface AllRoomPresenceSummary {
|
|
3
|
+
total: number;
|
|
4
|
+
success: number;
|
|
5
|
+
failed: number;
|
|
6
|
+
failedRooms: string[];
|
|
7
|
+
failures?: Array<{
|
|
8
|
+
roomJid: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare function allRoomPresences(client: Client): Promise<AllRoomPresenceSummary>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Client } from '@xmpp/client';
|
|
2
2
|
import { Element } from '@xmpp/xml';
|
|
3
|
-
export declare const presenceInRoom: (client: Client, roomJID: string, delay?: number) => Promise<Element>;
|
|
3
|
+
export declare const presenceInRoom: (client: Client, roomJID: string, delay?: number, timeoutMs?: number) => Promise<Element>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Client } from '@xmpp/client';
|
|
2
|
-
export declare const sendTextMessage: (client: Client, roomJID: string, firstName: string, lastName: string, photo: string, walletAddress: string, userMessage: string, notDisplayedValue?: string, isReply?: boolean, showInChannel?: boolean, mainMessage?: string, devServer?: string, customId?: string) =>
|
|
2
|
+
export declare const sendTextMessage: (client: Client, roomJID: string, firstName: string, lastName: string, photo: string, walletAddress: string, userMessage: string, notDisplayedValue?: string, isReply?: boolean, showInChannel?: boolean, mainMessage?: string, devServer?: string, customId?: string) => boolean;
|
|
@@ -12,4 +12,4 @@ export declare const sendTextMessageWithTranslateTag: (client: Client, stanzaMes
|
|
|
12
12
|
showInChannel?: boolean;
|
|
13
13
|
mainMessage?: string;
|
|
14
14
|
devServer?: string;
|
|
15
|
-
}, source: Iso639_1Codes, customId?: string) =>
|
|
15
|
+
}, source: Iso639_1Codes, customId?: string) => boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from '@xmpp/client';
|
|
2
|
+
export type SubscribeResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
reason?: 'forbidden' | 'error' | 'timeout';
|
|
7
|
+
message?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function subscribeToRoomMessages(client: Client, roomJID: string, userNick?: string): Promise<SubscribeResult>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Client } from '@xmpp/client';
|
|
2
2
|
import { Iso639_1Codes, XmppClientInterface, xmppSettingsInterface, IMessage } from '../types/types';
|
|
3
|
+
import { AllRoomPresenceSummary } from './xmpp/allRoomPresences.xmpp';
|
|
3
4
|
export declare class XmppClient implements XmppClientInterface {
|
|
4
5
|
client: Client;
|
|
5
6
|
devServer: string | undefined;
|
|
@@ -18,8 +19,14 @@ export declare class XmppClient implements XmppClientInterface {
|
|
|
18
19
|
presencesReady: boolean;
|
|
19
20
|
private connectionSteps;
|
|
20
21
|
private messageQueue;
|
|
22
|
+
private pendingSendById;
|
|
21
23
|
private inFlightIds;
|
|
22
24
|
private processingQueue;
|
|
25
|
+
private currentlyProcessingQueueId;
|
|
26
|
+
private isRecoveringRoomPresence;
|
|
27
|
+
private recoveryRoomJid;
|
|
28
|
+
private joinedRooms;
|
|
29
|
+
private roomPresenceInFlight;
|
|
23
30
|
checkOnline(): boolean;
|
|
24
31
|
pingInterval: any;
|
|
25
32
|
pingTimeout: any;
|
|
@@ -45,7 +52,7 @@ export declare class XmppClient implements XmppClientInterface {
|
|
|
45
52
|
private markActivity;
|
|
46
53
|
sendAllPresencesAndMarkReady(): Promise<void>;
|
|
47
54
|
reconnect(): Promise<void>;
|
|
48
|
-
allRoomPresencesStanza(): Promise<
|
|
55
|
+
allRoomPresencesStanza(): Promise<AllRoomPresenceSummary>;
|
|
49
56
|
ensureConnected(timeout?: number): Promise<void>;
|
|
50
57
|
close(): Promise<void>;
|
|
51
58
|
wrapWithConnectionCheck<T>(operation: () => Promise<T>): Promise<T>;
|
|
@@ -64,14 +71,16 @@ export declare class XmppClient implements XmppClientInterface {
|
|
|
64
71
|
createRoomStanza(title: string, description: string): Promise<string>;
|
|
65
72
|
inviteRoomRequestStanza(to: string, roomJid: string): Promise<void>;
|
|
66
73
|
leaveTheRoomStanza: (roomJID: string) => void;
|
|
67
|
-
|
|
74
|
+
private ensureRoomPresence;
|
|
75
|
+
presenceInRoomStanza: (roomJID: string, settleDelay?: number, timeoutMs?: number, waitForJoin?: boolean) => Promise<boolean>;
|
|
76
|
+
prioritizeRoomPresence: (roomJID: string) => Promise<boolean>;
|
|
68
77
|
getHistoryStanza: (chatJID: string, max: number, before?: number, otherStanzaId?: string) => Promise<IMessage[]>;
|
|
69
78
|
getLastMessageArchiveStanza(roomJID: string): void;
|
|
70
79
|
setRoomImageStanza: (roomJid: string, roomThumbnail: string, type: string, roomBackground?: string) => void;
|
|
71
80
|
getRoomInfoStanza: (roomJID: string) => void;
|
|
72
81
|
getRoomMembersStanza: (roomJID: string) => void;
|
|
73
82
|
setVCardStanza(xmppUsername: string): void;
|
|
74
|
-
sendMessageWithPingCheck(sendFn: () => Promise<
|
|
83
|
+
sendMessageWithPingCheck(sendFn: () => Promise<boolean>): Promise<boolean>;
|
|
75
84
|
sendMessage: (roomJID: string, firstName: string, lastName: string, photo: string, walletAddress: string, userMessage: string, notDisplayedValue?: string, isReply?: boolean, showInChannel?: boolean, mainMessage?: string, customId?: string) => Promise<boolean>;
|
|
76
85
|
sendTextMessageWithTranslateTagStanza: (roomJID: string, firstName: string, lastName: string, photo: string, walletAddress: string, userMessage: string, notDisplayedValue?: string, isReply?: boolean, showInChannel?: boolean, mainMessage?: string, langSource?: Iso639_1Codes, customId?: string) => Promise<boolean>;
|
|
77
86
|
deleteMessageStanza(room: string, msgId: string): void;
|
|
@@ -82,6 +91,7 @@ export declare class XmppClient implements XmppClientInterface {
|
|
|
82
91
|
actionSetTimestampToPrivateStoreStanza(chatId: string, timestamp: number, chats?: string[]): Promise<void>;
|
|
83
92
|
createPrivateRoomStanza(title: string, description: string, to: string): Promise<string>;
|
|
84
93
|
sendMediaMessageStanza(roomJID: string, data: any, id: string): void;
|
|
94
|
+
recoverRoomPresenceOnly(roomJID: string): Promise<boolean>;
|
|
85
95
|
sendPingStanza(): void;
|
|
86
96
|
handlePong(): void;
|
|
87
97
|
handlePingTimeout(): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Reducer, AnyAction } from '@reduxjs/toolkit';
|
|
2
|
+
import { roomHeapSliceState } from './roomHeapSlice';
|
|
3
|
+
import { IRoom } from '../types/types';
|
|
4
|
+
declare const rootReducer: Reducer<{
|
|
5
|
+
chatSettingStore: any;
|
|
6
|
+
rooms: any;
|
|
7
|
+
roomHeapSlice: roomHeapSliceState & import('redux-persist/es/persistReducer').PersistPartial;
|
|
8
|
+
}, import('redux').UnknownAction, Partial<{
|
|
9
|
+
chatSettingStore: any;
|
|
10
|
+
rooms: any;
|
|
11
|
+
roomHeapSlice: roomHeapSliceState & import('redux-persist/es/persistReducer').PersistPartial;
|
|
12
|
+
}>>;
|
|
13
|
+
export type RootState = ReturnType<typeof rootReducer>;
|
|
14
|
+
export declare const getActiveRoom: (state: RootState) => IRoom | null;
|
|
15
|
+
export declare const store: import('@reduxjs/toolkit').EnhancedStore<{
|
|
16
|
+
chatSettingStore: any;
|
|
17
|
+
rooms: any;
|
|
18
|
+
roomHeapSlice: roomHeapSliceState & import('redux-persist/es/persistReducer').PersistPartial;
|
|
19
|
+
}, AnyAction, import('@reduxjs/toolkit').Tuple<[import('redux').StoreEnhancer<{
|
|
20
|
+
dispatch: import('redux-thunk').ThunkDispatch<{
|
|
21
|
+
chatSettingStore: any;
|
|
22
|
+
rooms: any;
|
|
23
|
+
roomHeapSlice: roomHeapSliceState & import('redux-persist/es/persistReducer').PersistPartial;
|
|
24
|
+
}, undefined, import('redux').UnknownAction>;
|
|
25
|
+
}>, import('redux').StoreEnhancer]>>;
|
|
26
|
+
export type AppDispatch = typeof store.dispatch;
|
|
27
|
+
export declare const persistor: import('redux-persist').Persistor;
|
|
28
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PayloadAction } from '@reduxjs/toolkit';
|
|
2
2
|
import { IMessage } from '../types/types';
|
|
3
|
-
interface roomHeapSliceState {
|
|
3
|
+
export interface roomHeapSliceState {
|
|
4
4
|
messageHeap: IMessage[];
|
|
5
5
|
}
|
|
6
6
|
export declare const roomHeapSlice: import('@reduxjs/toolkit').Slice<roomHeapSliceState, {
|
|
@@ -12,6 +12,8 @@ interface RoomMessagesState {
|
|
|
12
12
|
reportRoom: {
|
|
13
13
|
isOpen: boolean;
|
|
14
14
|
};
|
|
15
|
+
subscribedRooms: string[];
|
|
16
|
+
pushSubscriptionStatus: Record<string, 'pending' | 'subscribed' | 'error' | 'blocked'>;
|
|
15
17
|
loadingText?: string;
|
|
16
18
|
}
|
|
17
19
|
export declare const addRoomViaApi: import('@reduxjs/toolkit').AsyncThunk<void, {
|
|
@@ -100,6 +102,11 @@ export declare const roomsStore: import('@reduxjs/toolkit').Slice<RoomMessagesSt
|
|
|
100
102
|
setOpenReportModal: (state: import('immer').WritableDraft<RoomMessagesState>, action: PayloadAction<{
|
|
101
103
|
isOpen: boolean;
|
|
102
104
|
}>) => void;
|
|
105
|
+
setPushSubscriptionStatus: (state: import('immer').WritableDraft<RoomMessagesState>, action: PayloadAction<{
|
|
106
|
+
jid: string;
|
|
107
|
+
status: "pending" | "subscribed" | "error" | "blocked";
|
|
108
|
+
}>) => void;
|
|
109
|
+
clearPushSubscriptions: (state: import('immer').WritableDraft<RoomMessagesState>) => void;
|
|
103
110
|
}, "roomMessages", "roomMessages", import('@reduxjs/toolkit').SliceSelectors<RoomMessagesState>>;
|
|
104
111
|
export declare const getLastMessageTimestamp: (state: RoomMessagesState, jid: string) => string | null;
|
|
105
112
|
export declare const addRoom: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
|
|
@@ -149,6 +156,9 @@ export declare const addRoom: import('@reduxjs/toolkit').ActionCreatorWithOption
|
|
|
149
156
|
isOpen: boolean;
|
|
150
157
|
}, "roomMessages/setOpenReportModal">, insertUsers: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
|
|
151
158
|
newUsers: RoomMember[];
|
|
152
|
-
}, "roomMessages/insertUsers"
|
|
159
|
+
}, "roomMessages/insertUsers">, setPushSubscriptionStatus: import('@reduxjs/toolkit').ActionCreatorWithOptionalPayload<{
|
|
160
|
+
jid: string;
|
|
161
|
+
status: "pending" | "subscribed" | "error" | "blocked";
|
|
162
|
+
}, "roomMessages/setPushSubscriptionStatus">, clearPushSubscriptions: import('@reduxjs/toolkit').ActionCreatorWithoutPayload<"roomMessages/clearPushSubscriptions">;
|
|
153
163
|
declare const _default: import('redux').Reducer<RoomMessagesState>;
|
|
154
164
|
export default _default;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { User } from './user.model';
|
|
2
2
|
import { xmppSettingsInterface } from './xmpp.model';
|
|
3
3
|
import { PartialRoomWithMandatoryKeys, ConfigRoom } from './room.model';
|
|
4
|
-
import { MessageBubble, MessageProps } from './message.model';
|
|
4
|
+
import { MessageBubble, MessageProps, IMessage } from './message.model';
|
|
5
5
|
import { Iso639_1Codes } from './language.model';
|
|
6
6
|
import { default as React } from 'react';
|
|
7
|
+
import { MessageNotificationToastProps } from '../../components/MessageNotification/MessageNotificationToast';
|
|
7
8
|
export interface FBConfig {
|
|
8
9
|
apiKey: string;
|
|
9
10
|
authDomain: string;
|
|
@@ -13,6 +14,7 @@ export interface FBConfig {
|
|
|
13
14
|
appId: string;
|
|
14
15
|
}
|
|
15
16
|
export interface IConfig {
|
|
17
|
+
appId?: string;
|
|
16
18
|
disableHeader?: boolean;
|
|
17
19
|
disableMedia?: boolean;
|
|
18
20
|
colors?: {
|
|
@@ -158,4 +160,36 @@ export interface IConfig {
|
|
|
158
160
|
hideSearch?: boolean;
|
|
159
161
|
};
|
|
160
162
|
useStoreConsoleEnabled?: boolean;
|
|
163
|
+
inAppNotifications?: {
|
|
164
|
+
enabled?: boolean;
|
|
165
|
+
showInContext?: boolean;
|
|
166
|
+
position?: {
|
|
167
|
+
horizontal?: 'left' | 'right' | 'center';
|
|
168
|
+
vertical?: 'top' | 'bottom';
|
|
169
|
+
offset?: {
|
|
170
|
+
top?: number | string;
|
|
171
|
+
bottom?: number | string;
|
|
172
|
+
left?: number | string;
|
|
173
|
+
right?: number | string;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
maxNotifications?: number;
|
|
177
|
+
duration?: number;
|
|
178
|
+
onClick?: (params: {
|
|
179
|
+
roomJID: string;
|
|
180
|
+
messageId: string;
|
|
181
|
+
message: IMessage;
|
|
182
|
+
roomName: string;
|
|
183
|
+
senderName: string;
|
|
184
|
+
}) => void | Promise<void>;
|
|
185
|
+
customComponent?: React.ComponentType<MessageNotificationToastProps>;
|
|
186
|
+
};
|
|
187
|
+
pushNotifications?: {
|
|
188
|
+
enabled?: boolean;
|
|
189
|
+
vapidPublicKey?: string;
|
|
190
|
+
firebaseConfig?: FBConfig;
|
|
191
|
+
serviceWorkerPath?: string;
|
|
192
|
+
serviceWorkerScope?: string;
|
|
193
|
+
softAsk?: boolean;
|
|
194
|
+
};
|
|
161
195
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { IMessage, LastMessage } from './message.model';
|
|
2
2
|
export interface RoomMember {
|
|
3
|
+
_id: string;
|
|
3
4
|
firstName: string;
|
|
4
5
|
lastName: string;
|
|
5
6
|
xmppUsername: string;
|
|
6
|
-
|
|
7
|
+
profileImage?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
email?: string;
|
|
7
10
|
ban_status?: string;
|
|
8
11
|
jid?: string;
|
|
9
12
|
name?: string;
|
|
@@ -40,7 +40,9 @@ export interface XmppClientInterface {
|
|
|
40
40
|
createRoomStanza(title: string, description: string, to?: string): Promise<string | object>;
|
|
41
41
|
inviteRoomRequestStanza(to: string, roomJid: string): Promise<void>;
|
|
42
42
|
leaveTheRoomStanza(roomJID: string): void;
|
|
43
|
-
presenceInRoomStanza(roomJID: string):
|
|
43
|
+
presenceInRoomStanza(roomJID: string, settleDelay?: number, timeoutMs?: number, waitForJoin?: boolean): Promise<boolean>;
|
|
44
|
+
prioritizeRoomPresence(roomJID: string): Promise<boolean>;
|
|
45
|
+
recoverRoomPresenceOnly(roomJID: string): Promise<boolean>;
|
|
44
46
|
getHistoryStanza(chatJID: string, max: number, before?: number, otherStanzaId?: string): Promise<IMessage[]>;
|
|
45
47
|
getLastMessageArchiveStanza(roomJID: string): void;
|
|
46
48
|
setRoomImageStanza(roomJid: string, roomThumbnail: string, type: string, roomBackground?: string): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MessagePayload } from 'firebase/messaging';
|
|
2
|
+
/**
|
|
3
|
+
* requestNotificationPermission()
|
|
4
|
+
* Requests permission from the user to display notifications.
|
|
5
|
+
* @returns boolean indicating if permission was granted.
|
|
6
|
+
*/
|
|
7
|
+
export declare function requestNotificationPermission(): Promise<boolean>;
|
|
8
|
+
interface FcmRegistrationOptions {
|
|
9
|
+
vapidPublicKey?: string;
|
|
10
|
+
serviceWorkerPath?: string;
|
|
11
|
+
serviceWorkerScope?: string;
|
|
12
|
+
firebaseConfig?: any;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* getFCMToken()
|
|
17
|
+
* Obtains the FCM registration token for the current device/browser.
|
|
18
|
+
* @param options - VAPID key and service worker settings.
|
|
19
|
+
* @returns The FCM token or null if failed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFCMToken(options?: FcmRegistrationOptions): Promise<string | null>;
|
|
22
|
+
/**
|
|
23
|
+
* initPushNotifications()
|
|
24
|
+
* Orchestrates the full push initialization flow.
|
|
25
|
+
* @returns The FCM token if successful, or null.
|
|
26
|
+
*/
|
|
27
|
+
export declare function initPushNotifications(options?: FcmRegistrationOptions): Promise<string | null>;
|
|
28
|
+
/**
|
|
29
|
+
* listenForForegroundMessages()
|
|
30
|
+
* Subscribes to FCM messages while the app is in the foreground.
|
|
31
|
+
* Returns an unsubscribe function.
|
|
32
|
+
*/
|
|
33
|
+
export declare function listenForForegroundMessages(handler: (payload: MessagePayload) => void, firebaseConfig?: any): () => void;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatError: (error: unknown, fallback?: string) => string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IMessage } from '../types/models/message.model';
|
|
2
|
+
export interface MessageNotificationCallback {
|
|
3
|
+
(message: IMessage, roomName: string, senderName: string, roomJID: string): void;
|
|
4
|
+
}
|
|
5
|
+
declare class MessageNotificationManager {
|
|
6
|
+
private callbacks;
|
|
7
|
+
private pending;
|
|
8
|
+
private maxPending;
|
|
9
|
+
private pendingTtlMs;
|
|
10
|
+
addCallback(callback: MessageNotificationCallback): () => void;
|
|
11
|
+
getCallbackCount(): number;
|
|
12
|
+
private flushPending;
|
|
13
|
+
showNotification(message: IMessage, roomName: string, senderName: string, roomJID: string): void;
|
|
14
|
+
}
|
|
15
|
+
export declare const messageNotificationManager: MessageNotificationManager;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IConfig, IRoom } from '../types/types';
|
|
2
|
+
export interface PushPayloadLike {
|
|
3
|
+
messageId?: string;
|
|
4
|
+
notification?: {
|
|
5
|
+
title?: string;
|
|
6
|
+
body?: string;
|
|
7
|
+
image?: string;
|
|
8
|
+
};
|
|
9
|
+
data?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export declare const isSystemPayload: (payload: PushPayloadLike) => boolean;
|
|
12
|
+
export declare const isActiveRoom: (activeRoomJid?: string, roomJid?: string) => boolean;
|
|
13
|
+
export declare const isCurrentUserMessage: (messageUserId?: string, currentXmppUsername?: string) => boolean;
|
|
14
|
+
export declare const buildNotificationUrl: (payload: PushPayloadLike, origin: string) => string;
|
|
15
|
+
export interface XmppToastDecisionInput {
|
|
16
|
+
config?: IConfig;
|
|
17
|
+
tabVisible: boolean;
|
|
18
|
+
activeRoom: boolean;
|
|
19
|
+
currentUserMessage: boolean;
|
|
20
|
+
isSystem: boolean;
|
|
21
|
+
isHistory?: boolean;
|
|
22
|
+
isCatchup?: boolean;
|
|
23
|
+
xmppOnline?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface DecisionResult {
|
|
26
|
+
show: boolean;
|
|
27
|
+
reason: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const shouldShowXmppToast: ({ config, tabVisible, activeRoom, currentUserMessage, isSystem, isHistory, isCatchup, }: XmppToastDecisionInput) => DecisionResult;
|
|
30
|
+
export interface ForegroundPushToastInput {
|
|
31
|
+
config?: IConfig;
|
|
32
|
+
tabVisible: boolean;
|
|
33
|
+
alreadyInStore: boolean;
|
|
34
|
+
deduped: boolean;
|
|
35
|
+
isSystem: boolean;
|
|
36
|
+
isHistory?: boolean;
|
|
37
|
+
isCatchup?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare const shouldShowForegroundPushToast: ({ config, tabVisible, alreadyInStore, deduped, isSystem, isHistory, isCatchup, }: ForegroundPushToastInput) => DecisionResult;
|
|
40
|
+
export interface ForegroundOsPushInput {
|
|
41
|
+
config?: IConfig;
|
|
42
|
+
tabVisible: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare const shouldShowForegroundOsPush: ({ config, tabVisible, }: ForegroundOsPushInput) => DecisionResult;
|
|
45
|
+
export declare const hasMessageInRooms: (roomsMap: Record<string, IRoom>, messageId?: string) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PushPayloadLike } from './notificationPolicy';
|
|
2
|
+
/**
|
|
3
|
+
* showBrowserNotification()
|
|
4
|
+
* Triggers a native browser notification.
|
|
5
|
+
* @param title - The notification title.
|
|
6
|
+
* @param options - Standard NotificationOptions plus Ethora-specific data.
|
|
7
|
+
* @param serviceWorkerScope - Optional SW scope for better integration.
|
|
8
|
+
*/
|
|
9
|
+
export declare function showBrowserNotification(title: string, options: NotificationOptions & {
|
|
10
|
+
data?: any;
|
|
11
|
+
}, serviceWorkerScope?: string, onClick?: (event: Event) => void): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Helper to extract common data from a message/payload for browser notifications.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getBrowserNotificationData(payload: PushPayloadLike, origin: string): {
|
|
16
|
+
title: any;
|
|
17
|
+
body: any;
|
|
18
|
+
url: string;
|
|
19
|
+
icon: string;
|
|
20
|
+
badge: string;
|
|
21
|
+
tag: string;
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as XmppClient } from '../networking/xmppClient';
|
|
2
|
+
import { SubscribeResult } from '../networking/xmpp/subscribeToRoomMessages.xmpp';
|
|
3
|
+
declare class PushSubscriptionService {
|
|
4
|
+
private failedRooms;
|
|
5
|
+
private retryCooldownMs;
|
|
6
|
+
private inFlightRooms;
|
|
7
|
+
private inFlightBatch;
|
|
8
|
+
private resolveClient;
|
|
9
|
+
subscribeToRoom(roomJID: string, client?: XmppClient | null): Promise<SubscribeResult>;
|
|
10
|
+
}
|
|
11
|
+
export declare const pushSubscriptionService: PushSubscriptionService;
|
|
12
|
+
export {};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ETHORA_CHAT_COMPONENT_VERSION = "
|
|
1
|
+
export declare const ETHORA_CHAT_COMPONENT_VERSION = "26.01.01";
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethora/chat-component",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.01.02",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"public/firebase-messaging-sw.js",
|
|
10
|
+
"scripts/init-push.js"
|
|
9
11
|
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"ethora-chat": "./scripts/init-push.js"
|
|
14
|
+
},
|
|
10
15
|
"scripts": {
|
|
11
16
|
"dev": "vite",
|
|
12
17
|
"build": "tsc && vite build",
|
|
@@ -19,8 +24,6 @@
|
|
|
19
24
|
"@emoji-mart/data": "^1.2.1",
|
|
20
25
|
"@emoji-mart/react": "^1.1.1",
|
|
21
26
|
"@reduxjs/toolkit": "^2.8.2",
|
|
22
|
-
"@types/react": "^19.1.8",
|
|
23
|
-
"@types/react-dom": "^19.1.6",
|
|
24
27
|
"@types/styled-components": "^5.1.34",
|
|
25
28
|
"@xmpp/client": "^0.13.6",
|
|
26
29
|
"axios": "^1.10.0",
|