瀏覽代碼

dump file prepere

gemercheung 3 年之前
父節點
當前提交
5a39161293

+ 8 - 11
src/controller/basicController.js

@@ -1,24 +1,21 @@
 import { pubClient } from "../connection/redis.js";
 import { ROLES, CODEMEG, EVENT, FROMTYPE } from "../enum/index.js";
-import { roomController } from "./roomController.js";
+// import { roomController } from "./dump/roomController.jser.js";
 import { syncActionController } from "./syncActionController.js";
 import { logger } from "../core/logger.js";
 import { getSig } from "../core/getSig.js";
 
-
 export class BasicController {
-  constructor(io,socket,pubClient){
-    this.io = io
-    this.socket = socket
-    this.redisCli = pubClient
-    this.logger = logger
-    this.getSig = getSig
+  constructor(io, socket, pubClient) {
+    this.io = io;
+    this.socket = socket;
+    this.redisCli = pubClient;
+    this.logger = logger;
+    this.getSig = getSig;
   }
 
   isHoster = (role) => {
     return String(role).toLowerCase() === ROLES.LEADER;
   };
-  run (){
-
-  }
+  run() {}
 }

+ 0 - 1
src/controller/connectController.js

@@ -14,7 +14,6 @@ export class ConnectController extends BasicController {
     await syncActionController(this.socket);
     this.socket.on("disconnect", (reason) => {
       if (reason === "transport close") {
-        console.log('this.roomController.user.from',this.roomController.user.from)
         if ([FROMTYPE.MiniAPP].includes(Number(this.roomController.user.from))) {
           this.roomController.logger.info("主动断开连接");
           this.roomController.roomAssistant.disconnect();

src/controller/basicsController.js → src/controller/dump/basicsController.js


src/controller/roomActionController.js → src/controller/dump/roomActionController.js


src/controller/roomAssistantController.js → src/controller/dump/roomAssistantController.js


src/controller/roomController.js → src/controller/dump/roomController.js


src/controller/roomStatusController.js → src/controller/dump/roomStatusController.js


+ 9 - 2
src/controller/errorController.js

@@ -1,3 +1,10 @@
-export async function errorController(socket) {
-  console.log("socket", socket);
+import { BasicController } from "./basicController.js";
+
+export class ErrorController extends BasicController {
+  constructor(...args) {
+    super(...args);
+  }
+  run() {
+    
+  }
 }

+ 3 - 2
src/controller/index.js

@@ -1,7 +1,7 @@
 import { io } from "../core/io.js";
 import { pubClient } from "../connection/redis.js";
 import { ConnectController } from "./connectController.js";
-// import { BasicController } from "./basicController.js";
+import { ErrorController } from "./errorController.js";
 
 // import { errorController } from "./errorController.js";
 
@@ -14,7 +14,8 @@ class mainController {
   run() {
     try {
       this.io.on("connection", (socket) => new ConnectController(this.io, socket, pubClient).run());
-      // this.io.on("disconnect", (socket) => new DisConnectController(this.io, socket, pubClient).run());
+      this.io.on("connect_error", (socket) => new ErrorController(this.io, socket, pubClient).run());
+      this.io.on("error", (socket) => new ErrorController(this.io, socket, pubClient).run());
 
       // this.io.on("connect_error", this.errorController);
       // this.io.on("error", this.errorController);

+ 6 - 8
src/controller/room/index.js

@@ -84,12 +84,11 @@ export class RoomController extends BasicController {
       // socket.broadcast.to(roomUniqueId).emit(EVENT.webSyncAction, data);
       try {
         if ([FROMTYPE.base].includes(Number(this.user.from))) {
-            this.socket.broadcast.to(this.roomId).emit(EVENT.webSyncAction, data);
-          }
+          this.socket.broadcast.to(this.roomId).emit(EVENT.webSyncAction, data);
+        }
       } catch (error) {
-          this.logger.error('roomController::EVENT.webSyncAction',error)
+        this.logger.error("roomController::EVENT.webSyncAction", error);
       }
-    
     });
     // 转发action
     this.socket.on(EVENT.action, (data) => {
@@ -101,7 +100,7 @@ export class RoomController extends BasicController {
           this.logger.error("action 事件不在房间内", this.user);
         }
       } catch (error) {
-          this.logger.error('roomController::EVENT.action',error)
+        this.logger.error("roomController::EVENT.action", error);
       }
     });
 
@@ -121,8 +120,7 @@ export class RoomController extends BasicController {
     }
   }
 
-  roomMasterAutoRejoin(){
-      
+  roomMasterAutoRejoin() {
+    // const
   }
-  
 }

+ 25 - 25
src/core/logger.js

@@ -22,12 +22,12 @@ const formatMeta = (meta) => {
 
 const customFormat = format.printf(({ timestamp, level, message, label = "", ...meta }) => `[${timestamp}] ${level} ${label} ${message} ${formatMeta(meta)}`);
 
-const apm = APM.start({
-  serverUrl: 'http://localhost:8200',
-  // Set the service environment
-  environment: 'production'
-  // NDNpS0lZQUJPcU1OdjVQSHhKeGY6N3ZuVWNIVWpTc0dRZ2pIa0tBckxOQQ==
-})
+// const apm = APM.start({
+//   serverUrl: 'http://localhost:8200',
+//   // Set the service environment
+//   environment: 'production'
+//   // NDNpS0lZQUJPcU1OdjVQSHhKeGY6N3ZuVWNIVWpTc0dRZ2pIa0tBckxOQQ==
+// })
 
 // const client = new Client({
 //   node: 'http://localhost:9200',
@@ -35,24 +35,24 @@ const apm = APM.start({
 // })
 
 
-const esTransportOpts = {
-  level: 'info',
-  indexPrefix: 'logging-api',
-  indexSuffixPattern: 'YYYY-MM-DD',
-  clientOpts : {
-      node: 'http://localhost:9200',
-      maxRetries: 5,
-      requestTimeout: 10000,
-      sniffOnStart: false,
-      // apiKey: 'SDNncElZQUJPcU1OdjVQSFRaY0I6MGpLUWg2TldSS0tTSjdRS0FfZGZGdw=='
-      auth: {
-          username: 'elastic',
-          password: 'changeme'
-      }
-  },
-  source: 'socket-api'
-}
-const esTransport = new ElasticsearchTransport(esTransportOpts);
+// const esTransportOpts = {
+//   level: 'info',
+//   indexPrefix: 'logging-api',
+//   indexSuffixPattern: 'YYYY-MM-DD',
+//   clientOpts : {
+//       node: 'http://localhost:9200',
+//       maxRetries: 5,
+//       requestTimeout: 10000,
+//       sniffOnStart: false,
+//       // apiKey: 'SDNncElZQUJPcU1OdjVQSFRaY0I6MGpLUWg2TldSS0tTSjdRS0FfZGZGdw=='
+//       auth: {
+//           username: 'elastic',
+//           password: 'changeme'
+//       }
+//   },
+//   source: 'socket-api'
+// }
+// const esTransport = new ElasticsearchTransport(esTransportOpts);
 
 
 const logger = createLogger({
@@ -73,7 +73,7 @@ const logger = createLogger({
     new transports.File({
       filename: join(__dirname, "../../logs/combined.log"),
     }),
-    esTransport
+    // esTransport
   ],
 });
 export { logger };