@wppconnect-team/wppconnect 1.41.3 → 2.0.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/CHANGELOG.md +12 -0
- package/dist/api/helpers/base64-mimetype.js +2 -2
- package/dist/api/helpers/decrypt.js +65 -72
- package/dist/api/helpers/download-file.js +31 -81
- package/dist/api/helpers/evaluate-and-return.js +98 -93
- package/dist/api/helpers/exposed.enum.d.ts +2 -1
- package/dist/api/helpers/exposed.enum.js +1 -0
- package/dist/api/helpers/file-to-base64.js +30 -81
- package/dist/api/helpers/filename-from-mimetype.js +4 -4
- package/dist/api/helpers/scrape-img-qr.js +37 -86
- package/dist/api/helpers/scrape-login.js +12 -57
- package/dist/api/helpers/select-sticker.js +35 -100
- package/dist/api/layers/business.layer.js +29 -134
- package/dist/api/layers/catalog.layer.js +59 -210
- package/dist/api/layers/community.layer.js +29 -120
- package/dist/api/layers/controls.layer.js +62 -262
- package/dist/api/layers/group.layer.js +126 -391
- package/dist/api/layers/host.layer.js +348 -702
- package/dist/api/layers/labels.layer.js +35 -131
- package/dist/api/layers/listener.layer.d.ts +9 -1
- package/dist/api/layers/listener.layer.js +392 -491
- package/dist/api/layers/newsletter.layer.js +20 -89
- package/dist/api/layers/profile.layer.js +73 -184
- package/dist/api/layers/retriever.layer.js +163 -468
- package/dist/api/layers/sender.layer.js +554 -1094
- package/dist/api/layers/status.layer.js +80 -179
- package/dist/api/layers/ui.layer.js +32 -129
- package/dist/api/model/enum/definitions.js +1 -1
- package/dist/api/whatsapp.js +200 -426
- package/dist/config/WAuserAgente.js +1 -1
- package/dist/config/create-config.js +1 -1
- package/dist/config/puppeteer.config.js +1 -1
- package/dist/controllers/auth.js +42 -110
- package/dist/controllers/browser.js +251 -411
- package/dist/controllers/initializer.js +171 -265
- package/dist/controllers/websocket.js +29 -28
- package/dist/controllers/welcome.js +38 -88
- package/dist/lib/wapi/wapi.js +1 -1
- package/dist/token-store/fileTokenStore.js +83 -173
- package/dist/token-store/isValidSessionToken.js +2 -2
- package/dist/token-store/isValidTokenStore.js +2 -2
- package/dist/token-store/memoryTokenStore.js +11 -14
- package/dist/utils/ffmpeg.js +75 -131
- package/dist/utils/logger.js +5 -5
- package/dist/utils/semver.js +6 -6
- package/dist/utils/sleep.js +1 -1
- package/package.json +8 -8
|
@@ -15,86 +15,26 @@
|
|
|
15
15
|
* You should have received a copy of the GNU Lesser General Public License
|
|
16
16
|
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
|
-
var __extends = (this && this.__extends) || (function () {
|
|
19
|
-
var extendStatics = function (d, b) {
|
|
20
|
-
extendStatics = Object.setPrototypeOf ||
|
|
21
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
-
return extendStatics(d, b);
|
|
24
|
-
};
|
|
25
|
-
return function (d, b) {
|
|
26
|
-
if (typeof b !== "function" && b !== null)
|
|
27
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
28
|
-
extendStatics(d, b);
|
|
29
|
-
function __() { this.constructor = d; }
|
|
30
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
34
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
36
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
37
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
38
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
39
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
43
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
44
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
-
function step(op) {
|
|
47
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
49
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
-
switch (op[0]) {
|
|
52
|
-
case 0: case 1: t = op; break;
|
|
53
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
-
default:
|
|
57
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
-
if (t[2]) _.ops.pop();
|
|
62
|
-
_.trys.pop(); continue;
|
|
63
|
-
}
|
|
64
|
-
op = body.call(thisArg, _);
|
|
65
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
-
if (ar || !(i in from)) {
|
|
72
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
-
ar[i] = from[i];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
-
};
|
|
78
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
19
|
exports.ListenerLayer = void 0;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
20
|
+
const events_1 = require("events");
|
|
21
|
+
const helpers_1 = require("../helpers");
|
|
22
|
+
const exposed_enum_1 = require("../helpers/exposed.enum");
|
|
23
|
+
const profile_layer_1 = require("./profile.layer");
|
|
24
|
+
class ListenerLayer extends profile_layer_1.ProfileLayer {
|
|
25
|
+
page;
|
|
26
|
+
listenerEmitter = new events_1.EventEmitter({
|
|
27
|
+
captureRejections: true,
|
|
28
|
+
});
|
|
29
|
+
constructor(page, session, options) {
|
|
30
|
+
super(page, session, options);
|
|
31
|
+
this.page = page;
|
|
32
|
+
this.listenerEmitter.setMaxListeners(0);
|
|
33
|
+
this.listenerEmitter.on(exposed_enum_1.ExposedFn.onInterfaceChange, (state) => {
|
|
34
|
+
this.log('http', `Current state: ${state.mode} (${state.displayInfo})`);
|
|
95
35
|
});
|
|
96
|
-
|
|
97
|
-
|
|
36
|
+
this.listenerEmitter[events_1.captureRejectionSymbol] = (reason, event) => {
|
|
37
|
+
let message = `Unhandled Rejection in a ${event} event: `;
|
|
98
38
|
if (reason instanceof Error) {
|
|
99
39
|
if (reason.stack) {
|
|
100
40
|
message += reason.stack;
|
|
@@ -106,463 +46,439 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
106
46
|
else {
|
|
107
47
|
message += JSON.stringify(reason);
|
|
108
48
|
}
|
|
109
|
-
|
|
49
|
+
this.log('error', reason);
|
|
110
50
|
};
|
|
111
|
-
return _this;
|
|
112
51
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
52
|
+
async afterPageScriptInjected() {
|
|
53
|
+
await super.afterPageScriptInjected();
|
|
54
|
+
const functions = [
|
|
55
|
+
...Object.values(exposed_enum_1.ExposedFn),
|
|
56
|
+
'onAddedToGroup',
|
|
57
|
+
'onIncomingCall',
|
|
58
|
+
'onRevokedMessage',
|
|
59
|
+
'onReactionMessage',
|
|
60
|
+
'onPollResponse',
|
|
61
|
+
'onUpdateLabel',
|
|
62
|
+
'onOrderStatusUpdate',
|
|
63
|
+
'onParticipantsChanged',
|
|
64
|
+
'onNewChat',
|
|
65
|
+
];
|
|
66
|
+
for (const func of functions) {
|
|
67
|
+
const has = await this.page
|
|
68
|
+
.evaluate((func) => typeof window[func] === 'function', func)
|
|
69
|
+
.catch(() => false);
|
|
70
|
+
if (!has) {
|
|
71
|
+
this.log('debug', `Exposing ${func} function`);
|
|
72
|
+
await this.page
|
|
73
|
+
.exposeFunction(func, (...args) => {
|
|
74
|
+
Promise.resolve().then(() => {
|
|
75
|
+
const count = this.listenerEmitter.listenerCount(func);
|
|
76
|
+
if (count > 0) {
|
|
77
|
+
this.log('debug', `Emitting ${func} event (${count} registered)`);
|
|
78
|
+
}
|
|
79
|
+
this.listenerEmitter.emit(func, ...args);
|
|
80
|
+
});
|
|
81
|
+
})
|
|
82
|
+
.catch(() => { });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
await this.page
|
|
86
|
+
.evaluate(() => {
|
|
87
|
+
try {
|
|
88
|
+
if (!window['onMessage']?.exposed) {
|
|
89
|
+
WPP.on('chat.new_message', (msg) => {
|
|
90
|
+
if (msg.isSentByMe || msg.isStatusV3) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const serialized = WAPI.processMessageObj(msg, false, false);
|
|
94
|
+
if (serialized) {
|
|
95
|
+
window['onMessage'](serialized);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
window['onMessage'].exposed = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error(error);
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
if (!window['onAck']?.exposed) {
|
|
106
|
+
window.WAPI.waitNewAcknowledgements(window['onAck']);
|
|
107
|
+
window['onAck'].exposed = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(error);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
if (!window['onMessageEdit']?.exposed) {
|
|
115
|
+
WPP.on('chat.msg_edited', (data) => {
|
|
116
|
+
const eventData = {
|
|
117
|
+
chat: data.chat,
|
|
118
|
+
id: data.id,
|
|
119
|
+
msg: WAPI.processMessageObj(data.msg, true, false),
|
|
166
120
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
case 2:
|
|
171
|
-
if (!(_i < functions_1.length)) return [3 /*break*/, 5];
|
|
172
|
-
func = functions_1[_i];
|
|
173
|
-
return [5 /*yield**/, _loop_1(func)];
|
|
174
|
-
case 3:
|
|
175
|
-
_a.sent();
|
|
176
|
-
_a.label = 4;
|
|
177
|
-
case 4:
|
|
178
|
-
_i++;
|
|
179
|
-
return [3 /*break*/, 2];
|
|
180
|
-
case 5: return [4 /*yield*/, this.page
|
|
181
|
-
.evaluate(function () {
|
|
182
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
183
|
-
try {
|
|
184
|
-
if (!((_a = window['onMessage']) === null || _a === void 0 ? void 0 : _a.exposed)) {
|
|
185
|
-
WPP.on('chat.new_message', function (msg) {
|
|
186
|
-
if (msg.isSentByMe || msg.isStatusV3) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
var serialized = WAPI.processMessageObj(msg, false, false);
|
|
190
|
-
if (serialized) {
|
|
191
|
-
window['onMessage'](serialized);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
window['onMessage'].exposed = true;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
console.error(error);
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
if (!((_b = window['onAck']) === null || _b === void 0 ? void 0 : _b.exposed)) {
|
|
202
|
-
window.WAPI.waitNewAcknowledgements(window['onAck']);
|
|
203
|
-
window['onAck'].exposed = true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
console.error(error);
|
|
208
|
-
}
|
|
209
|
-
try {
|
|
210
|
-
if (!((_c = window['onMessageEdit']) === null || _c === void 0 ? void 0 : _c.exposed)) {
|
|
211
|
-
WPP.on('chat.msg_edited', function (data) {
|
|
212
|
-
var eventData = {
|
|
213
|
-
chat: data.chat,
|
|
214
|
-
id: data.id,
|
|
215
|
-
msg: WAPI.processMessageObj(data.msg, true, false),
|
|
216
|
-
};
|
|
217
|
-
window['onMessageEdit'](eventData);
|
|
218
|
-
});
|
|
219
|
-
window['onMessageEdit'].exposed = true;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
console.error(error);
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
if (!((_d = window['onAnyMessage']) === null || _d === void 0 ? void 0 : _d.exposed)) {
|
|
227
|
-
WPP.on('chat.new_message', function (msg) {
|
|
228
|
-
var serialized = WAPI.processMessageObj(msg, true, false);
|
|
229
|
-
if (serialized) {
|
|
230
|
-
window['onAnyMessage'](serialized);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
window['onAnyMessage'].exposed = true;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
console.error(error);
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
if (!((_e = window['onStateChange']) === null || _e === void 0 ? void 0 : _e.exposed)) {
|
|
241
|
-
window.WAPI.onStateChange(window['onStateChange']);
|
|
242
|
-
window['onStateChange'].exposed = true;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
console.error(error);
|
|
247
|
-
}
|
|
248
|
-
try {
|
|
249
|
-
if (!((_f = window['onStreamChange']) === null || _f === void 0 ? void 0 : _f.exposed)) {
|
|
250
|
-
window.WAPI.onStreamChange(window['onStreamChange']);
|
|
251
|
-
window['onStreamChange'].exposed = true;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
console.error(error);
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
if (!((_g = window['onStreamModeChanged']) === null || _g === void 0 ? void 0 : _g.exposed)) {
|
|
259
|
-
window.WAPI.onStreamModeChanged(window['onStreamModeChanged']);
|
|
260
|
-
window['onStreamModeChanged'].exposed = true;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
console.error(error);
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
if (!((_h = window['onStreamInfoChanged']) === null || _h === void 0 ? void 0 : _h.exposed)) {
|
|
268
|
-
window.WAPI.onStreamInfoChanged(window['onStreamInfoChanged']);
|
|
269
|
-
window['onStreamInfoChanged'].exposed = true;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
catch (error) {
|
|
273
|
-
console.error(error);
|
|
274
|
-
}
|
|
275
|
-
try {
|
|
276
|
-
if (!((_j = window['onAddedToGroup']) === null || _j === void 0 ? void 0 : _j.exposed)) {
|
|
277
|
-
window.WAPI.onAddedToGroup(window['onAddedToGroup']);
|
|
278
|
-
window['onAddedToGroup'].exposed = true;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
console.error(error);
|
|
283
|
-
}
|
|
284
|
-
try {
|
|
285
|
-
if (!((_k = window['onIncomingCall']) === null || _k === void 0 ? void 0 : _k.exposed)) {
|
|
286
|
-
window.WAPI.onIncomingCall(window['onIncomingCall']);
|
|
287
|
-
window['onIncomingCall'].exposed = true;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
catch (error) {
|
|
291
|
-
console.error(error);
|
|
292
|
-
}
|
|
293
|
-
try {
|
|
294
|
-
if (!((_l = window['onInterfaceChange']) === null || _l === void 0 ? void 0 : _l.exposed)) {
|
|
295
|
-
window.WAPI.onInterfaceChange(window['onInterfaceChange']);
|
|
296
|
-
window['onInterfaceChange'].exposed = true;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
console.error(error);
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
if (!((_m = window['onNotificationMessage']) === null || _m === void 0 ? void 0 : _m.exposed)) {
|
|
304
|
-
window.WAPI.onNotificationMessage(window['onNotificationMessage']);
|
|
305
|
-
window['onNotificationMessage'].exposed = true;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
catch (error) {
|
|
309
|
-
console.error(error);
|
|
310
|
-
}
|
|
311
|
-
try {
|
|
312
|
-
if (!((_o = window['onPresenceChanged']) === null || _o === void 0 ? void 0 : _o.exposed)) {
|
|
313
|
-
WPP.on('chat.presence_change', window['onPresenceChanged']);
|
|
314
|
-
window['onPresenceChanged'].exposed = true;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
catch (error) {
|
|
318
|
-
console.error(error);
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
if (!((_p = window['onLiveLocation']) === null || _p === void 0 ? void 0 : _p.exposed)) {
|
|
322
|
-
window.WAPI.onLiveLocation(window['onLiveLocation']);
|
|
323
|
-
window['onLiveLocation'].exposed = true;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
327
|
-
console.error(error);
|
|
328
|
-
}
|
|
329
|
-
try {
|
|
330
|
-
if (!((_q = window['onRevokedMessage']) === null || _q === void 0 ? void 0 : _q.exposed)) {
|
|
331
|
-
WPP.on('chat.msg_revoke', function (data) {
|
|
332
|
-
var eventData = {
|
|
333
|
-
author: data.author,
|
|
334
|
-
from: data.from,
|
|
335
|
-
to: data.to,
|
|
336
|
-
id: data.id._serialized,
|
|
337
|
-
refId: data.refId._serialized,
|
|
338
|
-
};
|
|
339
|
-
window['onRevokedMessage'](eventData);
|
|
340
|
-
});
|
|
341
|
-
window['onRevokedMessage'].exposed = true;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
console.error(error);
|
|
346
|
-
}
|
|
347
|
-
try {
|
|
348
|
-
if (!((_r = window['onReactionMessage']) === null || _r === void 0 ? void 0 : _r.exposed)) {
|
|
349
|
-
WPP.on('chat.new_reaction', function (data) {
|
|
350
|
-
var eventData = {
|
|
351
|
-
id: data.id,
|
|
352
|
-
msgId: data.msgId,
|
|
353
|
-
reactionText: data.reactionText,
|
|
354
|
-
read: data.read,
|
|
355
|
-
orphan: data.orphan,
|
|
356
|
-
orphanReason: data.orphanReason,
|
|
357
|
-
timestamp: data.timestamp,
|
|
358
|
-
};
|
|
359
|
-
window['onReactionMessage'](eventData);
|
|
360
|
-
});
|
|
361
|
-
window['onReactionMessage'].exposed = true;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
catch (error) {
|
|
365
|
-
console.error(error);
|
|
366
|
-
}
|
|
367
|
-
try {
|
|
368
|
-
if (!((_s = window['onPollResponse']) === null || _s === void 0 ? void 0 : _s.exposed)) {
|
|
369
|
-
WPP.on('chat.poll_response', function (data) {
|
|
370
|
-
var eventData = {
|
|
371
|
-
msgId: data.msgId,
|
|
372
|
-
chatId: data.chatId,
|
|
373
|
-
selectedOptions: data.selectedOptions,
|
|
374
|
-
timestamp: data.timestamp,
|
|
375
|
-
sender: data.sender,
|
|
376
|
-
};
|
|
377
|
-
window['onPollResponse'](eventData);
|
|
378
|
-
});
|
|
379
|
-
window['onPollResponse'].exposed = true;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
catch (error) {
|
|
383
|
-
console.error(error);
|
|
384
|
-
}
|
|
385
|
-
try {
|
|
386
|
-
if (!((_t = window['onUpdateLabel']) === null || _t === void 0 ? void 0 : _t.exposed)) {
|
|
387
|
-
WPP.on('chat.update_label', function (data) {
|
|
388
|
-
var eventData = {
|
|
389
|
-
chat: data.chat,
|
|
390
|
-
ids: data.ids,
|
|
391
|
-
labels: data.labels,
|
|
392
|
-
type: data.type,
|
|
393
|
-
};
|
|
394
|
-
window['onUpdateLabel'](eventData);
|
|
395
|
-
});
|
|
396
|
-
window['onUpdateLabel'].exposed = true;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
catch (error) {
|
|
400
|
-
console.error(error);
|
|
401
|
-
}
|
|
402
|
-
try {
|
|
403
|
-
if (!((_u = window['onOrderStatusUpdate']) === null || _u === void 0 ? void 0 : _u.exposed)) {
|
|
404
|
-
WPP.on('order.payment_status', function (data) {
|
|
405
|
-
var eventData = {
|
|
406
|
-
method: data.method,
|
|
407
|
-
timestamp: data.timestamp,
|
|
408
|
-
reference_id: data.reference_id,
|
|
409
|
-
msgId: data.msgId,
|
|
410
|
-
};
|
|
411
|
-
window['onOrderStatusUpdate'](eventData);
|
|
412
|
-
});
|
|
413
|
-
window['onOrderStatusUpdate'].exposed = true;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
catch (error) {
|
|
417
|
-
console.error(error);
|
|
418
|
-
}
|
|
419
|
-
try {
|
|
420
|
-
if (!((_v = window['onParticipantsChanged']) === null || _v === void 0 ? void 0 : _v.exposed)) {
|
|
421
|
-
WPP.on('group.participant_changed', function (participantChangedEvent) {
|
|
422
|
-
window['onParticipantsChanged'](participantChangedEvent);
|
|
423
|
-
});
|
|
424
|
-
window['onParticipantsChanged'].exposed = true;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
catch (error) {
|
|
428
|
-
console.error(error);
|
|
429
|
-
}
|
|
430
|
-
try {
|
|
431
|
-
if (!((_w = window['onNewChat']) === null || _w === void 0 ? void 0 : _w.exposed)) {
|
|
432
|
-
WPP.on('chat.new_chat', function (chat) {
|
|
433
|
-
window['onNewChat'](chat);
|
|
434
|
-
});
|
|
435
|
-
window['onNewChat'].exposed = true;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
catch (error) {
|
|
439
|
-
console.error(error);
|
|
440
|
-
}
|
|
441
|
-
})
|
|
442
|
-
.catch(function () { })];
|
|
443
|
-
case 6:
|
|
444
|
-
_a.sent();
|
|
445
|
-
return [2 /*return*/];
|
|
121
|
+
window['onMessageEdit'](eventData);
|
|
122
|
+
});
|
|
123
|
+
window['onMessageEdit'].exposed = true;
|
|
446
124
|
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(error);
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
if (!window['onAnyMessage']?.exposed) {
|
|
131
|
+
WPP.on('chat.new_message', (msg) => {
|
|
132
|
+
const serialized = WAPI.processMessageObj(msg, true, false);
|
|
133
|
+
if (serialized) {
|
|
134
|
+
window['onAnyMessage'](serialized);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
window['onAnyMessage'].exposed = true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error(error);
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
if (!window['onStateChange']?.exposed) {
|
|
145
|
+
window.WAPI.onStateChange(window['onStateChange']);
|
|
146
|
+
window['onStateChange'].exposed = true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error(error);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
if (!window['onStreamChange']?.exposed) {
|
|
154
|
+
window.WAPI.onStreamChange(window['onStreamChange']);
|
|
155
|
+
window['onStreamChange'].exposed = true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error(error);
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
if (!window['onStreamModeChanged']?.exposed) {
|
|
163
|
+
window.WAPI.onStreamModeChanged(window['onStreamModeChanged']);
|
|
164
|
+
window['onStreamModeChanged'].exposed = true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error(error);
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
if (!window['onStreamInfoChanged']?.exposed) {
|
|
172
|
+
window.WAPI.onStreamInfoChanged(window['onStreamInfoChanged']);
|
|
173
|
+
window['onStreamInfoChanged'].exposed = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error(error);
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
if (!window['onAddedToGroup']?.exposed) {
|
|
181
|
+
window.WAPI.onAddedToGroup(window['onAddedToGroup']);
|
|
182
|
+
window['onAddedToGroup'].exposed = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
console.error(error);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
if (!window['onIncomingCall']?.exposed) {
|
|
190
|
+
window.WAPI.onIncomingCall(window['onIncomingCall']);
|
|
191
|
+
window['onIncomingCall'].exposed = true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
console.error(error);
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
if (!window['onInterfaceChange']?.exposed) {
|
|
199
|
+
window.WAPI.onInterfaceChange(window['onInterfaceChange']);
|
|
200
|
+
window['onInterfaceChange'].exposed = true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
console.error(error);
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
if (!window['onNotificationMessage']?.exposed) {
|
|
208
|
+
window.WAPI.onNotificationMessage(window['onNotificationMessage']);
|
|
209
|
+
window['onNotificationMessage'].exposed = true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
console.error(error);
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
if (!window['onPresenceChanged']?.exposed) {
|
|
217
|
+
WPP.on('chat.presence_change', window['onPresenceChanged']);
|
|
218
|
+
window['onPresenceChanged'].exposed = true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
console.error(error);
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
if (!window['onLiveLocation']?.exposed) {
|
|
226
|
+
window.WAPI.onLiveLocation(window['onLiveLocation']);
|
|
227
|
+
window['onLiveLocation'].exposed = true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.error(error);
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
if (!window['onRevokedMessage']?.exposed) {
|
|
235
|
+
WPP.on('chat.msg_revoke', (data) => {
|
|
236
|
+
const eventData = {
|
|
237
|
+
author: data.author,
|
|
238
|
+
from: data.from,
|
|
239
|
+
to: data.to,
|
|
240
|
+
id: data.id._serialized,
|
|
241
|
+
refId: data.refId._serialized,
|
|
242
|
+
};
|
|
243
|
+
window['onRevokedMessage'](eventData);
|
|
244
|
+
});
|
|
245
|
+
window['onRevokedMessage'].exposed = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
console.error(error);
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
if (!window['onReactionMessage']?.exposed) {
|
|
253
|
+
WPP.on('chat.new_reaction', (data) => {
|
|
254
|
+
const eventData = {
|
|
255
|
+
id: data.id,
|
|
256
|
+
msgId: data.msgId,
|
|
257
|
+
reactionText: data.reactionText,
|
|
258
|
+
read: data.read,
|
|
259
|
+
orphan: data.orphan,
|
|
260
|
+
orphanReason: data.orphanReason,
|
|
261
|
+
timestamp: data.timestamp,
|
|
262
|
+
};
|
|
263
|
+
window['onReactionMessage'](eventData);
|
|
264
|
+
});
|
|
265
|
+
window['onReactionMessage'].exposed = true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.error(error);
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
if (!window['onPollResponse']?.exposed) {
|
|
273
|
+
WPP.on('chat.poll_response', (data) => {
|
|
274
|
+
const eventData = {
|
|
275
|
+
msgId: data.msgId,
|
|
276
|
+
chatId: data.chatId,
|
|
277
|
+
selectedOptions: data.selectedOptions,
|
|
278
|
+
timestamp: data.timestamp,
|
|
279
|
+
sender: data.sender,
|
|
280
|
+
};
|
|
281
|
+
window['onPollResponse'](eventData);
|
|
282
|
+
});
|
|
283
|
+
window['onPollResponse'].exposed = true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error(error);
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
if (!window['onUpdateLabel']?.exposed) {
|
|
291
|
+
WPP.on('chat.update_label', (data) => {
|
|
292
|
+
const eventData = {
|
|
293
|
+
chat: data.chat,
|
|
294
|
+
ids: data.ids,
|
|
295
|
+
labels: data.labels,
|
|
296
|
+
type: data.type,
|
|
297
|
+
};
|
|
298
|
+
window['onUpdateLabel'](eventData);
|
|
299
|
+
});
|
|
300
|
+
window['onUpdateLabel'].exposed = true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
console.error(error);
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
if (!window['onOrderStatusUpdate']?.exposed) {
|
|
308
|
+
WPP.on('order.payment_status', (data) => {
|
|
309
|
+
const eventData = {
|
|
310
|
+
method: data.method,
|
|
311
|
+
timestamp: data.timestamp,
|
|
312
|
+
reference_id: data.reference_id,
|
|
313
|
+
msgId: data.msgId,
|
|
314
|
+
};
|
|
315
|
+
window['onOrderStatusUpdate'](eventData);
|
|
316
|
+
});
|
|
317
|
+
window['onOrderStatusUpdate'].exposed = true;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
console.error(error);
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
if (!window['onParticipantsChanged']?.exposed) {
|
|
325
|
+
WPP.on('group.participant_changed', (participantChangedEvent) => {
|
|
326
|
+
window['onParticipantsChanged'](participantChangedEvent);
|
|
327
|
+
});
|
|
328
|
+
window['onParticipantsChanged'].exposed = true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
console.error(error);
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
if (!window['onNewChat']?.exposed) {
|
|
336
|
+
WPP.on('chat.new_chat', (chat) => {
|
|
337
|
+
window['onNewChat'](chat);
|
|
338
|
+
});
|
|
339
|
+
window['onNewChat'].exposed = true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
console.error(error);
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
if (!window['onBackendEvent']?.exposed) {
|
|
347
|
+
WPP.on('conn.backend_event', (eventName, ...args) => {
|
|
348
|
+
window['onBackendEvent'](eventName, ...args);
|
|
349
|
+
});
|
|
350
|
+
window['onBackendEvent'].exposed = true;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
console.error(error);
|
|
355
|
+
}
|
|
356
|
+
})
|
|
357
|
+
.catch(() => { });
|
|
358
|
+
}
|
|
450
359
|
/**
|
|
451
360
|
* Register the event and create a disposable object to stop the listening
|
|
452
361
|
* @param event Name of event
|
|
453
362
|
* @param listener The function to execute
|
|
454
363
|
* @returns Disposable object to stop the listening
|
|
455
364
|
*/
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
this.log('debug', "Registering ".concat(event.toString(), " event"));
|
|
365
|
+
registerEvent(event, listener) {
|
|
366
|
+
this.log('debug', `Registering ${event.toString()} event`);
|
|
459
367
|
this.listenerEmitter.on(event, listener);
|
|
460
368
|
return {
|
|
461
|
-
dispose:
|
|
462
|
-
|
|
369
|
+
dispose: () => {
|
|
370
|
+
this.listenerEmitter.off(event, listener);
|
|
463
371
|
},
|
|
464
372
|
};
|
|
465
|
-
}
|
|
373
|
+
}
|
|
466
374
|
/**
|
|
467
375
|
* @event Listens to all new messages received only.
|
|
468
376
|
* @returns Disposable object to stop the listening
|
|
469
377
|
*/
|
|
470
|
-
|
|
378
|
+
onMessage(callback) {
|
|
471
379
|
return this.registerEvent(exposed_enum_1.ExposedFn.OnMessage, callback);
|
|
472
|
-
}
|
|
380
|
+
}
|
|
473
381
|
/**
|
|
474
382
|
* @event Listens to all new messages, sent and received.
|
|
475
383
|
* @param to callback
|
|
476
384
|
* @fires Message
|
|
477
385
|
* @returns Disposable object to stop the listening
|
|
478
386
|
*/
|
|
479
|
-
|
|
387
|
+
onAnyMessage(callback) {
|
|
480
388
|
return this.registerEvent(exposed_enum_1.ExposedFn.OnAnyMessage, callback);
|
|
481
|
-
}
|
|
389
|
+
}
|
|
482
390
|
/**
|
|
483
391
|
* @event Listens to all notification messages, like group changes, join, leave
|
|
484
392
|
* @param to callback
|
|
485
393
|
* @fires Message
|
|
486
394
|
* @returns Disposable object to stop the listening
|
|
487
395
|
*/
|
|
488
|
-
|
|
396
|
+
onNotificationMessage(callback) {
|
|
489
397
|
return this.registerEvent(exposed_enum_1.ExposedFn.onNotificationMessage, callback);
|
|
490
|
-
}
|
|
398
|
+
}
|
|
491
399
|
/**
|
|
492
400
|
* @event Listens List of mobile states
|
|
493
401
|
* @returns Disposable object to stop the listening
|
|
494
402
|
*/
|
|
495
|
-
|
|
403
|
+
onStateChange(callback) {
|
|
496
404
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStateChange, callback);
|
|
497
|
-
}
|
|
405
|
+
}
|
|
498
406
|
/**
|
|
499
407
|
* @deprecated in favor of {@link onStreamModeChanged}
|
|
500
408
|
* @event Returns the current state of the connection
|
|
501
409
|
* @returns Disposable object to stop the listening
|
|
502
410
|
*/
|
|
503
|
-
|
|
411
|
+
onStreamChange(callback) {
|
|
504
412
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStreamChange, callback);
|
|
505
|
-
}
|
|
413
|
+
}
|
|
506
414
|
/**
|
|
507
415
|
* @event Listens to Stream mode changes
|
|
508
416
|
* @returns Disposable object to stop the listening
|
|
509
417
|
*/
|
|
510
|
-
|
|
418
|
+
onStreamModeChanged(callback) {
|
|
511
419
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStreamModeChanged, callback);
|
|
512
|
-
}
|
|
420
|
+
}
|
|
513
421
|
/**
|
|
514
422
|
* @event Listens to Stream info changes
|
|
515
423
|
* @returns Disposable object to stop the listening
|
|
516
424
|
*/
|
|
517
|
-
|
|
425
|
+
onStreamInfoChanged(callback) {
|
|
518
426
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStreamInfoChanged, callback);
|
|
519
|
-
}
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* @event Listens to all internal WhatsApp Web BackendEventBus events.
|
|
430
|
+
* The first argument is the event name; additional arguments vary by event.
|
|
431
|
+
* @returns Disposable object to stop the listening
|
|
432
|
+
*/
|
|
433
|
+
onBackendEvent(callback) {
|
|
434
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onBackendEvent, callback);
|
|
435
|
+
}
|
|
520
436
|
/**
|
|
521
437
|
* @event Listens to interface mode change See {@link InterfaceState} and {@link InterfaceMode} for details
|
|
522
438
|
* @returns Disposable object to stop the listening
|
|
523
439
|
*/
|
|
524
|
-
|
|
440
|
+
onInterfaceChange(callback) {
|
|
525
441
|
return this.registerEvent(exposed_enum_1.ExposedFn.onInterfaceChange, callback);
|
|
526
|
-
}
|
|
442
|
+
}
|
|
527
443
|
/**
|
|
528
444
|
* @event Listens to message acknowledgement changes
|
|
529
445
|
* @returns Disposable object to stop the listening
|
|
530
446
|
*/
|
|
531
|
-
|
|
447
|
+
onAck(callback) {
|
|
532
448
|
return this.registerEvent(exposed_enum_1.ExposedFn.onAck, callback);
|
|
533
|
-
}
|
|
449
|
+
}
|
|
534
450
|
/**
|
|
535
451
|
* @event Listens to message edited changes
|
|
536
452
|
* @returns Disposable object to stop the listening
|
|
537
453
|
*/
|
|
538
|
-
|
|
454
|
+
onMessageEdit(callback) {
|
|
539
455
|
return this.registerEvent(exposed_enum_1.ExposedFn.onMessageEdit, callback);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
456
|
+
}
|
|
457
|
+
onLiveLocation(id, callback) {
|
|
458
|
+
const ids = [];
|
|
543
459
|
if (typeof id === 'function') {
|
|
544
460
|
callback = id;
|
|
545
461
|
}
|
|
546
462
|
else if (Array.isArray(id)) {
|
|
547
|
-
ids.push
|
|
463
|
+
ids.push(...id);
|
|
548
464
|
}
|
|
549
465
|
else {
|
|
550
466
|
ids.push(id);
|
|
551
467
|
}
|
|
552
|
-
return this.registerEvent(exposed_enum_1.ExposedFn.onLiveLocation,
|
|
468
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onLiveLocation, (event) => {
|
|
553
469
|
// Only group events
|
|
554
470
|
if (ids.length && !ids.includes(event.id)) {
|
|
555
471
|
return;
|
|
556
472
|
}
|
|
557
473
|
callback(event);
|
|
558
474
|
});
|
|
559
|
-
}
|
|
560
|
-
|
|
475
|
+
}
|
|
476
|
+
onParticipantsChanged(groupId, callback) {
|
|
561
477
|
if (typeof groupId === 'function') {
|
|
562
478
|
callback = groupId;
|
|
563
479
|
groupId = null;
|
|
564
480
|
}
|
|
565
|
-
return this.registerEvent(exposed_enum_1.ExposedFn.onParticipantsChanged,
|
|
481
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onParticipantsChanged, (evData) => {
|
|
566
482
|
if (groupId && groupId !== evData.groupId) {
|
|
567
483
|
return;
|
|
568
484
|
}
|
|
@@ -575,30 +491,30 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
575
491
|
who: evData.participants,
|
|
576
492
|
});
|
|
577
493
|
});
|
|
578
|
-
}
|
|
494
|
+
}
|
|
579
495
|
/**
|
|
580
496
|
* @event Fires callback with Chat object every time the host phone is added to a group.
|
|
581
497
|
* @param to callback
|
|
582
498
|
* @returns Disposable object to stop the listening
|
|
583
499
|
*/
|
|
584
|
-
|
|
500
|
+
onAddedToGroup(callback) {
|
|
585
501
|
return this.registerEvent('onAddedToGroup', callback);
|
|
586
|
-
}
|
|
502
|
+
}
|
|
587
503
|
/**
|
|
588
504
|
* @event Listen for incoming calls, whether audio or video (pending a reaction).
|
|
589
505
|
* To reject the call, simply call `rejectCall` {@link rejectCall}
|
|
590
506
|
* @returns Disposable object to stop listening
|
|
591
507
|
*/
|
|
592
|
-
|
|
508
|
+
onIncomingCall(callback) {
|
|
593
509
|
return this.registerEvent('onIncomingCall', callback);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
510
|
+
}
|
|
511
|
+
onPresenceChanged(id, callback) {
|
|
512
|
+
const ids = [];
|
|
597
513
|
if (typeof id === 'function') {
|
|
598
514
|
callback = id;
|
|
599
515
|
}
|
|
600
516
|
else if (Array.isArray(id)) {
|
|
601
|
-
ids.push
|
|
517
|
+
ids.push(...id);
|
|
602
518
|
}
|
|
603
519
|
else {
|
|
604
520
|
ids.push(id);
|
|
@@ -606,14 +522,14 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
606
522
|
if (ids.length) {
|
|
607
523
|
this.subscribePresence(ids);
|
|
608
524
|
}
|
|
609
|
-
return this.registerEvent(exposed_enum_1.ExposedFn.onPresenceChanged,
|
|
525
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onPresenceChanged, (presence) => {
|
|
610
526
|
// Only group events
|
|
611
527
|
if (ids.length && !ids.includes(presence.id)) {
|
|
612
528
|
return;
|
|
613
529
|
}
|
|
614
530
|
callback(presence);
|
|
615
531
|
});
|
|
616
|
-
}
|
|
532
|
+
}
|
|
617
533
|
/**
|
|
618
534
|
* Subscribe presence of a contact or group to use in onPresenceChanged (see {@link onPresenceChanged})
|
|
619
535
|
*
|
|
@@ -633,73 +549,58 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
633
549
|
* @param id contact id (xxxxx@c.us) or group id: xxxxx-yyyy@g.us
|
|
634
550
|
* @returns number of subscribed
|
|
635
551
|
*/
|
|
636
|
-
|
|
637
|
-
return
|
|
638
|
-
|
|
639
|
-
switch (_a.label) {
|
|
640
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (id) { return WAPI.subscribePresence(id); }, id)];
|
|
641
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
};
|
|
552
|
+
async subscribePresence(id) {
|
|
553
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, (id) => WAPI.subscribePresence(id), id);
|
|
554
|
+
}
|
|
646
555
|
/**
|
|
647
556
|
* Unsubscribe presence of a contact or group to use in onPresenceChanged (see {@link onPresenceChanged})
|
|
648
557
|
* @param id contact id (xxxxx@c.us) or group id: xxxxx-yyyy@g.us
|
|
649
558
|
* @returns number of unsubscribed
|
|
650
559
|
*/
|
|
651
|
-
|
|
652
|
-
return
|
|
653
|
-
|
|
654
|
-
switch (_a.label) {
|
|
655
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (id) { return WAPI.unsubscribePresence(id); }, id)];
|
|
656
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
});
|
|
660
|
-
};
|
|
560
|
+
async unsubscribePresence(id) {
|
|
561
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, (id) => WAPI.unsubscribePresence(id), id);
|
|
562
|
+
}
|
|
661
563
|
/**
|
|
662
564
|
* @event Listens to message revocation
|
|
663
565
|
* @returns Disposable object to stop the listening
|
|
664
566
|
*/
|
|
665
|
-
|
|
567
|
+
onRevokedMessage(callback) {
|
|
666
568
|
return this.registerEvent('onRevokedMessage', callback);
|
|
667
|
-
}
|
|
569
|
+
}
|
|
668
570
|
/**
|
|
669
571
|
* @event Listens to message reactions
|
|
670
572
|
* @returns Disposable object to stop the listening
|
|
671
573
|
*/
|
|
672
|
-
|
|
574
|
+
onReactionMessage(callback) {
|
|
673
575
|
return this.registerEvent('onReactionMessage', callback);
|
|
674
|
-
}
|
|
576
|
+
}
|
|
675
577
|
/**
|
|
676
578
|
* @event Listens to poll response messages
|
|
677
579
|
* @returns Disposable object to stop the listening
|
|
678
580
|
*/
|
|
679
|
-
|
|
581
|
+
onPollResponse(callback) {
|
|
680
582
|
return this.registerEvent('onPollResponse', callback);
|
|
681
|
-
}
|
|
583
|
+
}
|
|
682
584
|
/**
|
|
683
585
|
* @event Listens to update label
|
|
684
586
|
* @returns Disposable object to stop the listening
|
|
685
587
|
*/
|
|
686
|
-
|
|
588
|
+
onUpdateLabel(callback) {
|
|
687
589
|
return this.registerEvent('onUpdateLabel', callback);
|
|
688
|
-
}
|
|
590
|
+
}
|
|
689
591
|
/**
|
|
690
592
|
* @event Listens to update order status
|
|
691
593
|
* @returns Disposable object to stop the listening
|
|
692
594
|
*/
|
|
693
|
-
|
|
595
|
+
onOrderStatusUpdate(callback) {
|
|
694
596
|
return this.registerEvent('onOrderStatusUpdate', callback);
|
|
695
|
-
}
|
|
597
|
+
}
|
|
696
598
|
/**
|
|
697
599
|
* @event Listens to chats being added to ChatStore (Cache Layer)
|
|
698
600
|
* @returns Disposable object to stop the listening
|
|
699
601
|
*/
|
|
700
|
-
|
|
602
|
+
onNewChat(callback) {
|
|
701
603
|
return this.registerEvent('onNewChat', callback);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
}(profile_layer_1.ProfileLayer));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
705
606
|
exports.ListenerLayer = ListenerLayer;
|