mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 12:39:20 +00:00
[FIX] Use STREAM module for getting connection state instead of removed Conn model
This commit is contained in:
@@ -5,7 +5,7 @@ const puppeteer = require('puppeteer');
|
|||||||
const moduleRaid = require('moduleraid/moduleraid');
|
const moduleRaid = require('moduleraid/moduleraid');
|
||||||
|
|
||||||
const Util = require('./util/Util');
|
const Util = require('./util/Util');
|
||||||
const { WhatsWebURL, UserAgent, DefaultOptions, Events } = require('./util/Constants');
|
const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } = require('./util/Constants');
|
||||||
const { ExposeStore, LoadCustomSerializers } = require('./util/Injected');
|
const { ExposeStore, LoadCustomSerializers } = require('./util/Injected');
|
||||||
const ChatFactory = require('./factories/ChatFactory');
|
const ChatFactory = require('./factories/ChatFactory');
|
||||||
const Chat = require('./structures/Chat');
|
const Chat = require('./structures/Chat');
|
||||||
@@ -110,8 +110,9 @@ class Client extends EventEmitter {
|
|||||||
this.emit(Events.MESSAGE_RECEIVED, message);
|
this.emit(Events.MESSAGE_RECEIVED, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.exposeFunction('onConnectionChangedEvent', (conn, connected) => {
|
await page.exposeFunction('onAppStateChangedEvent', (AppState, state) => {
|
||||||
if (!connected) {
|
const ACCEPTED_STATES = [WAState.CONNECTED, WAState.OPENING, WAState.PAIRING];
|
||||||
|
if (!ACCEPTED_STATES.includes(state)) {
|
||||||
this.emit(Events.DISCONNECTED);
|
this.emit(Events.DISCONNECTED);
|
||||||
this.destroy();
|
this.destroy();
|
||||||
}
|
}
|
||||||
@@ -119,7 +120,7 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
Store.Msg.on('add', onAddMessageEvent);
|
Store.Msg.on('add', onAddMessageEvent);
|
||||||
Store.Conn.on('change:connected', onConnectionChangedEvent);
|
Store.AppState.on('change:state', onAppStateChangedEvent);
|
||||||
}).catch(err => console.log(err.message));
|
}).catch(err => console.log(err.message));
|
||||||
|
|
||||||
this.pupBrowser = browser;
|
this.pupBrowser = browser;
|
||||||
|
|||||||
@@ -42,3 +42,18 @@ exports.ChatTypes = {
|
|||||||
GROUP: 'group',
|
GROUP: 'group',
|
||||||
UNKNOWN: 'unknown'
|
UNKNOWN: 'unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.WAState = {
|
||||||
|
CONFLICT: "CONFLICT",
|
||||||
|
CONNECTED: "CONNECTED",
|
||||||
|
DEPRECATED_VERSION: "DEPRECATED_VERSION",
|
||||||
|
OPENING: "OPENING",
|
||||||
|
PAIRING: "PAIRING",
|
||||||
|
PROXYBLOCK: "PROXYBLOCK",
|
||||||
|
SMB_TOS_BLOCK: "SMB_TOS_BLOCK",
|
||||||
|
TIMEOUT: "TIMEOUT",
|
||||||
|
TOS_BLOCK: "TOS_BLOCK",
|
||||||
|
UNLAUNCHED: "UNLAUNCHED",
|
||||||
|
UNPAIRED: "UNPAIRED",
|
||||||
|
UNPAIRED_IDLE: "UNPAIRED_IDLE"
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
eval("var moduleRaid = " + moduleRaidStr);
|
eval("var moduleRaid = " + moduleRaidStr);
|
||||||
window.mR = moduleRaid();
|
window.mR = moduleRaid();
|
||||||
window.Store = window.mR.findModule("Chat")[1].default;
|
window.Store = window.mR.findModule("Chat")[1].default;
|
||||||
|
window.Store.AppState = window.mR.findModule("STREAM")[0].default;
|
||||||
|
|
||||||
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
|
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
|
||||||
window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
|
window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
|
||||||
|
|||||||
Reference in New Issue
Block a user