@wppconnect-team/wppconnect 2.0.0 → 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 +6 -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/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.js +386 -504
- 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 +161 -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 -437
- 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/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 +6 -6
|
@@ -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,482 +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, _x;
|
|
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
|
-
try {
|
|
442
|
-
if (!((_x = window['onBackendEvent']) === null || _x === void 0 ? void 0 : _x.exposed)) {
|
|
443
|
-
WPP.on('conn.backend_event', function (args) {
|
|
444
|
-
window['onBackendEvent'](args);
|
|
445
|
-
});
|
|
446
|
-
window['onBackendEvent'].exposed = true;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
catch (error) {
|
|
450
|
-
console.error(error);
|
|
451
|
-
}
|
|
452
|
-
})
|
|
453
|
-
.catch(function () { })];
|
|
454
|
-
case 6:
|
|
455
|
-
_a.sent();
|
|
456
|
-
return [2 /*return*/];
|
|
121
|
+
window['onMessageEdit'](eventData);
|
|
122
|
+
});
|
|
123
|
+
window['onMessageEdit'].exposed = true;
|
|
457
124
|
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
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
|
+
}
|
|
461
359
|
/**
|
|
462
360
|
* Register the event and create a disposable object to stop the listening
|
|
463
361
|
* @param event Name of event
|
|
464
362
|
* @param listener The function to execute
|
|
465
363
|
* @returns Disposable object to stop the listening
|
|
466
364
|
*/
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
this.log('debug', "Registering ".concat(event.toString(), " event"));
|
|
365
|
+
registerEvent(event, listener) {
|
|
366
|
+
this.log('debug', `Registering ${event.toString()} event`);
|
|
470
367
|
this.listenerEmitter.on(event, listener);
|
|
471
368
|
return {
|
|
472
|
-
dispose:
|
|
473
|
-
|
|
369
|
+
dispose: () => {
|
|
370
|
+
this.listenerEmitter.off(event, listener);
|
|
474
371
|
},
|
|
475
372
|
};
|
|
476
|
-
}
|
|
373
|
+
}
|
|
477
374
|
/**
|
|
478
375
|
* @event Listens to all new messages received only.
|
|
479
376
|
* @returns Disposable object to stop the listening
|
|
480
377
|
*/
|
|
481
|
-
|
|
378
|
+
onMessage(callback) {
|
|
482
379
|
return this.registerEvent(exposed_enum_1.ExposedFn.OnMessage, callback);
|
|
483
|
-
}
|
|
380
|
+
}
|
|
484
381
|
/**
|
|
485
382
|
* @event Listens to all new messages, sent and received.
|
|
486
383
|
* @param to callback
|
|
487
384
|
* @fires Message
|
|
488
385
|
* @returns Disposable object to stop the listening
|
|
489
386
|
*/
|
|
490
|
-
|
|
387
|
+
onAnyMessage(callback) {
|
|
491
388
|
return this.registerEvent(exposed_enum_1.ExposedFn.OnAnyMessage, callback);
|
|
492
|
-
}
|
|
389
|
+
}
|
|
493
390
|
/**
|
|
494
391
|
* @event Listens to all notification messages, like group changes, join, leave
|
|
495
392
|
* @param to callback
|
|
496
393
|
* @fires Message
|
|
497
394
|
* @returns Disposable object to stop the listening
|
|
498
395
|
*/
|
|
499
|
-
|
|
396
|
+
onNotificationMessage(callback) {
|
|
500
397
|
return this.registerEvent(exposed_enum_1.ExposedFn.onNotificationMessage, callback);
|
|
501
|
-
}
|
|
398
|
+
}
|
|
502
399
|
/**
|
|
503
400
|
* @event Listens List of mobile states
|
|
504
401
|
* @returns Disposable object to stop the listening
|
|
505
402
|
*/
|
|
506
|
-
|
|
403
|
+
onStateChange(callback) {
|
|
507
404
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStateChange, callback);
|
|
508
|
-
}
|
|
405
|
+
}
|
|
509
406
|
/**
|
|
510
407
|
* @deprecated in favor of {@link onStreamModeChanged}
|
|
511
408
|
* @event Returns the current state of the connection
|
|
512
409
|
* @returns Disposable object to stop the listening
|
|
513
410
|
*/
|
|
514
|
-
|
|
411
|
+
onStreamChange(callback) {
|
|
515
412
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStreamChange, callback);
|
|
516
|
-
}
|
|
413
|
+
}
|
|
517
414
|
/**
|
|
518
415
|
* @event Listens to Stream mode changes
|
|
519
416
|
* @returns Disposable object to stop the listening
|
|
520
417
|
*/
|
|
521
|
-
|
|
418
|
+
onStreamModeChanged(callback) {
|
|
522
419
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStreamModeChanged, callback);
|
|
523
|
-
}
|
|
420
|
+
}
|
|
524
421
|
/**
|
|
525
422
|
* @event Listens to Stream info changes
|
|
526
423
|
* @returns Disposable object to stop the listening
|
|
527
424
|
*/
|
|
528
|
-
|
|
425
|
+
onStreamInfoChanged(callback) {
|
|
529
426
|
return this.registerEvent(exposed_enum_1.ExposedFn.onStreamInfoChanged, callback);
|
|
530
|
-
}
|
|
427
|
+
}
|
|
531
428
|
/**
|
|
532
429
|
* @event Listens to all internal WhatsApp Web BackendEventBus events.
|
|
533
430
|
* The first argument is the event name; additional arguments vary by event.
|
|
534
431
|
* @returns Disposable object to stop the listening
|
|
535
432
|
*/
|
|
536
|
-
|
|
433
|
+
onBackendEvent(callback) {
|
|
537
434
|
return this.registerEvent(exposed_enum_1.ExposedFn.onBackendEvent, callback);
|
|
538
|
-
}
|
|
435
|
+
}
|
|
539
436
|
/**
|
|
540
437
|
* @event Listens to interface mode change See {@link InterfaceState} and {@link InterfaceMode} for details
|
|
541
438
|
* @returns Disposable object to stop the listening
|
|
542
439
|
*/
|
|
543
|
-
|
|
440
|
+
onInterfaceChange(callback) {
|
|
544
441
|
return this.registerEvent(exposed_enum_1.ExposedFn.onInterfaceChange, callback);
|
|
545
|
-
}
|
|
442
|
+
}
|
|
546
443
|
/**
|
|
547
444
|
* @event Listens to message acknowledgement changes
|
|
548
445
|
* @returns Disposable object to stop the listening
|
|
549
446
|
*/
|
|
550
|
-
|
|
447
|
+
onAck(callback) {
|
|
551
448
|
return this.registerEvent(exposed_enum_1.ExposedFn.onAck, callback);
|
|
552
|
-
}
|
|
449
|
+
}
|
|
553
450
|
/**
|
|
554
451
|
* @event Listens to message edited changes
|
|
555
452
|
* @returns Disposable object to stop the listening
|
|
556
453
|
*/
|
|
557
|
-
|
|
454
|
+
onMessageEdit(callback) {
|
|
558
455
|
return this.registerEvent(exposed_enum_1.ExposedFn.onMessageEdit, callback);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
456
|
+
}
|
|
457
|
+
onLiveLocation(id, callback) {
|
|
458
|
+
const ids = [];
|
|
562
459
|
if (typeof id === 'function') {
|
|
563
460
|
callback = id;
|
|
564
461
|
}
|
|
565
462
|
else if (Array.isArray(id)) {
|
|
566
|
-
ids.push
|
|
463
|
+
ids.push(...id);
|
|
567
464
|
}
|
|
568
465
|
else {
|
|
569
466
|
ids.push(id);
|
|
570
467
|
}
|
|
571
|
-
return this.registerEvent(exposed_enum_1.ExposedFn.onLiveLocation,
|
|
468
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onLiveLocation, (event) => {
|
|
572
469
|
// Only group events
|
|
573
470
|
if (ids.length && !ids.includes(event.id)) {
|
|
574
471
|
return;
|
|
575
472
|
}
|
|
576
473
|
callback(event);
|
|
577
474
|
});
|
|
578
|
-
}
|
|
579
|
-
|
|
475
|
+
}
|
|
476
|
+
onParticipantsChanged(groupId, callback) {
|
|
580
477
|
if (typeof groupId === 'function') {
|
|
581
478
|
callback = groupId;
|
|
582
479
|
groupId = null;
|
|
583
480
|
}
|
|
584
|
-
return this.registerEvent(exposed_enum_1.ExposedFn.onParticipantsChanged,
|
|
481
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onParticipantsChanged, (evData) => {
|
|
585
482
|
if (groupId && groupId !== evData.groupId) {
|
|
586
483
|
return;
|
|
587
484
|
}
|
|
@@ -594,30 +491,30 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
594
491
|
who: evData.participants,
|
|
595
492
|
});
|
|
596
493
|
});
|
|
597
|
-
}
|
|
494
|
+
}
|
|
598
495
|
/**
|
|
599
496
|
* @event Fires callback with Chat object every time the host phone is added to a group.
|
|
600
497
|
* @param to callback
|
|
601
498
|
* @returns Disposable object to stop the listening
|
|
602
499
|
*/
|
|
603
|
-
|
|
500
|
+
onAddedToGroup(callback) {
|
|
604
501
|
return this.registerEvent('onAddedToGroup', callback);
|
|
605
|
-
}
|
|
502
|
+
}
|
|
606
503
|
/**
|
|
607
504
|
* @event Listen for incoming calls, whether audio or video (pending a reaction).
|
|
608
505
|
* To reject the call, simply call `rejectCall` {@link rejectCall}
|
|
609
506
|
* @returns Disposable object to stop listening
|
|
610
507
|
*/
|
|
611
|
-
|
|
508
|
+
onIncomingCall(callback) {
|
|
612
509
|
return this.registerEvent('onIncomingCall', callback);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
|
|
510
|
+
}
|
|
511
|
+
onPresenceChanged(id, callback) {
|
|
512
|
+
const ids = [];
|
|
616
513
|
if (typeof id === 'function') {
|
|
617
514
|
callback = id;
|
|
618
515
|
}
|
|
619
516
|
else if (Array.isArray(id)) {
|
|
620
|
-
ids.push
|
|
517
|
+
ids.push(...id);
|
|
621
518
|
}
|
|
622
519
|
else {
|
|
623
520
|
ids.push(id);
|
|
@@ -625,14 +522,14 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
625
522
|
if (ids.length) {
|
|
626
523
|
this.subscribePresence(ids);
|
|
627
524
|
}
|
|
628
|
-
return this.registerEvent(exposed_enum_1.ExposedFn.onPresenceChanged,
|
|
525
|
+
return this.registerEvent(exposed_enum_1.ExposedFn.onPresenceChanged, (presence) => {
|
|
629
526
|
// Only group events
|
|
630
527
|
if (ids.length && !ids.includes(presence.id)) {
|
|
631
528
|
return;
|
|
632
529
|
}
|
|
633
530
|
callback(presence);
|
|
634
531
|
});
|
|
635
|
-
}
|
|
532
|
+
}
|
|
636
533
|
/**
|
|
637
534
|
* Subscribe presence of a contact or group to use in onPresenceChanged (see {@link onPresenceChanged})
|
|
638
535
|
*
|
|
@@ -652,73 +549,58 @@ var ListenerLayer = /** @class */ (function (_super) {
|
|
|
652
549
|
* @param id contact id (xxxxx@c.us) or group id: xxxxx-yyyy@g.us
|
|
653
550
|
* @returns number of subscribed
|
|
654
551
|
*/
|
|
655
|
-
|
|
656
|
-
return
|
|
657
|
-
|
|
658
|
-
switch (_a.label) {
|
|
659
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (id) { return WAPI.subscribePresence(id); }, id)];
|
|
660
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
661
|
-
}
|
|
662
|
-
});
|
|
663
|
-
});
|
|
664
|
-
};
|
|
552
|
+
async subscribePresence(id) {
|
|
553
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, (id) => WAPI.subscribePresence(id), id);
|
|
554
|
+
}
|
|
665
555
|
/**
|
|
666
556
|
* Unsubscribe presence of a contact or group to use in onPresenceChanged (see {@link onPresenceChanged})
|
|
667
557
|
* @param id contact id (xxxxx@c.us) or group id: xxxxx-yyyy@g.us
|
|
668
558
|
* @returns number of unsubscribed
|
|
669
559
|
*/
|
|
670
|
-
|
|
671
|
-
return
|
|
672
|
-
|
|
673
|
-
switch (_a.label) {
|
|
674
|
-
case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (id) { return WAPI.unsubscribePresence(id); }, id)];
|
|
675
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
};
|
|
560
|
+
async unsubscribePresence(id) {
|
|
561
|
+
return await (0, helpers_1.evaluateAndReturn)(this.page, (id) => WAPI.unsubscribePresence(id), id);
|
|
562
|
+
}
|
|
680
563
|
/**
|
|
681
564
|
* @event Listens to message revocation
|
|
682
565
|
* @returns Disposable object to stop the listening
|
|
683
566
|
*/
|
|
684
|
-
|
|
567
|
+
onRevokedMessage(callback) {
|
|
685
568
|
return this.registerEvent('onRevokedMessage', callback);
|
|
686
|
-
}
|
|
569
|
+
}
|
|
687
570
|
/**
|
|
688
571
|
* @event Listens to message reactions
|
|
689
572
|
* @returns Disposable object to stop the listening
|
|
690
573
|
*/
|
|
691
|
-
|
|
574
|
+
onReactionMessage(callback) {
|
|
692
575
|
return this.registerEvent('onReactionMessage', callback);
|
|
693
|
-
}
|
|
576
|
+
}
|
|
694
577
|
/**
|
|
695
578
|
* @event Listens to poll response messages
|
|
696
579
|
* @returns Disposable object to stop the listening
|
|
697
580
|
*/
|
|
698
|
-
|
|
581
|
+
onPollResponse(callback) {
|
|
699
582
|
return this.registerEvent('onPollResponse', callback);
|
|
700
|
-
}
|
|
583
|
+
}
|
|
701
584
|
/**
|
|
702
585
|
* @event Listens to update label
|
|
703
586
|
* @returns Disposable object to stop the listening
|
|
704
587
|
*/
|
|
705
|
-
|
|
588
|
+
onUpdateLabel(callback) {
|
|
706
589
|
return this.registerEvent('onUpdateLabel', callback);
|
|
707
|
-
}
|
|
590
|
+
}
|
|
708
591
|
/**
|
|
709
592
|
* @event Listens to update order status
|
|
710
593
|
* @returns Disposable object to stop the listening
|
|
711
594
|
*/
|
|
712
|
-
|
|
595
|
+
onOrderStatusUpdate(callback) {
|
|
713
596
|
return this.registerEvent('onOrderStatusUpdate', callback);
|
|
714
|
-
}
|
|
597
|
+
}
|
|
715
598
|
/**
|
|
716
599
|
* @event Listens to chats being added to ChatStore (Cache Layer)
|
|
717
600
|
* @returns Disposable object to stop the listening
|
|
718
601
|
*/
|
|
719
|
-
|
|
602
|
+
onNewChat(callback) {
|
|
720
603
|
return this.registerEvent('onNewChat', callback);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
}(profile_layer_1.ProfileLayer));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
724
606
|
exports.ListenerLayer = ListenerLayer;
|