@periskope/baileys 6.7.15-alpha.6 → 6.7.16-alpha.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.
Files changed (149) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +35 -1267
  3. package/WAProto/WAProto.proto +1299 -286
  4. package/WAProto/index.d.ts +16106 -2739
  5. package/WAProto/index.js +128593 -73944
  6. package/engine-requirements.js +10 -0
  7. package/lib/Defaults/baileys-version.json +3 -3
  8. package/lib/Defaults/index.d.ts +51 -53
  9. package/lib/Defaults/index.js +106 -107
  10. package/lib/Signal/libsignal.d.ts +3 -3
  11. package/lib/Signal/libsignal.js +161 -152
  12. package/lib/Socket/Client/index.d.ts +2 -2
  13. package/lib/Socket/Client/index.js +18 -18
  14. package/lib/Socket/Client/types.d.ts +15 -17
  15. package/lib/Socket/Client/types.js +13 -13
  16. package/lib/Socket/Client/websocket.d.ts +12 -12
  17. package/lib/Socket/Client/websocket.js +62 -62
  18. package/lib/Socket/business.d.ts +145 -149
  19. package/lib/Socket/business.js +260 -260
  20. package/lib/Socket/chats.d.ts +84 -85
  21. package/lib/Socket/chats.js +879 -850
  22. package/lib/Socket/groups.d.ts +123 -124
  23. package/lib/Socket/groups.js +314 -314
  24. package/lib/Socket/index.d.ts +145 -149
  25. package/lib/Socket/index.js +10 -10
  26. package/lib/Socket/messages-recv.d.ts +134 -136
  27. package/lib/Socket/messages-recv.js +925 -917
  28. package/lib/Socket/messages-send.d.ts +129 -130
  29. package/lib/Socket/messages-send.js +683 -673
  30. package/lib/Socket/socket.d.ts +43 -45
  31. package/lib/Socket/socket.js +622 -622
  32. package/lib/Socket/usync.d.ts +36 -38
  33. package/lib/Socket/usync.js +70 -70
  34. package/lib/Types/Auth.d.ts +103 -105
  35. package/lib/Types/Auth.js +2 -2
  36. package/lib/Types/Call.d.ts +13 -13
  37. package/lib/Types/Call.js +2 -2
  38. package/lib/Types/Chat.d.ts +112 -108
  39. package/lib/Types/Chat.js +4 -4
  40. package/lib/Types/Contact.d.ts +19 -19
  41. package/lib/Types/Contact.js +2 -2
  42. package/lib/Types/Events.d.ts +175 -175
  43. package/lib/Types/Events.js +2 -2
  44. package/lib/Types/GroupMetadata.d.ts +56 -56
  45. package/lib/Types/GroupMetadata.js +2 -2
  46. package/lib/Types/Label.d.ts +46 -46
  47. package/lib/Types/Label.js +27 -27
  48. package/lib/Types/LabelAssociation.d.ts +29 -29
  49. package/lib/Types/LabelAssociation.js +9 -9
  50. package/lib/Types/Message.d.ts +267 -271
  51. package/lib/Types/Message.js +9 -9
  52. package/lib/Types/Product.d.ts +78 -78
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.d.ts +57 -57
  55. package/lib/Types/Signal.js +2 -2
  56. package/lib/Types/Socket.d.ts +121 -118
  57. package/lib/Types/Socket.js +2 -2
  58. package/lib/Types/State.d.ts +27 -27
  59. package/lib/Types/State.js +2 -2
  60. package/lib/Types/USync.d.ts +25 -25
  61. package/lib/Types/USync.js +2 -2
  62. package/lib/Types/index.d.ts +63 -63
  63. package/lib/Types/index.js +41 -41
  64. package/lib/Utils/auth-utils.d.ts +18 -18
  65. package/lib/Utils/auth-utils.js +200 -200
  66. package/lib/Utils/baileys-event-stream.d.ts +16 -16
  67. package/lib/Utils/baileys-event-stream.js +63 -63
  68. package/lib/Utils/business.d.ts +22 -22
  69. package/lib/Utils/business.js +234 -234
  70. package/lib/Utils/chat-utils.d.ts +70 -72
  71. package/lib/Utils/chat-utils.js +745 -745
  72. package/lib/Utils/crypto.d.ts +40 -42
  73. package/lib/Utils/crypto.js +193 -181
  74. package/lib/Utils/decode-wa-message.d.ts +36 -36
  75. package/lib/Utils/decode-wa-message.js +205 -205
  76. package/lib/Utils/event-buffer.d.ts +35 -35
  77. package/lib/Utils/event-buffer.js +520 -520
  78. package/lib/Utils/generics.d.ts +90 -94
  79. package/lib/Utils/generics.js +398 -433
  80. package/lib/Utils/history.d.ts +19 -19
  81. package/lib/Utils/history.js +94 -94
  82. package/lib/Utils/index.d.ts +17 -17
  83. package/lib/Utils/index.js +33 -33
  84. package/lib/Utils/link-preview.d.ts +21 -21
  85. package/lib/Utils/link-preview.js +129 -119
  86. package/lib/Utils/logger.d.ts +11 -11
  87. package/lib/Utils/logger.js +7 -7
  88. package/lib/Utils/lt-hash.d.ts +12 -12
  89. package/lib/Utils/lt-hash.js +51 -51
  90. package/lib/Utils/make-mutex.d.ts +7 -7
  91. package/lib/Utils/make-mutex.js +44 -44
  92. package/lib/Utils/messages-media.d.ts +105 -109
  93. package/lib/Utils/messages-media.js +704 -694
  94. package/lib/Utils/messages.d.ts +75 -78
  95. package/lib/Utils/messages.js +761 -762
  96. package/lib/Utils/noise-handler.d.ts +19 -21
  97. package/lib/Utils/noise-handler.js +150 -150
  98. package/lib/Utils/process-message.d.ts +41 -42
  99. package/lib/Utils/process-message.js +385 -376
  100. package/lib/Utils/signal.d.ts +33 -33
  101. package/lib/Utils/signal.js +153 -153
  102. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -12
  103. package/lib/Utils/use-multi-file-auth-state.js +125 -94
  104. package/lib/Utils/validate-connection.d.ts +10 -10
  105. package/lib/Utils/validate-connection.js +175 -175
  106. package/lib/WABinary/constants.d.ts +27 -27
  107. package/lib/WABinary/constants.js +40 -40
  108. package/lib/WABinary/decode.d.ts +6 -8
  109. package/lib/WABinary/decode.js +264 -254
  110. package/lib/WABinary/encode.d.ts +2 -4
  111. package/lib/WABinary/encode.js +244 -234
  112. package/lib/WABinary/generic-utils.d.ts +14 -16
  113. package/lib/WABinary/generic-utils.js +110 -110
  114. package/lib/WABinary/index.d.ts +5 -5
  115. package/lib/WABinary/index.js +21 -21
  116. package/lib/WABinary/jid-utils.d.ts +33 -31
  117. package/lib/WABinary/jid-utils.js +66 -62
  118. package/lib/WABinary/types.d.ts +18 -18
  119. package/lib/WABinary/types.js +2 -2
  120. package/lib/WAM/BinaryInfo.d.ts +8 -18
  121. package/lib/WAM/BinaryInfo.js +13 -13
  122. package/lib/WAM/constants.d.ts +39 -39
  123. package/lib/WAM/constants.js +15350 -15350
  124. package/lib/WAM/encode.d.ts +2 -4
  125. package/lib/WAM/encode.js +155 -155
  126. package/lib/WAM/index.d.ts +3 -3
  127. package/lib/WAM/index.js +19 -19
  128. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  129. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -32
  130. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -22
  131. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -57
  132. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -12
  133. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -30
  134. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -12
  135. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -42
  136. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  137. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  138. package/lib/WAUSync/Protocols/index.d.ts +4 -4
  139. package/lib/WAUSync/Protocols/index.js +20 -20
  140. package/lib/WAUSync/USyncQuery.d.ts +26 -26
  141. package/lib/WAUSync/USyncQuery.js +79 -79
  142. package/lib/WAUSync/USyncUser.d.ts +12 -10
  143. package/lib/WAUSync/USyncUser.js +26 -22
  144. package/lib/WAUSync/index.d.ts +3 -3
  145. package/lib/WAUSync/index.js +19 -19
  146. package/lib/index.d.ts +11 -12
  147. package/lib/index.js +30 -31
  148. package/package.json +20 -26
  149. package/WAProto/GenerateStatics.sh +0 -4
