mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 20:49:14 +00:00
feat: takeover on conflict
This adds funcitonality to takeover after a certain timeout if WhatsApp Web has been opened in another browser close #119
This commit is contained in:
@@ -286,6 +286,17 @@ class Client extends EventEmitter {
|
|||||||
this.emit(Events.STATE_CHANGED, state);
|
this.emit(Events.STATE_CHANGED, state);
|
||||||
|
|
||||||
const ACCEPTED_STATES = [WAState.CONNECTED, WAState.OPENING, WAState.PAIRING, WAState.TIMEOUT];
|
const ACCEPTED_STATES = [WAState.CONNECTED, WAState.OPENING, WAState.PAIRING, WAState.TIMEOUT];
|
||||||
|
|
||||||
|
if(this.options.takeoverOnConflict) {
|
||||||
|
ACCEPTED_STATES.push(WAState.CONFLICT);
|
||||||
|
|
||||||
|
if(state === WAState.CONFLICT) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.pupPage.evaluate(() => window.Store.AppState.takeover());
|
||||||
|
}, this.options.takeoverTimeoutMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!ACCEPTED_STATES.includes(state)) {
|
if (!ACCEPTED_STATES.includes(state)) {
|
||||||
/**
|
/**
|
||||||
* Emitted when the client has been disconnected
|
* Emitted when the client has been disconnected
|
||||||
@@ -298,9 +309,10 @@ class Client extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await page.exposeFunction('onBatteryStateChangedEvent', (state) => {
|
await page.exposeFunction('onBatteryStateChangedEvent', (state) => {
|
||||||
|
|
||||||
const { battery, plugged } = state;
|
const { battery, plugged } = state;
|
||||||
|
|
||||||
|
if(battery === undefined) return;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the battery percentage for the attached device changes
|
* Emitted when the battery percentage for the attached device changes
|
||||||
* @event Client#change_battery
|
* @event Client#change_battery
|
||||||
@@ -415,7 +427,7 @@ class Client extends EventEmitter {
|
|||||||
msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
|
msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
|
||||||
}
|
}
|
||||||
return msg.serialize();
|
return msg.serialize();
|
||||||
}, chatId, content, internalOptions, sendSeen);
|
}, chatId, content, internalOptions, sendSeen).catch(error => { throw error; });
|
||||||
|
|
||||||
return new Message(this, newMessage);
|
return new Message(this, newMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ exports.DefaultOptions = {
|
|||||||
qrTimeoutMs: 45000,
|
qrTimeoutMs: 45000,
|
||||||
qrRefreshIntervalMs: 20000,
|
qrRefreshIntervalMs: 20000,
|
||||||
authTimeoutMs: 45000,
|
authTimeoutMs: 45000,
|
||||||
|
takeoverOnConflict: false,
|
||||||
|
takeoverTimeoutMs: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user