comment websocket
This commit is contained in:
parent
4647120172
commit
ad6d694c51
2 changed files with 37 additions and 37 deletions
46
src/app.ts
46
src/app.ts
|
|
@ -12,9 +12,9 @@ import { RegisterRoutes } from "./routes";
|
|||
import { OrganizationController } from "./controllers/OrganizationController";
|
||||
import logMiddleware from "./middlewares/logs";
|
||||
import { CommandController } from "./controllers/CommandController";
|
||||
import { WebSocketServer } from "ws";
|
||||
import http from "http";
|
||||
export const wss = new WebSocketServer({ noServer: true });
|
||||
// import { WebSocketServer } from "ws";
|
||||
// import http from "http";
|
||||
// export const wss = new WebSocketServer({ noServer: true });
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
|
@ -90,30 +90,30 @@ async function main() {
|
|||
|
||||
runMessageQueue();
|
||||
|
||||
// สร้างเซิร์ฟเวอร์ HTTP
|
||||
const server = http.createServer(app);
|
||||
// // สร้างเซิร์ฟเวอร์ HTTP
|
||||
// const server = http.createServer(app);
|
||||
|
||||
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
||||
server.on("upgrade", (request:any, socket:any, head:any) => {
|
||||
console.log("🔹 Handling upgrade request...");
|
||||
wss.handleUpgrade(request, socket, head, (ws:any) => {
|
||||
console.log("🔹 WebSocket connection established");
|
||||
wss.emit("connection", ws, request);
|
||||
});
|
||||
});
|
||||
// // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
||||
// server.on("upgrade", (request:any, socket:any, head:any) => {
|
||||
// console.log("🔹 Handling upgrade request...");
|
||||
// wss.handleUpgrade(request, socket, head, (ws:any) => {
|
||||
// console.log("🔹 WebSocket connection established");
|
||||
// wss.emit("connection", ws, request);
|
||||
// });
|
||||
// });
|
||||
|
||||
wss.on("connection", (ws:any) => {
|
||||
console.log("✅ Client connected to WebSocket");
|
||||
// wss.on("connection", (ws:any) => {
|
||||
// console.log("✅ Client connected to WebSocket");
|
||||
|
||||
ws.on("close", () => {
|
||||
console.log("❌ Client disconnected");
|
||||
});
|
||||
});
|
||||
// ws.on("close", () => {
|
||||
// console.log("❌ Client disconnected");
|
||||
// });
|
||||
// });
|
||||
|
||||
// เริ่มเซิร์ฟเวอร์ที่พอร์ต 5000
|
||||
server.listen(APP_PORT, () => {
|
||||
console.log("✅ HTTP Server is listening on port 5000");
|
||||
});
|
||||
// // เริ่มเซิร์ฟเวอร์ที่พอร์ต 5000
|
||||
// server.listen(APP_PORT, () => {
|
||||
// console.log("✅ HTTP Server is listening on port 5000");
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue