|
@@ -1,66 +1,66 @@
|
|
|
-import http from "http";
|
|
|
-import bcrypt from "bcrypt";
|
|
|
-import { Server } from "socket.io";
|
|
|
-import { instrument, RedisStore } from "@socket.io/admin-ui";
|
|
|
-import { createAdapter } from "@socket.io/redis-adapter";
|
|
|
-import { pubClient, subClient } from "../connection/redis.js";
|
|
|
-import { logger } from "./logger.js";
|
|
|
-import customParser from "socket.io-msgpack-parser";
|
|
|
-
|
|
|
-// import { PrometheusSocketIo } from 'socket.io-prometheus-v3';
|
|
|
-
|
|
|
-console.log("process.env.SOCKET_PATH", process.env.SOCKET_PATH);
|
|
|
-
|
|
|
-// console.log('PrometheusSocketIo',PrometheusSocketIo)
|
|
|
-
|
|
|
-
|
|
|
-const httpServer = http.createServer();
|
|
|
-const io = new Server(httpServer, {
|
|
|
- cors: {
|
|
|
- origin: "*",
|
|
|
- },
|
|
|
- path: process.env.SOCKET_PATH || "",
|
|
|
- pingInterval: 10000,
|
|
|
- pingTimeout: 5000,
|
|
|
- parser: customParser,
|
|
|
-});
|
|
|
-
|
|
|
-instrument(io, {
|
|
|
- auth: {
|
|
|
- type: "basic",
|
|
|
- username: process.env.WATCH_USER,
|
|
|
- password: bcrypt.hashSync(process.env.WATCH_PASSWORD, 10),
|
|
|
- },
|
|
|
- namespaceName: "/watch",
|
|
|
-});
|
|
|
-
|
|
|
-// const prometheus = PrometheusSocketIo.init({
|
|
|
-// io, // io.Server
|
|
|
-// collectDefaultMetrics: false // Collect some Node.js-specific metrics.
|
|
|
-// })
|
|
|
-// console.log('prometheus',prometheus)
|
|
|
-Server.prototype.ready = function(){
|
|
|
- return new Promise((resolve,reject)=>{
|
|
|
- Promise.all([pubClient.connect(), subClient.connect()])
|
|
|
- .then(() => {
|
|
|
- io.adapter(createAdapter(pubClient, subClient));
|
|
|
- logger.info("redis is conetcted");
|
|
|
- resolve(true);
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- reject(error);
|
|
|
- logger.error("redis is connect fail", error);
|
|
|
- });
|
|
|
- })
|
|
|
-}
|
|
|
-// Promise.all([pubClient.connect(), subClient.connect()])
|
|
|
-// .then(() => {
|
|
|
-// io.adapter(createAdapter(pubClient, subClient));
|
|
|
-// logger.info("redis is conetcted");
|
|
|
-
|
|
|
-// })
|
|
|
-// .catch((error) => {
|
|
|
-// logger.error("redis is connect fail", error);
|
|
|
-// });
|
|
|
-
|
|
|
-export { io };
|
|
|
+import http from "http";
|
|
|
+import bcrypt from "bcrypt";
|
|
|
+import { Server } from "socket.io";
|
|
|
+import { instrument, RedisStore } from "@socket.io/admin-ui";
|
|
|
+import { createAdapter } from "@socket.io/redis-adapter";
|
|
|
+import { pubClient, subClient } from "../connection/redis.js";
|
|
|
+import { logger } from "./logger.js";
|
|
|
+import customParser from "socket.io-msgpack-parser";
|
|
|
+
|
|
|
+// import { PrometheusSocketIo } from 'socket.io-prometheus-v3';
|
|
|
+
|
|
|
+console.log("process.env.SOCKET_PATH", process.env.SOCKET_PATH);
|
|
|
+
|
|
|
+// console.log('PrometheusSocketIo',PrometheusSocketIo)
|
|
|
+
|
|
|
+const httpServer = http.createServer();
|
|
|
+const io = new Server(httpServer, {
|
|
|
+ cors: {
|
|
|
+ origin: "*",
|
|
|
+ },
|
|
|
+ path: process.env.SOCKET_PATH || "",
|
|
|
+ pingInterval: 10000,
|
|
|
+ pingTimeout: 5000,
|
|
|
+ parser: customParser,
|
|
|
+ transports: ["websocket"],
|
|
|
+});
|
|
|
+
|
|
|
+instrument(io, {
|
|
|
+ auth: {
|
|
|
+ type: "basic",
|
|
|
+ username: process.env.WATCH_USER,
|
|
|
+ password: bcrypt.hashSync(process.env.WATCH_PASSWORD, 10),
|
|
|
+ },
|
|
|
+ namespaceName: "/watch",
|
|
|
+});
|
|
|
+
|
|
|
+// const prometheus = PrometheusSocketIo.init({
|
|
|
+// io, // io.Server
|
|
|
+// collectDefaultMetrics: false // Collect some Node.js-specific metrics.
|
|
|
+// })
|
|
|
+// console.log('prometheus',prometheus)
|
|
|
+Server.prototype.ready = function () {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ Promise.all([pubClient.connect(), subClient.connect()])
|
|
|
+ .then(() => {
|
|
|
+ io.adapter(createAdapter(pubClient, subClient));
|
|
|
+ logger.info("redis is conetcted");
|
|
|
+ resolve(true);
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ reject(error);
|
|
|
+ logger.error("redis is connect fail", error);
|
|
|
+ });
|
|
|
+ });
|
|
|
+};
|
|
|
+// Promise.all([pubClient.connect(), subClient.connect()])
|
|
|
+// .then(() => {
|
|
|
+// io.adapter(createAdapter(pubClient, subClient));
|
|
|
+// logger.info("redis is conetcted");
|
|
|
+
|
|
|
+// })
|
|
|
+// .catch((error) => {
|
|
|
+// logger.error("redis is connect fail", error);
|
|
|
+// });
|
|
|
+
|
|
|
+export { io };
|