@@ -1,152 +1,161 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeLibSignalRepository = void 0;
27
- const libsignal = __importStar(require("libsignal"));
28
- const WASignalGroup_1 = require("../../WASignalGroup");
29
- const Utils_1 = require("../Utils");
30
- const WABinary_1 = require("../WABinary");
31
- function makeLibSignalRepository(auth) {
32
- const storage = signalStorage(auth);
33
- return {
34
- decryptGroupMessage({ group, authorJid, msg }) {
35
- const senderName = jidToSignalSenderKeyName(group, authorJid);
36
- const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
37
- return cipher.decrypt(msg);
38
- },
39
- async processSenderKeyDistributionMessage({ item, authorJid }) {
40
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
41
- const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
42
- const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
43
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
44
- if (!senderKey) {
45
- await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
46
- }
47
- await builder.process(senderName, senderMsg);
48
- },
49
- async decryptMessage({ jid, type, ciphertext }) {
50
- const addr = jidToSignalProtocolAddress(jid);
51
- const session = new libsignal.SessionCipher(storage, addr);
52
- let result;
53
- switch (type) {
54
- case 'pkmsg':
55
- result = await session.decryptPreKeyWhisperMessage(ciphertext);
56
- break;
57
- case 'msg':
58
- result = await session.decryptWhisperMessage(ciphertext);
59
- break;
60
- }
61
- return result;
62
- },
63
- async encryptMessage({ jid, data }) {
64
- const addr = jidToSignalProtocolAddress(jid);
65
- const cipher = new libsignal.SessionCipher(storage, addr);
66
- const { type: sigType, body } = await cipher.encrypt(data);
67
- const type = sigType === 3 ? 'pkmsg' : 'msg';
68
- return { type, ciphertext: Buffer.from(body, 'binary') };
69
- },
70
- async encryptGroupMessage({ group, meId, data }) {
71
- const senderName = jidToSignalSenderKeyName(group, meId);
72
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
73
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
74
- if (!senderKey) {
75
- await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
76
- }
77
- const senderKeyDistributionMessage = await builder.create(senderName);
78
- const session = new WASignalGroup_1.GroupCipher(storage, senderName);
79
- const ciphertext = await session.encrypt(data);
80
- return {
81
- ciphertext,
82
- senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
83
- };
84
- },
85
- async injectE2ESession({ jid, session }) {
86
- const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
87
- await cipher.initOutgoing(session);
88
- },
89
- jidToSignalProtocolAddress(jid) {
90
- return jidToSignalProtocolAddress(jid).toString();
91
- },
92
- };
93
- }
94
- exports.makeLibSignalRepository = makeLibSignalRepository;
95
- const jidToSignalProtocolAddress = (jid) => {
96
- const { user, device } = (0, WABinary_1.jidDecode)(jid);
97
- return new libsignal.ProtocolAddress(user, device || 0);
98
- };
99
- const jidToSignalSenderKeyName = (group, user) => {
100
- return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
101
- };
102
- function signalStorage({ creds, keys }) {
103
- return {
104
- loadSession: async (id) => {
105
- const { [id]: sess } = await keys.get('session', [id]);
106
- if (sess) {
107
- return libsignal.SessionRecord.deserialize(sess);
108
- }
109
- },
110
- storeSession: async (id, session) => {
111
- await keys.set({ 'session': { [id]: session.serialize() } });
112
- },
113
- isTrustedIdentity: () => {
114
- return true;
115
- },
116
- loadPreKey: async (id) => {
117
- const keyId = id.toString();
118
- const { [keyId]: key } = await keys.get('pre-key', [keyId]);
119
- if (key) {
120
- return {
121
- privKey: Buffer.from(key.private),
122
- pubKey: Buffer.from(key.public)
123
- };
124
- }
125
- },
126
- removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
127
- loadSignedPreKey: () => {
128
- const key = creds.signedPreKey;
129
- return {
130
- privKey: Buffer.from(key.keyPair.private),
131
- pubKey: Buffer.from(key.keyPair.public)
132
- };
133
- },
134
- loadSenderKey: async (keyId) => {
135
- const { [keyId]: key } = await keys.get('sender-key', [keyId]);
136
- if (key) {
137
- return new WASignalGroup_1.SenderKeyRecord(key);
138
- }
139
- },
140
- storeSenderKey: async (keyId, key) => {
141
- await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
142
- },
143
- getOurRegistrationId: () => (creds.registrationId),
144
- getOurIdentity: () => {
145
- const { signedIdentityKey } = creds;
146
- return {
147
- privKey: Buffer.from(signedIdentityKey.private),
148
- pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
149
- };
150
- }
151
- };
152
- }
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.makeLibSignalRepository = makeLibSignalRepository;
37
+ const libsignal = __importStar(require("libsignal"));
38
+ const WASignalGroup_1 = require("../../WASignalGroup");
39
+ const Utils_1 = require("../Utils");
40
+ const WABinary_1 = require("../WABinary");
41
+ function makeLibSignalRepository(auth) {
42
+ const storage = signalStorage(auth);
43
+ return {
44
+ decryptGroupMessage({ group, authorJid, msg }) {
45
+ const senderName = jidToSignalSenderKeyName(group, authorJid);
46
+ const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
47
+ return cipher.decrypt(msg);
48
+ },
49
+ async processSenderKeyDistributionMessage({ item, authorJid }) {
50
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
51
+ const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
52
+ const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
53
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
54
+ if (!senderKey) {
55
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
56
+ }
57
+ await builder.process(senderName, senderMsg);
58
+ },
59
+ async decryptMessage({ jid, type, ciphertext }) {
60
+ const addr = jidToSignalProtocolAddress(jid);
61
+ const session = new libsignal.SessionCipher(storage, addr);
62
+ let result;
63
+ switch (type) {
64
+ case 'pkmsg':
65
+ result = await session.decryptPreKeyWhisperMessage(ciphertext);
66
+ break;
67
+ case 'msg':
68
+ result = await session.decryptWhisperMessage(ciphertext);
69
+ break;
70
+ }
71
+ return result;
72
+ },
73
+ async encryptMessage({ jid, data }) {
74
+ const addr = jidToSignalProtocolAddress(jid);
75
+ const cipher = new libsignal.SessionCipher(storage, addr);
76
+ const { type: sigType, body } = await cipher.encrypt(data);
77
+ const type = sigType === 3 ? 'pkmsg' : 'msg';
78
+ return { type, ciphertext: Buffer.from(body, 'binary') };
79
+ },
80
+ async encryptGroupMessage({ group, meId, data }) {
81
+ const senderName = jidToSignalSenderKeyName(group, meId);
82
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
83
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
84
+ if (!senderKey) {
85
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
86
+ }
87
+ const senderKeyDistributionMessage = await builder.create(senderName);
88
+ const session = new WASignalGroup_1.GroupCipher(storage, senderName);
89
+ const ciphertext = await session.encrypt(data);
90
+ return {
91
+ ciphertext,
92
+ senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
93
+ };
94
+ },
95
+ async injectE2ESession({ jid, session }) {
96
+ const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
97
+ await cipher.initOutgoing(session);
98
+ },
99
+ jidToSignalProtocolAddress(jid) {
100
+ return jidToSignalProtocolAddress(jid).toString();
101
+ },
102
+ };
103
+ }
104
+ const jidToSignalProtocolAddress = (jid) => {
105
+ const { user, device } = (0, WABinary_1.jidDecode)(jid);
106
+ return new libsignal.ProtocolAddress(user, device || 0);
107
+ };
108
+ const jidToSignalSenderKeyName = (group, user) => {
109
+ return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
110
+ };
111
+ function signalStorage({ creds, keys }) {
112
+ return {
113
+ loadSession: async (id) => {
114
+ const { [id]: sess } = await keys.get('session', [id]);
115
+ if (sess) {
116
+ return libsignal.SessionRecord.deserialize(sess);
117
+ }
118
+ },
119
+ storeSession: async (id, session) => {
120
+ await keys.set({ 'session': { [id]: session.serialize() } });
121
+ },
122
+ isTrustedIdentity: () => {
123
+ return true;
124
+ },
125
+ loadPreKey: async (id) => {
126
+ const keyId = id.toString();
127
+ const { [keyId]: key } = await keys.get('pre-key', [keyId]);
128
+ if (key) {
129
+ return {
130
+ privKey: Buffer.from(key.private),
131
+ pubKey: Buffer.from(key.public)
132
+ };
133
+ }
134
+ },
135
+ removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
136
+ loadSignedPreKey: () => {
137
+ const key = creds.signedPreKey;
138
+ return {
139
+ privKey: Buffer.from(key.keyPair.private),
140
+ pubKey: Buffer.from(key.keyPair.public)
141
+ };
142
+ },
143
+ loadSenderKey: async (keyId) => {
144
+ const { [keyId]: key } = await keys.get('sender-key', [keyId]);
145
+ if (key) {
146
+ return new WASignalGroup_1.SenderKeyRecord(key);
147
+ }
148
+ },
149
+ storeSenderKey: async (keyId, key) => {
150
+ await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
151
+ },
152
+ getOurRegistrationId: () => (creds.registrationId),
153
+ getOurIdentity: () => {
154
+ const { signedIdentityKey } = creds;
155
+ return {
156
+ privKey: Buffer.from(signedIdentityKey.private),
157
+ pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
158
+ };
159
+ }
160
+ };
161
+ }
@@ -1,2 +1,2 @@
1
- export * from './types';
2
- export * from './websocket';
1
+ export * from './types';
2
+ export * from './websocket';
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./websocket"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./websocket"), exports);
@@ -1,17 +1,15 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { EventEmitter } from 'events';
4
- import { URL } from 'url';
5
- import { SocketConfig } from '../../Types';
6
- export declare abstract class AbstractSocketClient extends EventEmitter {
7
- url: URL;
8
- config: SocketConfig;
9
- abstract get isOpen(): boolean;
10
- abstract get isClosed(): boolean;
11
- abstract get isClosing(): boolean;
12
- abstract get isConnecting(): boolean;
13
- constructor(url: URL, config: SocketConfig);
14
- abstract connect(): Promise<void>;
15
- abstract close(): Promise<void>;
16
- abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
17
- }
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 send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
15
+ }
@@ -1,13 +1,13 @@
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
+ "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,12 +1,12 @@
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
- send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
12
- }
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
+ send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
12
+ }
@@ -1,62 +1,62 @@
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
- }
15
- get isOpen() {
16
- var _a;
17
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
18
- }
19
- get isClosed() {
20
- var _a;
21
- return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
22
- }
23
- get isClosing() {
24
- var _a;
25
- return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
26
- }
27
- get isConnecting() {
28
- var _a;
29
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
30
- }
31
- async connect() {
32
- var _a, _b;
33
- if (this.socket) {
34
- return;
35
- }
36
- this.socket = new ws_1.default(this.url, {
37
- origin: Defaults_1.DEFAULT_ORIGIN,
38
- headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
- handshakeTimeout: this.config.connectTimeoutMs,
40
- timeout: this.config.connectTimeoutMs,
41
- agent: this.config.agent,
42
- });
43
- this.socket.setMaxListeners(0);
44
- const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
45
- for (const event of events) {
46
- (_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
47
- }
48
- }
49
- async close() {
50
- if (!this.socket) {
51
- return;
52
- }
53
- this.socket.close();
54
- this.socket = null;
55
- }
56
- send(str, cb) {
57
- var _a;
58
- (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
59
- return Boolean(this.socket);
60
- }
61
- }
62
- exports.WebSocketClient = WebSocketClient;
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
+ }
15
+ get isOpen() {
16
+ var _a;
17
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
18
+ }
19
+ get isClosed() {
20
+ var _a;
21
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
22
+ }
23
+ get isClosing() {
24
+ var _a;
25
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
26
+ }
27
+ get isConnecting() {
28
+ var _a;
29
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
30
+ }
31
+ async connect() {
32
+ var _a, _b;
33
+ if (this.socket) {
34
+ return;
35
+ }
36
+ this.socket = new ws_1.default(this.url, {
37
+ origin: Defaults_1.DEFAULT_ORIGIN,
38
+ headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
+ handshakeTimeout: this.config.connectTimeoutMs,
40
+ timeout: this.config.connectTimeoutMs,
41
+ agent: this.config.agent,
42
+ });
43
+ this.socket.setMaxListeners(0);
44
+ const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
45
+ for (const event of events) {
46
+ (_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
47
+ }
48
+ }
49
+ async close() {
50
+ if (!this.socket) {
51
+ return;
52
+ }
53
+ this.socket.close();
54
+ this.socket = null;
55
+ }
56
+ send(str, cb) {
57
+ var _a;
58
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
59
+ return Boolean(this.socket);
60
+ }
61
+ }
62
+ exports.WebSocketClient = WebSocketClient;