feat: new connections page to handle multiple whats

This commit is contained in:
canove
2020-09-05 14:41:55 -03:00
parent 8786c7ca5e
commit b8ff993e6f
9 changed files with 335 additions and 119 deletions

View File

@@ -133,7 +133,7 @@ const handleMessage = async (msg, ticket, contact) => {
};
const wbotMessageListener = dbSession => {
const wbot = getWbot(dbSession.name);
const wbot = getWbot(dbSession.id);
const io = getIO();
wbot.on("message_create", async msg => {

View File

@@ -7,11 +7,12 @@ const { getWbot, init } = require("../libs/wbot");
const wbotMonitor = dbSession => {
const io = getIO();
const wbot = getWbot(dbSession.name);
const sessionName = dbSession.name;
const wbot = getWbot(dbSession.id);
try {
wbot.on("change_state", async newState => {
console.log("monitor", newState);
console.log("Monitor session:", sessionName, newState);
try {
await dbSession.update({ status: newState });
} catch (err) {
@@ -27,7 +28,9 @@ const wbotMonitor = dbSession => {
wbot.on("change_battery", async batteryInfo => {
const { battery, plugged } = batteryInfo;
console.log(`Battery: ${battery}% - Charging? ${plugged}`);
console.log(
`Battery session: ${sessionName} ${battery}% - Charging? ${plugged}`
);
try {
await dbSession.update({ battery, plugged });
@@ -43,7 +46,7 @@ const wbotMonitor = dbSession => {
});
wbot.on("disconnected", async reason => {
console.log("disconnected", reason);
console.log("Disconnected session:", sessionName, reason);
try {
await dbSession.update({ status: "disconnected" });
} catch (err) {
@@ -52,7 +55,7 @@ const wbotMonitor = dbSession => {
}
io.emit("session", {
action: "logout",
action: "update",
session: dbSession,
});
@@ -60,7 +63,7 @@ const wbotMonitor = dbSession => {
() =>
init(dbSession)
.then(() => {
wbotMessageListener();
wbotMessageListener(dbSession);
wbotMonitor(dbSession);
})
.catch(err => {