@ethora/chat-component-rn 26.4.1
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/LICENSE +661 -0
- package/README.md +148 -0
- package/empty-shim.js +15 -0
- package/index.js +13 -0
- package/metro.js +72 -0
- package/package.json +99 -0
- package/src/api.config.ts +34 -0
- package/src/assets/BG.png +0 -0
- package/src/assets/BG.tsx +56 -0
- package/src/assets/File.svg +4 -0
- package/src/assets/ForzaCare.png +0 -0
- package/src/assets/ForzaCare.tsx +27 -0
- package/src/assets/icons.tsx +685 -0
- package/src/assets/images.tsx +41 -0
- package/src/assets/test.xml +243 -0
- package/src/components/AuthForms/Login.tsx +295 -0
- package/src/components/AuthForms/LoginAnonym.tsx +68 -0
- package/src/components/AuthForms/Register.tsx +8 -0
- package/src/components/ContextMenu/ContextMenuComponents.tsx +87 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +244 -0
- package/src/components/ExampleComponents/CustomMessage.tsx +92 -0
- package/src/components/ExampleComponents/CustomTypingIndicatorExamples.tsx +239 -0
- package/src/components/Header/HeaderRoomList.tsx +104 -0
- package/src/components/InputComponents/AudioInput.tsx +24 -0
- package/src/components/InputComponents/AudioRecorder.tsx +100 -0
- package/src/components/InputComponents/MediaInput.tsx +114 -0
- package/src/components/InputComponents/RecordingIndicator.tsx +77 -0
- package/src/components/InputComponents/Search.tsx +135 -0
- package/src/components/InputComponents/TextInput.tsx +66 -0
- package/src/components/MainComponents/ChatHeader.tsx +163 -0
- package/src/components/MainComponents/ChatRoom.tsx +392 -0
- package/src/components/MainComponents/ChatWrapper.tsx +318 -0
- package/src/components/MainComponents/ChooseChatMessage.tsx +44 -0
- package/src/components/MainComponents/ConnectionBanner.tsx +33 -0
- package/src/components/MainComponents/EditWrapper.tsx +72 -0
- package/src/components/MainComponents/LoginWrapper.tsx +134 -0
- package/src/components/MainComponents/MediaMessage.tsx +55 -0
- package/src/components/MainComponents/MessageContainer.tsx +122 -0
- package/src/components/MainComponents/MessageList.tsx +429 -0
- package/src/components/MainComponents/NoMessagesPlaceholder.tsx +49 -0
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +143 -0
- package/src/components/MainComponents/RNStyled.tsx +34 -0
- package/src/components/MainComponents/ReduxWrapper.tsx +40 -0
- package/src/components/MainComponents/RoomList.tsx +246 -0
- package/src/components/MainComponents/Select.tsx +165 -0
- package/src/components/MainComponents/Switch.tsx +73 -0
- package/src/components/MainComponents/SystemMessage.tsx +42 -0
- package/src/components/Menu/HeaderRoomListMenu.tsx +169 -0
- package/src/components/MenuRoom/MenuRoom.tsx +46 -0
- package/src/components/MessageBubble/Avatar.tsx +84 -0
- package/src/components/MessageBubble/BottomReplyContainer.tsx +117 -0
- package/src/components/MessageBubble/CustomDivider.tsx +10 -0
- package/src/components/MessageBubble/DeletedMessage.tsx +36 -0
- package/src/components/MessageBubble/Message.tsx +400 -0
- package/src/components/MessageBubble/MessageInteractions.tsx +247 -0
- package/src/components/MessageBubble/MessageReaction.tsx +149 -0
- package/src/components/MessageBubble/MessageReply.tsx +50 -0
- package/src/components/MessageBubble/MessageTranslations.tsx +30 -0
- package/src/components/Modals/AddMembersModal/AddMembersModal.tsx +142 -0
- package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +471 -0
- package/src/components/Modals/ChatProfileModal/DeleteChatModal.tsx +91 -0
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +298 -0
- package/src/components/Modals/Modal/Modal.tsx +52 -0
- package/src/components/Modals/ModalHeaderComponent.tsx +41 -0
- package/src/components/Modals/ModalSelectMedia/ModalSelectMedia.tsx +285 -0
- package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +103 -0
- package/src/components/Modals/NewChatModal/ModalContent.tsx +151 -0
- package/src/components/Modals/NewChatModal/NewChatModal.tsx +391 -0
- package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +136 -0
- package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +134 -0
- package/src/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.tsx +63 -0
- package/src/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.tsx +115 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +121 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/StyledComponents.ts +0 -0
- package/src/components/Modals/SettingsModals/ProfileShares/ProfileShares.tsx +65 -0
- package/src/components/Modals/SettingsModals/Referrals/Referrals.tsx +90 -0
- package/src/components/Modals/SettingsModals/SharedStyledComponents.ts +74 -0
- package/src/components/Modals/SettingsModals/Visibility/RadioInput.tsx +59 -0
- package/src/components/Modals/SettingsModals/Visibility/StyledComponents.ts +32 -0
- package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +146 -0
- package/src/components/Modals/UserProfileModal/EditUserModal.tsx +163 -0
- package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +410 -0
- package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +85 -0
- package/src/components/Modals/styledModalComponents.tsx +181 -0
- package/src/components/OperationalModal/OperationalModal.tsx +78 -0
- package/src/components/RoomComponents/ChatRoomItem.tsx +219 -0
- package/src/components/RoomComponents/LastMessageItem.tsx +47 -0
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +62 -0
- package/src/components/RoomComponents/styled/LastMessageEmoji.tsx +26 -0
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +70 -0
- package/src/components/RoomComponents/styled/LastTextMessage.tsx +65 -0
- package/src/components/RoomComponents/styled/StyledRoomComponents.ts +53 -0
- package/src/components/SortDropDown/index.tsx +76 -0
- package/src/components/Thread/ThreadHeader.tsx +41 -0
- package/src/components/Thread/ThreadWrapper.tsx +270 -0
- package/src/components/Toast/Toast.tsx +128 -0
- package/src/components/Toast/index.ts +13 -0
- package/src/components/UsersList/StyledComponents.ts +30 -0
- package/src/components/UsersList/UsersList.tsx +112 -0
- package/src/components/styled/ActionButton.tsx +40 -0
- package/src/components/styled/AudioMessage.tsx +82 -0
- package/src/components/styled/Button.tsx +107 -0
- package/src/components/styled/ChatWrapperBox.tsx +9 -0
- package/src/components/styled/DateLabel.tsx +77 -0
- package/src/components/styled/Loader.tsx +65 -0
- package/src/components/styled/MediaFilePreview.tsx +42 -0
- package/src/components/styled/MediaModal.tsx +54 -0
- package/src/components/styled/MessageImage.tsx +54 -0
- package/src/components/styled/NewMessageLabel.tsx +50 -0
- package/src/components/styled/RoomListComponents/index.tsx +164 -0
- package/src/components/styled/SendInput.tsx +297 -0
- package/src/components/styled/StyledComponents.ts +320 -0
- package/src/components/styled/StyledInput.tsx +101 -0
- package/src/components/styled/StyledInputComponents/AudioComponents.tsx +1 -0
- package/src/components/styled/StyledInputComponents/Composing.tsx +97 -0
- package/src/components/styled/StyledInputComponents/CustomTypingIndicator.tsx +261 -0
- package/src/components/styled/StyledInputComponents/MediaComponents.tsx +90 -0
- package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +131 -0
- package/src/components/styled/StyledInputComponents/VideoComponents.tsx +49 -0
- package/src/components/styled/TreadLabel.tsx +50 -0
- package/src/components/styled/UnsupportedType.tsx +95 -0
- package/src/components/styled/VideoMessage.tsx +68 -0
- package/src/context/MessageNotificationContext.tsx +335 -0
- package/src/context/PushNotificationProvider.tsx +78 -0
- package/src/context/ToastContext.tsx +63 -0
- package/src/context/toastProvider.tsx +0 -0
- package/src/context/xmppProvider.tsx +364 -0
- package/src/helpers/block_scroll.ts +95 -0
- package/src/helpers/chatAutoEnterer.ts +46 -0
- package/src/helpers/checkUniqueUsers.tsx +31 -0
- package/src/helpers/constants/CHAT_TYPES.ts +6 -0
- package/src/helpers/constants/LANGUAGE_OPTIONS.ts +14 -0
- package/src/helpers/constants/LOCAL_STORAGE.ts +3 -0
- package/src/helpers/constants/MESSAGE_INTERACTIONS.ts +29 -0
- package/src/helpers/constants/MODAL_TYPES.ts +57 -0
- package/src/helpers/constants/PLATFORM_CONSTANTS.ts +3 -0
- package/src/helpers/createMainMessageForThread.ts +23 -0
- package/src/helpers/createMessageFromXml.ts +118 -0
- package/src/helpers/createRoomFromApi.tsx +27 -0
- package/src/helpers/createUserNameFromSetUser.ts +15 -0
- package/src/helpers/dateComparison.ts +12 -0
- package/src/helpers/debounce.ts +10 -0
- package/src/helpers/ensureScopedChatCache.ts +61 -0
- package/src/helpers/extractUniqueMembersFromRooms.ts +45 -0
- package/src/helpers/formatNumberWithCommas.ts +3 -0
- package/src/helpers/getBooleanFromString.ts +7 -0
- package/src/helpers/getDataFromXml.ts +80 -0
- package/src/helpers/getNumberFromString.ts +5 -0
- package/src/helpers/getRoomsWithRetry.ts +45 -0
- package/src/helpers/getTintedColor.ts +28 -0
- package/src/helpers/getUnnamedUsers.ts +39 -0
- package/src/helpers/handleCopyClick.ts +3 -0
- package/src/helpers/handleXmppError.ts +14 -0
- package/src/helpers/hashcolor.ts +34 -0
- package/src/helpers/historyPreloadScheduler.ts +264 -0
- package/src/helpers/initRoomsPresence.ts +32 -0
- package/src/helpers/initXmppRooms.tsx +71 -0
- package/src/helpers/insertMessageWithDelimiter.ts +96 -0
- package/src/helpers/isChatIdPresentInArray.ts +54 -0
- package/src/helpers/localStorageUser.ts +9 -0
- package/src/helpers/markdownParser.tsx +295 -0
- package/src/helpers/nanoToMs.ts +3 -0
- package/src/helpers/parseMessageBody.tsx +516 -0
- package/src/helpers/parseUrls.tsx +42 -0
- package/src/helpers/resolveInitBeforeLoadUser.ts +240 -0
- package/src/helpers/storeConsole.ts +26 -0
- package/src/helpers/transformTranslatations.ts +16 -0
- package/src/helpers/updateMessagesTillLast.tsx +104 -0
- package/src/helpers/updatedChatLastTimestamps.ts +29 -0
- package/src/helpers/validator.ts +20 -0
- package/src/helpers/walletUsername.ts +12 -0
- package/src/hooks/hooks.ts +6 -0
- package/src/hooks/useChatSettingState.tsx +38 -0
- package/src/hooks/useChatWrapperInit.ts +266 -0
- package/src/hooks/useComposing.tsx +59 -0
- package/src/hooks/useCustomTypingIndicator.tsx +193 -0
- package/src/hooks/useEventHandlers.tsx +81 -0
- package/src/hooks/useGetNewArchRoom.tsx +57 -0
- package/src/hooks/useHeapSender.tsx +88 -0
- package/src/hooks/useLocalStorage.tsx +53 -0
- package/src/hooks/useLogout.tsx +31 -0
- package/src/hooks/useMessageHeapState.tsx +11 -0
- package/src/hooks/useMessageLoaderQueue.tsx +90 -0
- package/src/hooks/useMessageQueue.ts +146 -0
- package/src/hooks/usePendingNotification.ts +49 -0
- package/src/hooks/usePrevious.tsx +15 -0
- package/src/hooks/usePushNotifications.ts +106 -0
- package/src/hooks/useQRCodeChatHandler.ts +58 -0
- package/src/hooks/useRoomInitialization.tsx +160 -0
- package/src/hooks/useRoomState.tsx +47 -0
- package/src/hooks/useRoomUrl.tsx +41 -0
- package/src/hooks/useSendMessage.tsx +306 -0
- package/src/hooks/useUnreadMessagesCounter.ts +55 -0
- package/src/hooks/useXmppInitialization.ts +148 -0
- package/src/main.ts +45 -0
- package/src/networking/api-requests/auth.api.ts +140 -0
- package/src/networking/api-requests/push.api.ts +55 -0
- package/src/networking/api-requests/roomMembers.api.ts +20 -0
- package/src/networking/api-requests/rooms.api.ts +142 -0
- package/src/networking/api-requests/user.api.ts +65 -0
- package/src/networking/apiClient.ts +149 -0
- package/src/networking/helpers/refreshChecker.ts +13 -0
- package/src/networking/stanzaHandlers.ts +418 -0
- package/src/networking/xmpp/actionSetTimestampToPrivateStore.xmpp.ts +37 -0
- package/src/networking/xmpp/allRoomPresences.xmpp.ts +10 -0
- package/src/networking/xmpp/createPrivateRoom.xmpp.ts +26 -0
- package/src/networking/xmpp/createRoom.xmpp.ts +35 -0
- package/src/networking/xmpp/createRoomPresence.xmpp.ts +74 -0
- package/src/networking/xmpp/createTimeoutPromise.xmpp.ts +15 -0
- package/src/networking/xmpp/deleteMessage.xmpp.ts +19 -0
- package/src/networking/xmpp/editMessage.xmpp.ts +46 -0
- package/src/networking/xmpp/getChatsPrivateStoreRequest.xmpp.ts +57 -0
- package/src/networking/xmpp/getHistory.xmpp.ts +140 -0
- package/src/networking/xmpp/getLastMessageArchive.xmpp.ts +24 -0
- package/src/networking/xmpp/getRoomInfo.xmpp.ts +15 -0
- package/src/networking/xmpp/getRoomMembers.xmpp.ts +13 -0
- package/src/networking/xmpp/getRooms.xmpp.ts +43 -0
- package/src/networking/xmpp/getRoomsPaged.xmpp.ts +59 -0
- package/src/networking/xmpp/handlePong.xmpp.ts +7 -0
- package/src/networking/xmpp/handleStanzas.xmpp.ts +55 -0
- package/src/networking/xmpp/inviteRoomRequest.xmpp.ts +25 -0
- package/src/networking/xmpp/leaveTheRoom.xmpp.ts +15 -0
- package/src/networking/xmpp/listenerManager.ts +116 -0
- package/src/networking/xmpp/presenceInRoom.xmpp.ts +57 -0
- package/src/networking/xmpp/roomConfig.xmpp.ts +71 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +97 -0
- package/src/networking/xmpp/sendMessageReaction.xmpp.ts +41 -0
- package/src/networking/xmpp/sendPing.xmpp.ts +21 -0
- package/src/networking/xmpp/sendTextMessage.xmpp.ts +99 -0
- package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +44 -0
- package/src/networking/xmpp/sendTypingRequest.xmpp.ts +26 -0
- package/src/networking/xmpp/setChatsPrivateStoreRequest.xmpp.ts +48 -0
- package/src/networking/xmpp/setMeAsOwner.xmpp.ts +52 -0
- package/src/networking/xmpp/setRoomImage.xmpp.ts +26 -0
- package/src/networking/xmpp/setVCard.xmpp.ts +19 -0
- package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +75 -0
- package/src/networking/xmppClient.ts +603 -0
- package/src/roomStore/Middleware/logoutMiddleware.tsx +24 -0
- package/src/roomStore/Middleware/newMessageMidlleware.tsx +87 -0
- package/src/roomStore/Middleware/reactionsMiddleware.tsx +77 -0
- package/src/roomStore/Middleware/testMiddleware.tsx +20 -0
- package/src/roomStore/Middleware/unreadMidlleware.tsx +58 -0
- package/src/roomStore/chatSettingsSlice.ts +178 -0
- package/src/roomStore/index.ts +68 -0
- package/src/roomStore/persistence.ts +152 -0
- package/src/roomStore/roomHeapSlice.ts +37 -0
- package/src/roomStore/roomsSlice.ts +353 -0
- package/src/services/pushNotifications.ts +170 -0
- package/src/services/pushSubscriptionService.ts +145 -0
- package/src/types/messages.ts +61 -0
- package/src/types/models/action.model.ts +30 -0
- package/src/types/models/config.model.ts +16 -0
- package/src/types/models/customComponents.model.ts +53 -0
- package/src/types/models/language.model.ts +11 -0
- package/src/types/models/media.model.ts +5 -0
- package/src/types/models/message.model.ts +69 -0
- package/src/types/models/modal.model.ts +9 -0
- package/src/types/models/room.model.ts +120 -0
- package/src/types/models/user.model.ts +90 -0
- package/src/types/models/xmpp.model.ts +155 -0
- package/src/types/types.ts +505 -0
- package/src/utils/PriorityQueue.ts +47 -0
- package/src/utils/actionHelpers.ts +40 -0
- package/src/utils/actionLogger.ts +64 -0
- package/src/utils/clientRegistry.ts +80 -0
- package/src/utils/devLogger.ts +197 -0
- package/src/utils/messageNotificationManager.ts +108 -0
- package/src/utils/resendMessage.ts +87 -0
- package/src/utils/toastEmitter.ts +27 -0
- package/src/utils/xmppMemoryMonitor.ts +63 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Client } from '@xmpp/client';
|
|
2
|
+
import { Element } from '@xmpp/xml';
|
|
3
|
+
|
|
4
|
+
const activeListeners = new Map<
|
|
5
|
+
string,
|
|
6
|
+
{
|
|
7
|
+
handler: (stanza: Element) => void;
|
|
8
|
+
client: Client;
|
|
9
|
+
eventType: string;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
>();
|
|
13
|
+
|
|
14
|
+
export class XmppListenerManager {
|
|
15
|
+
static addListener(
|
|
16
|
+
client: Client,
|
|
17
|
+
eventType: string,
|
|
18
|
+
listenerKey: string,
|
|
19
|
+
handler: (stanza: Element) => void
|
|
20
|
+
): void {
|
|
21
|
+
this.removeListener(listenerKey);
|
|
22
|
+
|
|
23
|
+
activeListeners.set(listenerKey, {
|
|
24
|
+
handler,
|
|
25
|
+
client,
|
|
26
|
+
eventType,
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
client.on(eventType, handler);
|
|
31
|
+
|
|
32
|
+
if (process.env.NODE_ENV === 'development') {
|
|
33
|
+
console.log(
|
|
34
|
+
`[XmppListenerManager] Added listener: ${listenerKey}, Total: ${activeListeners.size}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static removeListener(listenerKey: string): boolean {
|
|
40
|
+
const listener = activeListeners.get(listenerKey);
|
|
41
|
+
if (listener) {
|
|
42
|
+
listener.client.off(listener.eventType, listener.handler);
|
|
43
|
+
activeListeners.delete(listenerKey);
|
|
44
|
+
|
|
45
|
+
if (process.env.NODE_ENV === 'development') {
|
|
46
|
+
console.log(
|
|
47
|
+
`[XmppListenerManager] Removed listener: ${listenerKey}, Total: ${activeListeners.size}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static removeAllListenersForClient(client: Client): void {
|
|
56
|
+
let removedCount = 0;
|
|
57
|
+
for (const [key, listener] of activeListeners.entries()) {
|
|
58
|
+
if (listener.client === client) {
|
|
59
|
+
listener.client.off(listener.eventType, listener.handler);
|
|
60
|
+
activeListeners.delete(key);
|
|
61
|
+
removedCount++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (process.env.NODE_ENV === 'development' && removedCount > 0) {
|
|
66
|
+
console.log(
|
|
67
|
+
`[XmppListenerManager] Removed ${removedCount} listeners for client, Total: ${activeListeners.size}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static getListenerKey(operation: string, identifier: string): string {
|
|
73
|
+
return `${operation}-${identifier}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static clearAllListeners(): void {
|
|
77
|
+
const count = activeListeners.size;
|
|
78
|
+
for (const [key, listener] of activeListeners.entries()) {
|
|
79
|
+
listener.client.off(listener.eventType, listener.handler);
|
|
80
|
+
}
|
|
81
|
+
activeListeners.clear();
|
|
82
|
+
|
|
83
|
+
if (process.env.NODE_ENV === 'development') {
|
|
84
|
+
console.log(`[XmppListenerManager] Cleared all ${count} listeners`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static getActiveListenerCount(): number {
|
|
89
|
+
return activeListeners.size;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static getActiveListenersInfo(): Array<{
|
|
93
|
+
key: string;
|
|
94
|
+
eventType: string;
|
|
95
|
+
timestamp: number;
|
|
96
|
+
age: number;
|
|
97
|
+
}> {
|
|
98
|
+
const now = Date.now();
|
|
99
|
+
return Array.from(activeListeners.entries()).map(([key, listener]) => ({
|
|
100
|
+
key,
|
|
101
|
+
eventType: listener.eventType,
|
|
102
|
+
timestamp: listener.timestamp,
|
|
103
|
+
age: now - listener.timestamp,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static logActiveListeners(): void {
|
|
108
|
+
if (process.env.NODE_ENV === 'development') {
|
|
109
|
+
const info = this.getActiveListenersInfo();
|
|
110
|
+
console.log(
|
|
111
|
+
`[XmppListenerManager] Active listeners (${info.length}):`,
|
|
112
|
+
info
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
3
|
+
import { Element } from '@xmpp/xml';
|
|
4
|
+
export const presenceInRoom = async (
|
|
5
|
+
client: Client,
|
|
6
|
+
roomJID: string,
|
|
7
|
+
delay = 2000
|
|
8
|
+
): Promise<Element> => {
|
|
9
|
+
let stanzaHandler: (stanza: Element) => void;
|
|
10
|
+
|
|
11
|
+
const unsubscribe = () => client.off('stanza', stanzaHandler);
|
|
12
|
+
|
|
13
|
+
return new Promise(async (resolve, reject) => {
|
|
14
|
+
let settled = false;
|
|
15
|
+
|
|
16
|
+
const finish = (cb: (value?: any) => void, value?: any) => {
|
|
17
|
+
if (settled) {return;}
|
|
18
|
+
settled = true;
|
|
19
|
+
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
unsubscribe();
|
|
22
|
+
cb(value);
|
|
23
|
+
}, delay);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
stanzaHandler = (stanza) => {
|
|
27
|
+
if (
|
|
28
|
+
stanza.is('presence') &&
|
|
29
|
+
stanza.attrs.id === 'presenceInRoom' &&
|
|
30
|
+
stanza.attrs.from?.startsWith(roomJID)
|
|
31
|
+
) {
|
|
32
|
+
finish(resolve, stanza);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
client.on('stanza', stanzaHandler);
|
|
37
|
+
|
|
38
|
+
const presence = xml(
|
|
39
|
+
'presence',
|
|
40
|
+
{
|
|
41
|
+
from: client.jid?.toString(),
|
|
42
|
+
to: `${roomJID}/${client.jid?.getLocal()}`,
|
|
43
|
+
id: 'presenceInRoom',
|
|
44
|
+
},
|
|
45
|
+
xml('x', { xmlns: 'http://jabber.org/protocol/muc' })
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await client.send(presence);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
unsubscribe();
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await createTimeoutPromise(2000, unsubscribe).catch(reject);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
3
|
+
import { Element } from 'ltx';
|
|
4
|
+
|
|
5
|
+
export function roomConfig(
|
|
6
|
+
roomId: string,
|
|
7
|
+
roomTitle: string,
|
|
8
|
+
roomDescription: string,
|
|
9
|
+
client: Client
|
|
10
|
+
) {
|
|
11
|
+
const id = `room-config:${Date.now().toString()}`;
|
|
12
|
+
|
|
13
|
+
let stanzaHdlrPointer: {
|
|
14
|
+
(el: Element): void;
|
|
15
|
+
(stanza: any): void;
|
|
16
|
+
(el: Element): void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const unsubscribe = () => {
|
|
20
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const responsePromise = new Promise((resolve) => {
|
|
24
|
+
stanzaHdlrPointer = (stanza: { attrs: { [x: string]: string } }) => {
|
|
25
|
+
if (stanza.attrs.id === id && stanza.attrs.type === 'result') {
|
|
26
|
+
unsubscribe();
|
|
27
|
+
resolve(true);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
client.on('stanza', stanzaHdlrPointer);
|
|
32
|
+
|
|
33
|
+
const message = xml(
|
|
34
|
+
'iq',
|
|
35
|
+
{
|
|
36
|
+
id: id,
|
|
37
|
+
to: roomId,
|
|
38
|
+
type: 'set',
|
|
39
|
+
},
|
|
40
|
+
xml(
|
|
41
|
+
'query',
|
|
42
|
+
{ xmlns: 'http://jabber.org/protocol/muc#owner' },
|
|
43
|
+
xml(
|
|
44
|
+
'x',
|
|
45
|
+
{ xmlns: 'jabber:x:data', type: 'submit' },
|
|
46
|
+
xml(
|
|
47
|
+
'field',
|
|
48
|
+
{ var: 'FORM_TYPE' },
|
|
49
|
+
xml('value', {}, 'http://jabber.org/protocol/muc#roomconfig')
|
|
50
|
+
),
|
|
51
|
+
xml(
|
|
52
|
+
'field',
|
|
53
|
+
{ var: 'muc#roomconfig_roomname' },
|
|
54
|
+
xml('value', {}, roomTitle)
|
|
55
|
+
),
|
|
56
|
+
xml(
|
|
57
|
+
'field',
|
|
58
|
+
{ var: 'muc#roomconfig_roomdesc' },
|
|
59
|
+
xml('value', {}, roomDescription)
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
client.send(message);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const timeoutPromise = createTimeoutPromise(2000, unsubscribe);
|
|
69
|
+
|
|
70
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
71
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Same xmlns derivation as sendTextMessage — the server registers app
|
|
5
|
+
* messages under the WSS service URL (`wss://<host>/ws`), and stanzas
|
|
6
|
+
* carrying a bare hostname (or no xmlns at all) get silently dropped.
|
|
7
|
+
*/
|
|
8
|
+
const toServiceXmlns = (devServer: string | undefined, client: Client): string => {
|
|
9
|
+
const clientService = (client as any)?.options?.service as string | undefined;
|
|
10
|
+
if (clientService && /^wss?:\/\//.test(clientService)) {return clientService;}
|
|
11
|
+
const ds = (devServer || '').trim();
|
|
12
|
+
if (!ds) {return 'wss://xmpp.ethoradev.com/ws';}
|
|
13
|
+
if (/^wss?:\/\//.test(ds)) {return ds;}
|
|
14
|
+
if (ds.includes('://')) {return ds;}
|
|
15
|
+
return `wss://${ds.replace(/^\/+|\/+$/g, '')}/ws`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function sendMediaMessage(
|
|
19
|
+
client: Client,
|
|
20
|
+
roomJID: string,
|
|
21
|
+
data: any,
|
|
22
|
+
customId?: string,
|
|
23
|
+
devServer?: string
|
|
24
|
+
) {
|
|
25
|
+
const id =
|
|
26
|
+
customId || `send-media-message-${Date.now().toString()}`;
|
|
27
|
+
|
|
28
|
+
const dataToSend = {
|
|
29
|
+
xmlns: toServiceXmlns(devServer, client),
|
|
30
|
+
senderJID: client.jid?.toString(),
|
|
31
|
+
senderFirstName: data.firstName,
|
|
32
|
+
senderLastName: data.lastName,
|
|
33
|
+
senderWalletAddress: data.walletAddress,
|
|
34
|
+
isSystemMessage: false,
|
|
35
|
+
tokenAmount: '0',
|
|
36
|
+
receiverMessageId: '0',
|
|
37
|
+
mucname: data.chatName,
|
|
38
|
+
photoURL: data.userAvatar ? data.userAvatar : '',
|
|
39
|
+
isMediafile: true,
|
|
40
|
+
createdAt: data.createdAt,
|
|
41
|
+
expiresAt: data.expiresAt,
|
|
42
|
+
fileName: data.fileName,
|
|
43
|
+
isVisible: data.isVisible,
|
|
44
|
+
location: data.location,
|
|
45
|
+
locationPreview: data.locationPreview,
|
|
46
|
+
mimetype: data.mimetype,
|
|
47
|
+
originalName: data.originalName,
|
|
48
|
+
ownerKey: data.ownerKey,
|
|
49
|
+
size: data.size,
|
|
50
|
+
duration: data?.duration,
|
|
51
|
+
updatedAt: data.updatedAt,
|
|
52
|
+
userId: data.userId,
|
|
53
|
+
waveForm: data.waveForm,
|
|
54
|
+
attachmentId: data?.attachmentId,
|
|
55
|
+
isReply: data?.isReply,
|
|
56
|
+
showInChannel: data?.showInChannel,
|
|
57
|
+
mainMessage: data?.mainMessage,
|
|
58
|
+
roomJid: data?.roomJid,
|
|
59
|
+
push: 'true',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const message = xml(
|
|
63
|
+
'message',
|
|
64
|
+
{
|
|
65
|
+
id: id,
|
|
66
|
+
type: 'groupchat',
|
|
67
|
+
from: client.jid?.toString(),
|
|
68
|
+
to: roomJID,
|
|
69
|
+
},
|
|
70
|
+
xml('body', {}, 'media'),
|
|
71
|
+
xml('store', { xmlns: 'urn:xmpp:hints' }),
|
|
72
|
+
xml('data', dataToSend)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
console.log('🟢 [sendMediaMessage] sending stanza', {
|
|
76
|
+
id,
|
|
77
|
+
to: roomJID,
|
|
78
|
+
mime: data?.mimetype,
|
|
79
|
+
name: data?.fileName,
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const sendResult = client.send(message);
|
|
83
|
+
if (sendResult && typeof (sendResult as any).then === 'function') {
|
|
84
|
+
(sendResult as Promise<unknown>)
|
|
85
|
+
.then(() => console.log('🟢 [sendMediaMessage] client.send resolved', { id }))
|
|
86
|
+
.catch((err) =>
|
|
87
|
+
console.error('🔴 [sendMediaMessage] client.send REJECTED', {
|
|
88
|
+
id,
|
|
89
|
+
message: (err as any)?.message,
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('🔴 [sendMediaMessage] sync error', error);
|
|
95
|
+
}
|
|
96
|
+
return id;
|
|
97
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export function sendMessageReaction(
|
|
4
|
+
client: Client,
|
|
5
|
+
messageId: string,
|
|
6
|
+
roomJid: string,
|
|
7
|
+
reactionsList: string[],
|
|
8
|
+
data: any,
|
|
9
|
+
reactionSymbol?: any,
|
|
10
|
+
) {
|
|
11
|
+
const id = `message-reaction:${Date.now().toString()}`;
|
|
12
|
+
|
|
13
|
+
const dataReaction = {
|
|
14
|
+
senderFirstName: data.firstName,
|
|
15
|
+
senderLastName: data.lastName,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const message = xml(
|
|
19
|
+
'message',
|
|
20
|
+
{
|
|
21
|
+
id: id,
|
|
22
|
+
type: 'groupchat',
|
|
23
|
+
from: client.jid?.toString(),
|
|
24
|
+
to: roomJid,
|
|
25
|
+
},
|
|
26
|
+
xml(
|
|
27
|
+
'reactions',
|
|
28
|
+
{
|
|
29
|
+
id: messageId,
|
|
30
|
+
from: client.jid?.toString(),
|
|
31
|
+
xmlns: 'urn:xmpp:reactions:0',
|
|
32
|
+
},
|
|
33
|
+
...reactionsList.map((reaction) => xml('reaction', {}, reaction ?? ''))
|
|
34
|
+
// xml('reaction', {}, reactionSymbol ?? '👋'),
|
|
35
|
+
),
|
|
36
|
+
xml('data', dataReaction),
|
|
37
|
+
xml('store', { xmlns: 'urn:xmpp:hints' })
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
client.send(message);
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export function sendPing(client: any, to: string, id?: string) {
|
|
4
|
+
if (
|
|
5
|
+
client.status !== 'online' ||
|
|
6
|
+
client._status === 'closing' ||
|
|
7
|
+
client._status === 'closed'
|
|
8
|
+
) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const pingId =
|
|
13
|
+
id || 'ping-' + Date.now() + '-' + Math.floor(Math.random() * 10000);
|
|
14
|
+
const pingStanza = xml(
|
|
15
|
+
'iq',
|
|
16
|
+
{ type: 'get', to, id: pingId },
|
|
17
|
+
xml('ping', 'urn:xmpp:ping')
|
|
18
|
+
);
|
|
19
|
+
client.send(pingStanza);
|
|
20
|
+
return pingId;
|
|
21
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalize devServer to the WSS service URL that the server uses as
|
|
5
|
+
* the data-element xmlns. The user-facing `xmppDevServer` config
|
|
6
|
+
* typically holds a bare hostname (`xmpp.chat.ethora.com`); the server
|
|
7
|
+
* registers messages under the full `wss://<host>/ws` URL, and stanzas
|
|
8
|
+
* carrying just the bare host as xmlns get silently dropped.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors web's `SERVICE` derivation (utils/runtimeHostConfig.ts).
|
|
11
|
+
*/
|
|
12
|
+
const toServiceXmlns = (devServer: string | undefined, client: Client): string => {
|
|
13
|
+
// Prefer the URL the client is actually connected to — guaranteed to
|
|
14
|
+
// be the one the server expects.
|
|
15
|
+
const clientService = (client as any)?.options?.service as string | undefined;
|
|
16
|
+
if (clientService && /^wss?:\/\//.test(clientService)) {return clientService;}
|
|
17
|
+
const ds = (devServer || '').trim();
|
|
18
|
+
if (!ds) {return 'wss://xmpp.ethoradev.com/ws';}
|
|
19
|
+
if (/^wss?:\/\//.test(ds)) {return ds;}
|
|
20
|
+
if (ds.includes('://')) {return ds;}
|
|
21
|
+
// Bare host → wss://<host>/ws
|
|
22
|
+
return `wss://${ds.replace(/^\/+|\/+$/g, '')}/ws`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const sendTextMessage = (
|
|
26
|
+
client: Client,
|
|
27
|
+
roomJID: string,
|
|
28
|
+
firstName: string,
|
|
29
|
+
lastName: string,
|
|
30
|
+
photo: string,
|
|
31
|
+
walletAddress: string,
|
|
32
|
+
userMessage: string,
|
|
33
|
+
notDisplayedValue?: string,
|
|
34
|
+
isReply?: boolean,
|
|
35
|
+
showInChannel?: boolean,
|
|
36
|
+
mainMessage?: string,
|
|
37
|
+
devServer?: string,
|
|
38
|
+
customId?: string
|
|
39
|
+
) => {
|
|
40
|
+
const id = customId
|
|
41
|
+
? customId
|
|
42
|
+
: isReply
|
|
43
|
+
? `send-reply-message-${Date.now().toString()}`
|
|
44
|
+
: `send-text-message-${Date.now().toString()}`;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const message = xml(
|
|
48
|
+
'message',
|
|
49
|
+
{
|
|
50
|
+
to: roomJID,
|
|
51
|
+
type: 'groupchat',
|
|
52
|
+
id: id,
|
|
53
|
+
},
|
|
54
|
+
xml('data', {
|
|
55
|
+
xmlns: toServiceXmlns(devServer, client),
|
|
56
|
+
senderFirstName: firstName,
|
|
57
|
+
senderLastName: lastName,
|
|
58
|
+
fullName: `${firstName} ${lastName}`,
|
|
59
|
+
photoURL: photo,
|
|
60
|
+
senderJID: client.jid?.toString(),
|
|
61
|
+
senderWalletAddress: walletAddress,
|
|
62
|
+
roomJid: roomJID,
|
|
63
|
+
isSystemMessage: false,
|
|
64
|
+
tokenAmount: 0,
|
|
65
|
+
quickReplies: '',
|
|
66
|
+
notDisplayedValue: '',
|
|
67
|
+
showInChannel: showInChannel || false,
|
|
68
|
+
isReply: isReply || false,
|
|
69
|
+
mainMessage: mainMessage || '',
|
|
70
|
+
push: 'true',
|
|
71
|
+
}),
|
|
72
|
+
xml('body', {}, userMessage)
|
|
73
|
+
);
|
|
74
|
+
console.log('🟢 [sendTextMessage] sending stanza', {
|
|
75
|
+
id,
|
|
76
|
+
to: roomJID,
|
|
77
|
+
bodyLen: userMessage?.length,
|
|
78
|
+
clientJid: client.jid?.toString(),
|
|
79
|
+
xmlns: toServiceXmlns(devServer, client),
|
|
80
|
+
});
|
|
81
|
+
const sendResult = client.send(message);
|
|
82
|
+
if (sendResult && typeof (sendResult as any).then === 'function') {
|
|
83
|
+
(sendResult as Promise<unknown>)
|
|
84
|
+
.then(() => console.log('🟢 [sendTextMessage] client.send resolved', { id }))
|
|
85
|
+
.catch((err) =>
|
|
86
|
+
console.error('🔴 [sendTextMessage] client.send REJECTED', {
|
|
87
|
+
id,
|
|
88
|
+
message: (err as any)?.message,
|
|
89
|
+
name: (err as any)?.name,
|
|
90
|
+
stack: (err as any)?.stack,
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
} else {
|
|
94
|
+
console.log('🟡 [sendTextMessage] client.send returned non-promise', { id, type: typeof sendResult });
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('🔴 [sendTextMessage] sync error', error);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { Iso639_1Codes } from '../../types/types';
|
|
3
|
+
|
|
4
|
+
export const sendTextMessageWithTranslateTag = (
|
|
5
|
+
client: Client,
|
|
6
|
+
stanzaMessage: {
|
|
7
|
+
roomJID: string;
|
|
8
|
+
firstName: string;
|
|
9
|
+
lastName: string;
|
|
10
|
+
photo: string;
|
|
11
|
+
walletAddress: string;
|
|
12
|
+
userMessage: string;
|
|
13
|
+
notDisplayedValue?: string;
|
|
14
|
+
isReply?: boolean;
|
|
15
|
+
showInChannel?: boolean;
|
|
16
|
+
mainMessage?: string;
|
|
17
|
+
devServer?: string;
|
|
18
|
+
},
|
|
19
|
+
source: Iso639_1Codes,
|
|
20
|
+
customId?: string
|
|
21
|
+
) => {
|
|
22
|
+
const id = customId || `get-translate-messsage:${Date.now().toString()}`;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const message = xml(
|
|
26
|
+
'message',
|
|
27
|
+
{
|
|
28
|
+
to: stanzaMessage.roomJID,
|
|
29
|
+
type: 'groupchat',
|
|
30
|
+
id: id,
|
|
31
|
+
},
|
|
32
|
+
xml('data', {
|
|
33
|
+
...stanzaMessage,
|
|
34
|
+
push: 'true',
|
|
35
|
+
}),
|
|
36
|
+
xml('body', {}, stanzaMessage.userMessage),
|
|
37
|
+
xml('translate', { source: source })
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
client.send(message);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('An error occurred while sending message:', error);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
|
|
3
|
+
export function sendTypingRequest(
|
|
4
|
+
client: Client,
|
|
5
|
+
chatId: string,
|
|
6
|
+
fullName: string,
|
|
7
|
+
start: boolean
|
|
8
|
+
) {
|
|
9
|
+
let id = start ? `typing-${Date.now()}` : `stop-typing-${Date.now()}`;
|
|
10
|
+
const stanza = xml(
|
|
11
|
+
'message',
|
|
12
|
+
{
|
|
13
|
+
type: 'groupchat',
|
|
14
|
+
id: id,
|
|
15
|
+
to: chatId,
|
|
16
|
+
},
|
|
17
|
+
xml(start ? 'composing' : 'paused', {
|
|
18
|
+
xmlns: 'http://jabber.org/protocol/chatstates',
|
|
19
|
+
}),
|
|
20
|
+
xml('data', {
|
|
21
|
+
fullName: fullName,
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
client.send(stanza);
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Client, xml } from '@xmpp/client';
|
|
2
|
+
import { Element } from 'ltx';
|
|
3
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
4
|
+
|
|
5
|
+
export async function setChatsPrivateStoreRequest(
|
|
6
|
+
client: Client,
|
|
7
|
+
jsonObj: string
|
|
8
|
+
) {
|
|
9
|
+
const id = `set-chats-private-req:${Date.now().toString()}`;
|
|
10
|
+
let stanzaHdlrPointer: {
|
|
11
|
+
(el: Element): void;
|
|
12
|
+
(stanza: Element): void;
|
|
13
|
+
(el: Element): void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const unsubscribe = () => {
|
|
17
|
+
client?.off('stanza', stanzaHdlrPointer);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const responsePromise = new Promise((resolve, _reject) => {
|
|
21
|
+
stanzaHdlrPointer = (stanza: Element) => {
|
|
22
|
+
if (stanza.is('iq') && stanza.attrs.id === id) {
|
|
23
|
+
resolve(true);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
client?.on('stanza', stanzaHdlrPointer);
|
|
28
|
+
|
|
29
|
+
const message = xml(
|
|
30
|
+
'iq',
|
|
31
|
+
{
|
|
32
|
+
id: id,
|
|
33
|
+
type: 'set',
|
|
34
|
+
},
|
|
35
|
+
xml(
|
|
36
|
+
'query',
|
|
37
|
+
{ xmlns: 'jabber:iq:private' },
|
|
38
|
+
xml('chatjson', { xmlns: 'chatjson:store', value: jsonObj })
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
client?.send(message);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const timeoutPromise = createTimeoutPromise(2000, unsubscribe);
|
|
46
|
+
|
|
47
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
48
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Element } from 'ltx';
|
|
2
|
+
import { Client, xml } from '@xmpp/client';
|
|
3
|
+
import { createTimeoutPromise } from './createTimeoutPromise.xmpp';
|
|
4
|
+
|
|
5
|
+
export function setMeAsOwner(roomId: string, client: Client) {
|
|
6
|
+
const id = `set-me-as-owner:${Date.now().toString()}`;
|
|
7
|
+
|
|
8
|
+
let stanzaHdlrPointer: {
|
|
9
|
+
(el: Element): void;
|
|
10
|
+
(stanza: Element): void;
|
|
11
|
+
(el: Element): void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const unsubscribe = () => {
|
|
15
|
+
client.off('stanza', stanzaHdlrPointer);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const responsePromise = new Promise((resolve) => {
|
|
19
|
+
stanzaHdlrPointer = (stanza: Element) => {
|
|
20
|
+
if (
|
|
21
|
+
stanza.is('iq') &&
|
|
22
|
+
stanza.attrs.id === id &&
|
|
23
|
+
stanza.attrs.type === 'result'
|
|
24
|
+
) {
|
|
25
|
+
unsubscribe();
|
|
26
|
+
resolve(true);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
client.on('stanza', stanzaHdlrPointer);
|
|
31
|
+
|
|
32
|
+
const message = xml(
|
|
33
|
+
'iq',
|
|
34
|
+
{
|
|
35
|
+
to: roomId,
|
|
36
|
+
id: id,
|
|
37
|
+
type: 'set',
|
|
38
|
+
},
|
|
39
|
+
xml(
|
|
40
|
+
'query',
|
|
41
|
+
{ xmlns: 'http://jabber.org/protocol/muc#owner' },
|
|
42
|
+
xml('x', { xmlns: 'jabber:x:data', type: 'submit' })
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
client.send(message);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const timeoutPromise = createTimeoutPromise(2000, unsubscribe);
|
|
50
|
+
|
|
51
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
52
|
+
}
|