-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added phoneWatchdog verification
- Loading branch information
1 parent
62dc4dd
commit 6616fa2
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This file is part of WPPConnect. | ||
* | ||
* WPPConnect is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* WPPConnect is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
let timer = null; | ||
let pong = true; | ||
|
||
async function sendPing() { | ||
return window.WAPI.waitForStore(['State', 'Stream'], () => { | ||
console.log(window.Store.Stream.mode, window.Store.State.default.state); | ||
// Check only if the interface is in CHAT and not disconnected | ||
if ( | ||
window.Store.Stream.mode !== 'MAIN' || | ||
window.Store.State.default.state === 'TIMEOUT' | ||
) { | ||
return; | ||
} | ||
|
||
// Start phoneWatchdog if ping fails | ||
if (!pong) { | ||
window.Store.State.default.phoneWatchdog.activate(); | ||
window.Store.State.default.phoneWatchdog.poke(250); | ||
return; | ||
} | ||
|
||
// Reset ping state | ||
pong = false; | ||
|
||
// Send a ping request | ||
return window.Store.State.default | ||
.sendBasic({ | ||
tag: window.Store.State.default.tag('ping'), | ||
data: ['admin', 'test'], | ||
}) | ||
.then(() => { | ||
pong = true; | ||
}); | ||
}); | ||
} | ||
|
||
export function startPhoneWatchdog(interval = 15000) { | ||
stopPhoneWatchdog(); | ||
|
||
timer = setInterval(sendPing, interval); | ||
} | ||
|
||
export function stopPhoneWatchdog() { | ||
if (timer) { | ||
clearInterval(timer); | ||
} | ||
timer = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6616fa2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref #89