mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
migrated socket IO initialization to typescript
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
"@types/jsonwebtoken": "^8.5.0",
|
"@types/jsonwebtoken": "^8.5.0",
|
||||||
"@types/multer": "^1.4.4",
|
"@types/multer": "^1.4.4",
|
||||||
"@types/node": "^14.10.1",
|
"@types/node": "^14.10.1",
|
||||||
|
"@types/socket.io": "^2.1.11",
|
||||||
"@types/validator": "^13.1.0",
|
"@types/validator": "^13.1.0",
|
||||||
"@types/yup": "^0.29.7",
|
"@types/yup": "^0.29.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.1.0",
|
"@typescript-eslint/eslint-plugin": "^4.1.0",
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
let io;
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
init: httpServer => {
|
|
||||||
io = require("socket.io")(httpServer);
|
|
||||||
return io;
|
|
||||||
},
|
|
||||||
getIO: () => {
|
|
||||||
if (!io) {
|
|
||||||
throw new Error("Socket IO not initialized");
|
|
||||||
}
|
|
||||||
return io;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
15
backend/src/libs/socket.ts
Normal file
15
backend/src/libs/socket.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import socketIo, { Server as SocketIO } from "socket.io";
|
||||||
|
import { Server } from "http";
|
||||||
|
|
||||||
|
let io: SocketIO;
|
||||||
|
|
||||||
|
export const initIO = (httpServer: Server): SocketIO => {
|
||||||
|
io = socketIo(httpServer);
|
||||||
|
return io;
|
||||||
|
};
|
||||||
|
export const getIO = (): SocketIO => {
|
||||||
|
if (!io) {
|
||||||
|
throw new Error("Socket IO not initialized");
|
||||||
|
}
|
||||||
|
return io;
|
||||||
|
};
|
||||||
@@ -4,11 +4,12 @@ import "express-async-errors";
|
|||||||
import express, { Request, Response, NextFunction } from "express";
|
import express, { Request, Response, NextFunction } from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
|
|
||||||
import uploadConfig from "./config/upload";
|
import uploadConfig from "./config/upload";
|
||||||
import AppError from "./errors/AppError";
|
import AppError from "./errors/AppError";
|
||||||
import routes from "./routes";
|
import routes from "./routes";
|
||||||
|
import { initIO } from "./libs/socket";
|
||||||
import "./database";
|
import "./database";
|
||||||
|
|
||||||
// import path from "path";
|
// import path from "path";
|
||||||
@@ -43,23 +44,23 @@ const server = app.listen(process.env.PORT, () => {
|
|||||||
console.log(`Server started on port: ${process.env.PORT}`);
|
console.log(`Server started on port: ${process.env.PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// const io = require("./libs/socket").init(server);
|
const io = initIO(server);
|
||||||
// io.on("connection", socket => {
|
io.on("connection", socket => {
|
||||||
// console.log("Client Connected");
|
console.log("Client Connected");
|
||||||
// socket.on("joinChatBox", ticketId => {
|
socket.on("joinChatBox", ticketId => {
|
||||||
// console.log("A client joined a ticket channel");
|
console.log("A client joined a ticket channel");
|
||||||
// socket.join(ticketId);
|
socket.join(ticketId);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// socket.on("joinNotification", () => {
|
socket.on("joinNotification", () => {
|
||||||
// console.log("A client joined notification channel");
|
console.log("A client joined notification channel");
|
||||||
// socket.join("notification");
|
socket.join("notification");
|
||||||
// });
|
});
|
||||||
|
|
||||||
// socket.on("disconnect", () => {
|
socket.on("disconnect", () => {
|
||||||
// console.log("Client disconnected");
|
console.log("Client disconnected");
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const startWhatsAppSessions = async () => {
|
// const startWhatsAppSessions = async () => {
|
||||||
// const whatsapps = await Whatsapp.findAll();
|
// const whatsapps = await Whatsapp.findAll();
|
||||||
|
|||||||
@@ -189,6 +189,13 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/express" "*"
|
"@types/express" "*"
|
||||||
|
|
||||||
|
"@types/engine.io@*":
|
||||||
|
version "3.1.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/engine.io/-/engine.io-3.1.4.tgz#3d9472711d179daa7c95c051e50ad411e18a9bdc"
|
||||||
|
integrity sha512-98rXVukLD6/ozrQ2O80NAlWDGA4INg+tqsEReWJldqyi2fulC9V7Use/n28SWgROXKm6003ycWV4gZHoF8GA6w==
|
||||||
|
dependencies:
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/express-serve-static-core@*":
|
"@types/express-serve-static-core@*":
|
||||||
version "4.17.12"
|
version "4.17.12"
|
||||||
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.12.tgz#9a487da757425e4f267e7d1c5720226af7f89591"
|
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.12.tgz#9a487da757425e4f267e7d1c5720226af7f89591"
|
||||||
@@ -265,6 +272,14 @@
|
|||||||
"@types/express-serve-static-core" "*"
|
"@types/express-serve-static-core" "*"
|
||||||
"@types/mime" "*"
|
"@types/mime" "*"
|
||||||
|
|
||||||
|
"@types/socket.io@^2.1.11":
|
||||||
|
version "2.1.11"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/socket.io/-/socket.io-2.1.11.tgz#e0d6759880e5f9818d5297a3328b36641bae996b"
|
||||||
|
integrity sha512-bVprmqPhJMLb9ZCm8g0Xy8kwBFRbnanOWSxzWkDkkIwxTvud5tKMfAJymXX6LQbizUKCS1yima7JM4BeLqjNqA==
|
||||||
|
dependencies:
|
||||||
|
"@types/engine.io" "*"
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/strip-bom@^3.0.0":
|
"@types/strip-bom@^3.0.0":
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2"
|
resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2"
|
||||||
|
|||||||
Reference in New Issue
Block a user