@pontalabs/baileys 1.0.11 → 1.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.
Files changed (119) hide show
  1. package/README.md +96 -85
  2. package/lib/Defaults/connection.js +39 -0
  3. package/lib/Defaults/constants.js +50 -0
  4. package/lib/Defaults/history.js +13 -0
  5. package/lib/Defaults/index.js +36 -151
  6. package/lib/Defaults/media.js +43 -0
  7. package/lib/Defaults/phonenumber-mcc.json +221 -221
  8. package/lib/Defaults/prefix.js +12 -0
  9. package/lib/Defaults/vialeys-version.json +7 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -15
  11. package/lib/Signal/Group/group-session-builder.js +34 -60
  12. package/lib/Signal/Group/group_cipher.js +69 -76
  13. package/lib/Signal/Group/index.js +41 -60
  14. package/lib/Signal/Group/keyhelper.js +12 -57
  15. package/lib/Signal/Group/sender-chain-key.js +20 -33
  16. package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
  17. package/lib/Signal/Group/sender-key-message.js +58 -53
  18. package/lib/Signal/Group/sender-key-name.js +21 -31
  19. package/lib/Signal/Group/sender-key-record.js +21 -34
  20. package/lib/Signal/Group/sender-key-state.js +59 -106
  21. package/lib/Signal/Group/sender-message-key.js +16 -21
  22. package/lib/Signal/libsignal.js +282 -203
  23. package/lib/Signal/lid-mapping.js +164 -184
  24. package/lib/Socket/Client/index.js +31 -22
  25. package/lib/Socket/Client/types.js +9 -15
  26. package/lib/Socket/Client/websocket.js +42 -37
  27. package/lib/Socket/business.js +212 -336
  28. package/lib/Socket/chats.js +696 -940
  29. package/lib/Socket/community.js +454 -369
  30. package/lib/Socket/groups.js +278 -280
  31. package/lib/Socket/index.js +9 -21
  32. package/lib/Socket/messages-recv.js +1027 -1570
  33. package/lib/Socket/messages-send.js +1180 -1136
  34. package/lib/Socket/mex.js +59 -0
  35. package/lib/Socket/newsletter.js +193 -251
  36. package/lib/Socket/socket.js +758 -898
  37. package/lib/Store/index.js +35 -24
  38. package/lib/Store/make-cache-manager-store.js +53 -66
  39. package/lib/Store/make-in-memory-store.js +319 -325
  40. package/lib/Store/make-ordered-dictionary.js +49 -57
  41. package/lib/Store/object-repository.js +10 -15
  42. package/lib/Types/Auth.js +2 -3
  43. package/lib/Types/Bussines.js +2 -3
  44. package/lib/Types/Call.js +2 -3
  45. package/lib/Types/Chat.js +10 -9
  46. package/lib/Types/Contact.js +2 -3
  47. package/lib/Types/Events.js +2 -3
  48. package/lib/Types/GroupMetadata.js +2 -3
  49. package/lib/Types/Label.js +6 -12
  50. package/lib/Types/LabelAssociation.js +4 -13
  51. package/lib/Types/Message.js +10 -18
  52. package/lib/Types/MexUpdates.js +15 -18
  53. package/lib/Types/Newsletter.js +26 -34
  54. package/lib/Types/Product.js +2 -3
  55. package/lib/Types/Signal.js +2 -3
  56. package/lib/Types/Socket.js +2 -3
  57. package/lib/Types/State.js +8 -13
  58. package/lib/Types/USync.js +2 -3
  59. package/lib/Types/index.js +49 -40
  60. package/lib/Utils/auth-utils.js +190 -495
  61. package/lib/Utils/browser-utils.js +29 -0
  62. package/lib/Utils/business.js +177 -199
  63. package/lib/Utils/chat-utils.js +711 -624
  64. package/lib/Utils/crypto.js +116 -161
  65. package/lib/Utils/decode-wa-message.js +225 -321
  66. package/lib/Utils/event-buffer.js +363 -405
  67. package/lib/Utils/generics.js +318 -472
  68. package/lib/Utils/history.js +72 -76
  69. package/lib/Utils/index.js +49 -41
  70. package/lib/Utils/link-preview.js +59 -103
  71. package/lib/Utils/logger.js +4 -7
  72. package/lib/Utils/lt-hash.js +29 -42
  73. package/lib/Utils/make-mutex.js +26 -42
  74. package/lib/Utils/message-retry-manager.js +134 -160
  75. package/lib/Utils/messages-media.js +665 -731
  76. package/lib/Utils/messages.js +518 -1
  77. package/lib/Utils/noise-handler.js +127 -125
  78. package/lib/Utils/pre-key-manager.js +86 -0
  79. package/lib/Utils/process-message.js +739 -351
  80. package/lib/Utils/signal.js +146 -129
  81. package/lib/Utils/use-multi-file-auth-state.js +68 -135
  82. package/lib/Utils/validate-connection.js +183 -142
  83. package/lib/Utils/vialeys-event-stream.js +41 -0
  84. package/lib/WABinary/constants.js +1281 -1289
  85. package/lib/WABinary/decode.js +145 -200
  86. package/lib/WABinary/encode.js +149 -202
  87. package/lib/WABinary/generic-utils.js +79 -97
  88. package/lib/WABinary/index.js +36 -25
  89. package/lib/WABinary/jid-utils.js +91 -123
  90. package/lib/WABinary/types.js +2 -3
  91. package/lib/WAM/BinaryInfo.js +8 -13
  92. package/lib/WAM/constants.js +16584 -11464
  93. package/lib/WAM/encode.js +117 -133
  94. package/lib/WAM/index.js +34 -23
  95. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
  96. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
  97. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
  98. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
  99. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
  101. package/lib/WAUSync/Protocols/index.js +37 -26
  102. package/lib/WAUSync/USyncQuery.js +66 -66
  103. package/lib/WAUSync/USyncUser.js +13 -18
  104. package/lib/WAUSync/index.js +34 -23
  105. package/lib/index.js +95 -28
  106. package/package.json +2 -1
  107. package/lib/Defaults/baileys-version.json +0 -3
  108. package/lib/Signal/Group/queue-job.d.ts +0 -1
  109. package/lib/Signal/Group/queue-job.js +0 -57
  110. package/lib/Socket/usync.d.ts +0 -37
  111. package/lib/Socket/usync.js +0 -83
  112. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  113. package/lib/Utils/baileys-event-stream.js +0 -70
  114. package/lib/Utils/signal-housekeeping.d.ts +0 -19
  115. package/lib/Utils/signal-housekeeping.js +0 -73
  116. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  117. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  118. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  119. package/lib/Utils/use-single-file-auth-state.js +0 -80
@@ -1,184 +1,164 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const lru_cache_1 = require("lru-cache")
6
- const WABinary_1 = require("../WABinary")
7
-
8
- class LIDMappingStore {
9
- constructor(keys, onWhatsAppFunc, logger) {
10
- this.mappingCache = new lru_cache_1.LRUCache({
11
- ttl: 7 * 24 * 60 * 60 * 1000, // 7 days
12
- ttlAutopurge: true,
13
- updateAgeOnGet: true
14
- })
15
- this.keys = keys
16
- this.logger = logger
17
- this.onWhatsAppFunc = onWhatsAppFunc // needed to get LID from PN if not found
18
- }
19
- /**
20
- * Store LID-PN mapping - USER LEVEL
21
- */
22
- async storeLIDPNMappings(pairs) {
23
- // Validate inputs
24
- const pairMap = {}
25
- const logger = this.logger
26
-
27
- for (const { lid, pn } of pairs) {
28
- if (!((WABinary_1.isLidUser(lid) && WABinary_1.isJidUser(pn)) || (WABinary_1.isJidUser(lid) && WABinary_1.isLidUser(pn)))) {
29
- logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`)
30
- continue
31
- }
32
-
33
- const [lidJid, pnJid] = WABinary_1.isLidUser(lid) ? [lid, pn] : [pn, lid]
34
- const lidDecoded = WABinary_1.jidDecode(lidJid)
35
- const pnDecoded = WABinary_1.jidDecode(pnJid)
36
-
37
- if (!lidDecoded || !pnDecoded) return
38
-
39
- const pnUser = pnDecoded.user
40
- const lidUser = lidDecoded.user
41
-
42
- // Check if mapping already exists (cache first, then database)
43
- let existingLidUser = this.mappingCache.get(`pn:${pnUser}`)
44
-
45
- if (!existingLidUser) {
46
- // Cache miss - check database
47
- const stored = await this.keys.get('lid-mapping', [pnUser])
48
-
49
- existingLidUser = stored[pnUser]
50
-
51
- if (existingLidUser) {
52
- // Update cache with database value
53
- this.mappingCache.set(`pn:${pnUser}`, existingLidUser)
54
- this.mappingCache.set(`lid:${existingLidUser}`, pnUser)
55
- }
56
- }
57
-
58
- if (existingLidUser === lidUser) {
59
- logger.debug({ pnUser, lidUser }, 'LID mapping already exists, skipping')
60
- continue
61
- }
62
-
63
- pairMap[pnUser] = lidUser
64
- }
65
-
66
- logger.trace({ pairMap }, `Storing ${Object.keys(pairMap).length} pn mappings`)
67
-
68
- await this.keys.transaction(async () => {
69
- for (const [pnUser, lidUser] of Object.entries(pairMap)) {
70
- await this.keys.set({
71
- 'lid-mapping': {
72
- [pnUser]: lidUser, // "554396160286" -> "102765716062358"
73
- [`${lidUser}_reverse`]: pnUser // "102765716062358_reverse" -> "554396160286"
74
- }
75
- })
76
-
77
- // Update cache with both directions
78
- this.mappingCache.set(`pn:${pnUser}`, lidUser)
79
- this.mappingCache.set(`lid:${lidUser}`, pnUser)
80
- }
81
- }, 'lid-mapping')
82
- }
83
- /**
84
- * Get LID for PN - Returns device-specific LID based on user mapping
85
- */
86
- async getLIDForPN(pn) {
87
- if (!WABinary_1.isJidUser(pn)) return null
88
-
89
- const logger = this.logger
90
- const decoded = WABinary_1.jidDecode(pn)
91
-
92
- if (!decoded) return null
93
-
94
- // Check cache first for PN → LID mapping
95
- const pnUser = decoded.user
96
-
97
- let lidUser = this.mappingCache.get(`pn:${pnUser}`)
98
-
99
- if (!lidUser) {
100
- // Cache miss - check database
101
- const stored = await this.keys.get('lid-mapping', [pnUser])
102
-
103
- lidUser = stored[pnUser]
104
-
105
- if (lidUser) {
106
- // Cache the database result
107
- this.mappingCache.set(`pn:${pnUser}`, lidUser)
108
- }
109
-
110
- else {
111
- // Not in database - try USync
112
- logger.trace(`No LID mapping found for PN user ${pnUser}; getting from USync`)
113
-
114
- const { exists, lid } = (await this.onWhatsAppFunc?.(pn))?.[0] // this function already adds LIDs to mapping
115
-
116
- if (exists && lid) {
117
- lidUser = WABinary_1.jidDecode(lid)?.user
118
-
119
- if (lidUser) {
120
- // Cache the USync result
121
- this.mappingCache.set(`pn:${pnUser}`, lidUser)
122
- }
123
- }
124
-
125
- else {
126
- return null
127
- }
128
- }
129
- }
130
-
131
- if (typeof lidUser !== 'string' || !lidUser) {
132
- logger.warn(`Invalid or empty LID user for PN ${pn}: lidUser = "${lidUser}"`)
133
- return null
134
- }
135
-
136
- // Push the PN device ID to the LID to maintain device separation
137
- const pnDevice = decoded.device !== undefined ? decoded.device : 0
138
- const deviceSpecificLid = `${lidUser}:${pnDevice}@lid`
139
-
140
- logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`)
141
-
142
- return deviceSpecificLid
143
- }
144
- /**
145
- * Get PN for LID - USER LEVEL with device construction
146
- */
147
- async getPNForLID(lid) {
148
- if (!WABinary_1.isLidUser(lid)) return null
149
-
150
- const logger = this.logger
151
- const decoded = WABinary_1.jidDecode(lid)
152
-
153
- if (!decoded) return null
154
-
155
- // Check cache first for LID → PN mapping
156
- const lidUser = decoded.user
157
-
158
- let pnUser = this.mappingCache.get(`lid:${lidUser}`)
159
-
160
- if (!pnUser || typeof pnUser !== 'string') {
161
- // Cache miss - check database
162
- const stored = await this.keys.get('lid-mapping', [`${lidUser}_reverse`]);
163
- pnUser = stored[`${lidUser}_reverse`]
164
-
165
- if (!pnUser || typeof pnUser !== 'string') {
166
- logger.trace(`No reverse mapping found for LID user: ${lidUser}`)
167
- return null
168
- }
169
-
170
- this.mappingCache.set(`lid:${lidUser}`, pnUser)
171
- }
172
-
173
- // Construct device-specific PN JID
174
- const lidDevice = decoded.device !== undefined ? decoded.device : 0
175
- const pnJid = `${pnUser}:${lidDevice}@s.whatsapp.net`
176
- logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`)
177
-
178
- return pnJid
179
- }
180
- }
181
-
182
- module.exports = {
183
- LIDMappingStore
184
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { LRUCache: LRUCache } = require("lru-cache");
4
+ const {
5
+ isHostedPnUser: isHostedPnUser,
6
+ isLidUser: isLidUser,
7
+ isPnUser: isPnUser,
8
+ jidDecode: jidDecode,
9
+ jidNormalizedUser: jidNormalizedUser,
10
+ WAJIDDomains: WAJIDDomains,
11
+ } = require("../WABinary");
12
+ class LIDMappingStore {
13
+ constructor(keys, logger, pnToLIDFunc) {
14
+ this.mappingCache = new LRUCache({
15
+ ttl: 3 * 24 * 60 * 60 * 1e3,
16
+ ttlAutopurge: true,
17
+ updateAgeOnGet: true,
18
+ });
19
+ this.keys = keys;
20
+ this.pnToLIDFunc = pnToLIDFunc;
21
+ this.logger = logger;
22
+ }
23
+ async storeLIDPNMappings(pairs) {
24
+ const pairMap = {};
25
+ for (const { lid: lid, pn: pn } of pairs) {
26
+ if (!((isLidUser(lid) && isPnUser(pn)) || (isPnUser(lid) && isLidUser(pn)))) {
27
+ this.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
28
+ continue;
29
+ }
30
+ const lidDecoded = jidDecode(lid);
31
+ const pnDecoded = jidDecode(pn);
32
+ if (!lidDecoded || !pnDecoded) return;
33
+ const pnUser = pnDecoded.user;
34
+ const lidUser = lidDecoded.user;
35
+ let existingLidUser = this.mappingCache.get(`pn:${pnUser}`);
36
+ if (!existingLidUser) {
37
+ this.logger.trace(`Cache miss for PN user ${pnUser}; checking database`);
38
+ const stored = await this.keys.get("lid-mapping", [pnUser]);
39
+ existingLidUser = stored[pnUser];
40
+ if (existingLidUser) {
41
+ this.mappingCache.set(`pn:${pnUser}`, existingLidUser);
42
+ this.mappingCache.set(`lid:${existingLidUser}`, pnUser);
43
+ }
44
+ }
45
+ if (existingLidUser === lidUser) {
46
+ this.logger.debug(
47
+ { pnUser: pnUser, lidUser: lidUser },
48
+ "LID mapping already exists, skipping"
49
+ );
50
+ continue;
51
+ }
52
+ pairMap[pnUser] = lidUser;
53
+ }
54
+ this.logger.trace(
55
+ { pairMap: pairMap },
56
+ `Storing ${Object.keys(pairMap).length} pn mappings`
57
+ );
58
+ await this.keys.transaction(async () => {
59
+ for (const [pnUser, lidUser] of Object.entries(pairMap)) {
60
+ await this.keys.set({
61
+ "lid-mapping": { [pnUser]: lidUser, [`${lidUser}_reverse`]: pnUser },
62
+ });
63
+ this.mappingCache.set(`pn:${pnUser}`, lidUser);
64
+ this.mappingCache.set(`lid:${lidUser}`, pnUser);
65
+ }
66
+ }, "lid-mapping");
67
+ }
68
+ async getLIDForPN(pn) {
69
+ return (await this.getLIDsForPNs([pn]))?.[0]?.lid || null;
70
+ }
71
+ async getLIDsForPNs(pns) {
72
+ const usyncFetch = {};
73
+ const successfulPairs = {};
74
+ for (const pn of pns) {
75
+ if (!isPnUser(pn) && !isHostedPnUser(pn)) continue;
76
+ const decoded = jidDecode(pn);
77
+ if (!decoded) continue;
78
+ const pnUser = decoded.user;
79
+ let lidUser = this.mappingCache.get(`pn:${pnUser}`);
80
+ if (!lidUser) {
81
+ const stored = await this.keys.get("lid-mapping", [pnUser]);
82
+ lidUser = stored[pnUser];
83
+ if (lidUser) {
84
+ this.mappingCache.set(`pn:${pnUser}`, lidUser);
85
+ this.mappingCache.set(`lid:${lidUser}`, pnUser);
86
+ } else {
87
+ this.logger.trace(
88
+ `No LID mapping found for PN user ${pnUser}; batch getting from USync`
89
+ );
90
+ const device = decoded.device || 0;
91
+ let normalizedPn = jidNormalizedUser(pn);
92
+ if (isHostedPnUser(normalizedPn)) {
93
+ normalizedPn = `${pnUser}@s.whatsapp.net`;
94
+ }
95
+ if (!usyncFetch[normalizedPn]) {
96
+ usyncFetch[normalizedPn] = [device];
97
+ } else {
98
+ usyncFetch[normalizedPn]?.push(device);
99
+ }
100
+ continue;
101
+ }
102
+ }
103
+ lidUser = lidUser.toString();
104
+ if (!lidUser) {
105
+ this.logger.warn(`Invalid or empty LID user for PN ${pn}: lidUser = "${lidUser}"`);
106
+ return null;
107
+ }
108
+ const pnDevice = decoded.device !== undefined ? decoded.device : 0;
109
+ const deviceSpecificLid = `${lidUser}${!!pnDevice ? `:${pnDevice}` : ``}@${decoded.server === "hosted" ? "hosted.lid" : "lid"}`;
110
+ this.logger.trace(
111
+ `getLIDForPN: ${pn} ${deviceSpecificLid} (user mapping with device ${pnDevice})`
112
+ );
113
+ successfulPairs[pn] = { lid: deviceSpecificLid, pn: pn };
114
+ }
115
+ if (Object.keys(usyncFetch).length > 0) {
116
+ const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch));
117
+ if (result && result.length > 0) {
118
+ await this.storeLIDPNMappings(result);
119
+ for (const pair of result) {
120
+ const pnDecoded = jidDecode(pair.pn);
121
+ const pnUser = pnDecoded?.user;
122
+ if (!pnUser) continue;
123
+ const lidUser = jidDecode(pair.lid)?.user;
124
+ if (!lidUser) continue;
125
+ for (const device of usyncFetch[pair.pn]) {
126
+ const deviceSpecificLid = `${lidUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted.lid" : "lid"}`;
127
+ this.logger.trace(
128
+ `getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`
129
+ );
130
+ const deviceSpecificPn = `${pnUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted" : "s.whatsapp.net"}`;
131
+ successfulPairs[deviceSpecificPn] = {
132
+ lid: deviceSpecificLid,
133
+ pn: deviceSpecificPn,
134
+ };
135
+ }
136
+ }
137
+ } else {
138
+ return null;
139
+ }
140
+ }
141
+ return Object.values(successfulPairs);
142
+ }
143
+ async getPNForLID(lid) {
144
+ if (!isLidUser(lid)) return null;
145
+ const decoded = jidDecode(lid);
146
+ if (!decoded) return null;
147
+ const lidUser = decoded.user;
148
+ let pnUser = this.mappingCache.get(`lid:${lidUser}`);
149
+ if (!pnUser || typeof pnUser !== "string") {
150
+ const stored = await this.keys.get("lid-mapping", [`${lidUser}_reverse`]);
151
+ pnUser = stored[`${lidUser}_reverse`];
152
+ if (!pnUser || typeof pnUser !== "string") {
153
+ this.logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
154
+ return null;
155
+ }
156
+ this.mappingCache.set(`lid:${lidUser}`, pnUser);
157
+ }
158
+ const lidDevice = decoded.device !== undefined ? decoded.device : 0;
159
+ const pnJid = `${pnUser}:${lidDevice}@${decoded.domainType === WAJIDDomains.HOSTED_LID ? "hosted" : "s.whatsapp.net"}`;
160
+ this.logger.trace(`Found reverse mapping: ${lid} ${pnJid}`);
161
+ return pnJid;
162
+ }
163
+ }
164
+ module.exports = { LIDMappingStore: LIDMappingStore };
@@ -1,22 +1,31 @@
1
- "use strict"
2
-
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
8
- }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
-
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
- }
18
-
19
- Object.defineProperty(exports, "__esModule", { value: true })
20
-
21
- __exportStar(require("./types"), exports)
22
- __exportStar(require("./websocket"), exports)
1
+ "use strict";
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ var __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m)
26
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
27
+ __createBinding(exports, m, p);
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ __exportStar(require("./types"), exports);
31
+ __exportStar(require("./websocket"), exports);
@@ -1,18 +1,12 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const events_1 = require("events")
6
-
7
- class AbstractSocketClient extends events_1.EventEmitter {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { EventEmitter: EventEmitter } = require("events");
4
+ class AbstractSocketClient extends EventEmitter {
8
5
  constructor(url, config) {
9
- super()
10
- this.url = url
11
- this.config = config
12
- this.setMaxListeners(0)
6
+ super();
7
+ this.url = url;
8
+ this.config = config;
9
+ this.setMaxListeners(0);
13
10
  }
14
11
  }
15
-
16
- module.exports = {
17
- AbstractSocketClient
18
- }
12
+ module.exports = { AbstractSocketClient: AbstractSocketClient };
@@ -1,62 +1,67 @@
1
- "use strict"
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
-
9
- const ws_1 = __importDefault(require("ws"))
10
- const Defaults_1 = require("../../Defaults")
11
- const types_1 = require("./types")
12
-
13
- class WebSocketClient extends types_1.AbstractSocketClient {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ OPEN: OPEN,
5
+ CLOSED: CLOSED,
6
+ CLOSING: CLOSING,
7
+ CONNECTING: CONNECTING,
8
+ WebSocket: WebSocket,
9
+ } = require("ws");
10
+ const { DEFAULT_ORIGIN: DEFAULT_ORIGIN } = require("../../Defaults/constants");
11
+ const { AbstractSocketClient: AbstractSocketClient } = require("./types");
12
+ class WebSocketClient extends AbstractSocketClient {
14
13
  constructor() {
15
- super(...arguments)
16
- this.socket = null
14
+ super(...arguments);
15
+ this.socket = null;
17
16
  }
18
17
  get isOpen() {
19
- return this.socket?.readyState === ws_1.default.OPEN
18
+ return this.socket?.readyState === OPEN;
20
19
  }
21
20
  get isClosed() {
22
- return this.socket?.readyState === ws_1.default.CLOSED
21
+ return this.socket?.readyState === CLOSED;
23
22
  }
24
23
  get isClosing() {
25
- this.socket?.readyState === ws_1.default.CLOSING
24
+ this.socket?.readyState === CLOSING;
26
25
  }
27
26
  get isConnecting() {
28
- this.socket?.readyState === ws_1.default.CONNECTING
27
+ this.socket?.readyState === CONNECTING;
29
28
  }
30
- async connect() {
29
+ connect() {
31
30
  if (this.socket) {
32
- return
31
+ return;
33
32
  }
34
- this.socket = new ws_1.default(this.url, {
35
- origin: Defaults_1.DEFAULT_ORIGIN,
33
+ this.socket = new WebSocket(this.url, {
34
+ origin: DEFAULT_ORIGIN,
36
35
  headers: this.config.options?.headers,
37
36
  handshakeTimeout: this.config.connectTimeoutMs,
38
37
  timeout: this.config.connectTimeoutMs,
39
38
  agent: this.config.agent,
40
- })
41
- this.socket.setMaxListeners(0)
42
- const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response']
39
+ });
40
+ this.socket.setMaxListeners(0);
41
+ const events = [
42
+ "close",
43
+ "error",
44
+ "upgrade",
45
+ "message",
46
+ "open",
47
+ "ping",
48
+ "pong",
49
+ "unexpected-response",
50
+ ];
43
51
  for (const event of events) {
44
- this.socket?.on(event, (...args) => this.emit(event, ...args))
52
+ this.socket?.on(event, (...args) => this.emit(event, ...args));
45
53
  }
46
54
  }
47
- async close() {
55
+ close() {
48
56
  if (!this.socket) {
49
- return
57
+ return;
50
58
  }
51
- this.socket.close()
52
- this.socket = null
59
+ this.socket.close();
60
+ this.socket = null;
53
61
  }
54
62
  send(str, cb) {
55
- this.socket?.send(str, cb)
56
- return Boolean(this.socket)
63
+ this.socket?.send(str, cb);
64
+ return Boolean(this.socket);
57
65
  }
58
66
  }
59
-
60
- module.exports = {
61
- WebSocketClient
62
- }
67
+ module.exports = { WebSocketClient: WebSocketClient };