mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
use appError on socket io
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import socketIo, { Server as SocketIO } from "socket.io";
|
import socketIo, { Server as SocketIO } from "socket.io";
|
||||||
import { Server } from "http";
|
import { Server } from "http";
|
||||||
|
import AppError from "../errors/AppError";
|
||||||
|
|
||||||
let io: SocketIO;
|
let io: SocketIO;
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ export const initIO = (httpServer: Server): SocketIO => {
|
|||||||
};
|
};
|
||||||
export const getIO = (): SocketIO => {
|
export const getIO = (): SocketIO => {
|
||||||
if (!io) {
|
if (!io) {
|
||||||
throw new Error("Socket IO not initialized");
|
throw new AppError("Socket IO not initialized");
|
||||||
}
|
}
|
||||||
return io;
|
return io;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ module.exports = {
|
|||||||
|
|
||||||
const wbot = new Client({
|
const wbot = new Client({
|
||||||
session: sessionCfg,
|
session: sessionCfg,
|
||||||
restartOnAuthFail: true,
|
restartOnAuthFail: true
|
||||||
});
|
});
|
||||||
wbot.initialize();
|
wbot.initialize();
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ module.exports = {
|
|||||||
|
|
||||||
io.emit("whatsappSession", {
|
io.emit("whatsappSession", {
|
||||||
action: "update",
|
action: "update",
|
||||||
session: whatsapp,
|
session: whatsapp
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,12 +46,12 @@ module.exports = {
|
|||||||
|
|
||||||
await whatsapp.update({
|
await whatsapp.update({
|
||||||
session: JSON.stringify(session),
|
session: JSON.stringify(session),
|
||||||
status: "authenticated",
|
status: "authenticated"
|
||||||
});
|
});
|
||||||
|
|
||||||
io.emit("whatsappSession", {
|
io.emit("whatsappSession", {
|
||||||
action: "update",
|
action: "update",
|
||||||
session: whatsapp,
|
session: whatsapp
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -66,12 +66,12 @@ module.exports = {
|
|||||||
|
|
||||||
await whatsapp.update({
|
await whatsapp.update({
|
||||||
status: "CONNECTED",
|
status: "CONNECTED",
|
||||||
qrcode: "",
|
qrcode: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
io.emit("whatsappSession", {
|
io.emit("whatsappSession", {
|
||||||
action: "update",
|
action: "update",
|
||||||
session: whatsapp,
|
session: whatsapp
|
||||||
});
|
});
|
||||||
|
|
||||||
wbot.sendPresenceAvailable();
|
wbot.sendPresenceAvailable();
|
||||||
@@ -106,5 +106,5 @@ module.exports = {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user