alipclutch-baileys 8.5.4 → 8.5.6
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/WAProto/index.js +56887 -17535
- 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 +65 -34
- package/lib/Utils/generics.js +11 -9
- package/lib/Utils/messages.js +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +45 -6
- 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
|
@@ -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;
|