Backend folders organize and finshed send audio

This commit is contained in:
canove
2020-07-08 11:19:08 -03:00
parent 87e4537ce2
commit c9cc973088
38 changed files with 61 additions and 21 deletions

View File

@@ -0,0 +1,50 @@
const Whatsapp = require("../models/Whatsapp");
const wbotMessageListener = require("./wbotMessageListener");
const { getIO } = require("../libs/socket");
const { getWbot, init } = require("../libs/wbot");
const wbotMonitor = () => {
const io = getIO();
const wbot = getWbot();
try {
wbot.on("change_state", newState => {
console.log("monitor", newState);
});
wbot.on("change_battery", async batteryInfo => {
// Battery percentage for attached device has changed
const { battery, plugged } = batteryInfo;
try {
await Whatsapp.update({ battery, plugged }, { where: { id: 1 } });
} catch (err) {
console.log(err);
}
console.log(`Battery: ${battery}% - Charging? ${plugged}`); //todo> save batery state to db
});
wbot.on("disconnected", reason => {
console.log("disconnected", reason); //todo> save connection status to DB
setTimeout(
() =>
init()
.then(res => {
wbotMessageListener();
wbotMonitor();
})
.catch(err => console.log(err)),
2000
);
});
// setInterval(() => {
// wbot.resetState();
// }, 20000);
} catch (err) {
console.log(err);
}
};
module.exports = wbotMonitor;