gemercheung преди 3 години
родител
ревизия
1693800622

+ 1 - 1
.env.development

@@ -1,6 +1,6 @@
 PORT=3000
 VOLUME_DIR=./data
-REDIS_HOST=localhost
+REDIS_HOST=127.0.0.1
 REDIS_PORT=6379
 REDIS_PASSWORD=redis9394
 WATCH_USER=4dage

+ 8 - 0
.env.production

@@ -0,0 +1,8 @@
+PORT=3000
+VOLUME_DIR=./data
+REDIS_HOST=redis
+REDIS_PORT=6379
+REDIS_USER=redis
+REDIS_PASSWORD=s1mpl3
+WATCH_USER=4dage
+WATCH_PASSWORD=4dage168.

+ 1 - 0
.gitignore

@@ -1,6 +1,7 @@
 .DS_Store
 node_modules
 dist
+logs
 
 # local env files
 .env.local

+ 45 - 0
demo/client1.html

@@ -0,0 +1,45 @@
+<html>
+  <head>
+    <meta charset="UTF-8" />
+    <title>socket.io客户端</title>
+    <!-- <script src="./js/socket.io.js"></script> -->
+    <script
+      src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"
+      integrity="sha512-iqRVtNB+t9O+epcgUTIPF+nklypcR23H1yR1NFM9kffn6/iBhZ9bTB6oKLaGMv8JE9UgjcwfBFg/eHC/VMws+g=="
+      crossorigin="anonymous"
+      referrerpolicy="no-referrer"
+    ></script>
+  </head>
+
+  <body>
+    <iframe src="./index.html"></iframe>
+    </div>
+
+    <script>
+      localStorage.debug = "socket.io-client:socket";
+      // 'http://47.115.43.159:3000'
+      // var socket = io("http://0.0.0.0:3000");
+      // const { roomId, userId, sceneNum, isClient, role, userLimitNum, roomType } = user
+      var socket = io("http://0.0.0.0:3000", {
+        path: "/test",
+        query: {
+          userId: "user_001",
+          sceneNum: "t-GusppsiKEC",
+          role: "LEADER",
+          from: 1,
+          roomType: "normal",
+          nickName: "测试1",
+          roomId: "001",
+          myHeadUrl: "http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg",
+        },
+      });
+
+      socket.on("connect", function (data) {
+        console.log(data);
+      });
+
+    
+      
+    </script>
+  </body>
+</html>

+ 1 - 1
demo/index.html

@@ -31,7 +31,7 @@
           userId: "user_001",
           sceneNum: "t-GusppsiKEC",
           role: "LEADER",
-          isClient: false,
+          from: 0,
           roomType: "normal",
           nickName: "测试1",
           roomId: "001",

+ 1 - 1
demo/index2.html

@@ -27,7 +27,7 @@
           userId: "user_002",
           sceneNum: "t-GusppsiKEC",
           role: "AGENT",
-          isClient: true,
+          from: 0,
           roomType: "1v1",
           nickName: "测试1",
           roomId: "001",

+ 1 - 1
demo/index3.html

@@ -27,7 +27,7 @@
           userId: "user_003",
           sceneNum: "t-GusppsiKEC",
           role: "AGENT",
-          isClient: true,
+          from: 0,
           roomType: "1v1",
           nickName: "测试3",
           roomId: "001",

+ 0 - 153
logs/combined.log

@@ -1,153 +0,0 @@
-[Jan 24, 2022 11:30] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:30] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:30] debug  Master 8419 is running 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA8hxQ","isLogin":true}}
-[Jan 24, 2022 11:30] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:30] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:30] debug  Master 8465 is running 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  redis is conetcted 
-[Jan 24, 2022 11:30] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA8lZr","isLogin":true}}
-[Jan 24, 2022 11:31] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA8ocD","isLogin":true}}
-[Jan 24, 2022 11:31] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:31] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:31] debug  Master 8505 is running 
-[Jan 24, 2022 11:31] debug  redis is conetcted 
-[Jan 24, 2022 11:31] debug  redis is conetcted 
-[Jan 24, 2022 11:31] debug  redis is conetcted 
-[Jan 24, 2022 11:31] debug  redis is conetcted 
-[Jan 24, 2022 11:31] debug  redis is conetcted 
-[Jan 24, 2022 11:32] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA90JZ","isLogin":true}}
-[Jan 24, 2022 11:32] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:32] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:32] debug  Master 8547 is running 
-[Jan 24, 2022 11:32] debug  redis is conetcted 
-[Jan 24, 2022 11:32] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:32] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:32] debug  Master 8568 is running 
-[Jan 24, 2022 11:32] debug  redis is conetcted 
-[Jan 24, 2022 11:32] debug  redis is conetcted 
-[Jan 24, 2022 11:32] debug  redis is conetcted 
-[Jan 24, 2022 11:32] debug  redis is conetcted 
-[Jan 24, 2022 11:32] debug  redis is conetcted 
-[Jan 24, 2022 11:32] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA94wG","isLogin":true}}
-[Jan 24, 2022 11:34:59] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:34:59] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:34:59] debug  Master 8718 is running 
-[Jan 24, 2022 11:35:00] debug  redis is conetcted 
-[Jan 24, 2022 11:35:01] debug  redis is conetcted 
-[Jan 24, 2022 11:35:01] debug  redis is conetcted 
-[Jan 24, 2022 11:35:02] debug  redis is conetcted 
-[Jan 24, 2022 11:35:02] debug  redis is conetcted 
-[Jan 24, 2022 11:35:23] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA9n1r","isLogin":true}}
-[Jan 24, 2022 11:35:26] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:35:26] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:35:26] debug  Master 8804 is running 
-[Jan 24, 2022 11:35:26] debug  redis is conetcted 
-[Jan 24, 2022 11:35:28] debug  redis is conetcted 
-[Jan 24, 2022 11:35:28] debug  redis is conetcted 
-[Jan 24, 2022 11:35:28] debug  redis is conetcted 
-[Jan 24, 2022 11:35:28] debug  redis is conetcted 
-[Jan 24, 2022 11:35:29] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA9oWJ","isLogin":true}}
-[Jan 24, 2022 11:36:12] info  redis "redis://:redis9394@localhost:6379"
-[Jan 24, 2022 11:36:12] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:36:12] debug  Master 8848 is running 
-[Jan 24, 2022 11:36:13] debug  redis is conetcted 
-[Jan 24, 2022 11:36:16] debug  redis is conetcted 
-[Jan 24, 2022 11:36:16] debug  redis is conetcted 
-[Jan 24, 2022 11:36:16] debug  redis is conetcted 
-[Jan 24, 2022 11:36:16] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA9zUG","isLogin":true}}
-[Jan 24, 2022 11:36:16] debug  redis is conetcted 
-[Jan 24, 2022 11:36:41] info  redis {"0":"r","1":"e","2":"d","3":"i","4":"s","5":":","6":"/","7":"/","8":":","9":"r","10":"e","11":"d","12":"i","13":"s","14":"9","15":"3","16":"9","17":"4","18":"@","19":"l","20":"o","21":"c","22":"a","23":"l","24":"h","25":"o","26":"s","27":"t","28":":","29":"6","30":"3","31":"7","32":"9"}
-[Jan 24, 2022 11:36:41] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:36:41] debug  Master 8899 is running 
-[Jan 24, 2022 11:36:42] debug  redis is conetcted 
-[Jan 24, 2022 11:36:44] debug  redis is conetcted 
-[Jan 24, 2022 11:36:44] debug  redis is conetcted 
-[Jan 24, 2022 11:36:44] debug  redis is conetcted 
-[Jan 24, 2022 11:36:44] debug  redis is conetcted 
-[Jan 24, 2022 11:36:58] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:36:59] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:36:59] debug  Master 8937 is running 
-[Jan 24, 2022 11:36:59] debug  redis is conetcted 
-[Jan 24, 2022 11:37:01] debug  redis is conetcted 
-[Jan 24, 2022 11:37:01] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAA8uF","isLogin":true}}
-[Jan 24, 2022 11:37:01] debug  redis is conetcted 
-[Jan 24, 2022 11:37:01] debug  redis is conetcted 
-[Jan 24, 2022 11:37:01] debug  redis is conetcted 
-[Jan 24, 2022 11:37:32] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:37:32] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:37:32] debug  Master 8975 is running 
-[Jan 24, 2022 11:37:33] debug  redis is conetcted 
-[Jan 24, 2022 11:37:35] debug  redis is conetcted 
-[Jan 24, 2022 11:37:36] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:37:36] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:37:36] debug  Master 8997 is running 
-[Jan 24, 2022 11:37:37] debug  redis is conetcted 
-[Jan 24, 2022 11:37:38] debug  redis is conetcted 
-[Jan 24, 2022 11:37:38] debug  redis is conetcted 
-[Jan 24, 2022 11:37:38] debug  redis is conetcted 
-[Jan 24, 2022 11:37:38] debug  redis is conetcted 
-[Jan 24, 2022 11:37:48] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:37:49] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:37:49] debug  Master 9028 is running 
-[Jan 24, 2022 11:37:49] debug  redis is conetcted 
-[Jan 24, 2022 11:37:50] debug  redis is conetcted 
-[Jan 24, 2022 11:37:50] debug  redis is conetcted 
-[Jan 24, 2022 11:37:50] debug  redis is conetcted 
-[Jan 24, 2022 11:37:50] debug  redis is conetcted 
-[Jan 24, 2022 11:37:52] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAALPA","isLogin":true}}
-[Jan 24, 2022 11:38:00] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:38:00] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:38:00] debug  Master 9056 is running 
-[Jan 24, 2022 11:38:00] debug  redis is conetcted 
-[Jan 24, 2022 11:38:02] debug  redis is conetcted 
-[Jan 24, 2022 11:38:02] debug  redis is conetcted 
-[Jan 24, 2022 11:38:02] debug  redis is conetcted 
-[Jan 24, 2022 11:38:02] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAANi2","isLogin":true}}
-[Jan 24, 2022 11:38:02] debug  redis is conetcted 
-[Jan 24, 2022 11:38:15] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:38:15] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:38:15] debug  Master 9093 is running 
-[Jan 24, 2022 11:38:15] debug  redis is conetcted 
-[Jan 24, 2022 11:38:17] debug  redis is conetcted 
-[Jan 24, 2022 11:38:18] debug  redis is conetcted 
-[Jan 24, 2022 11:38:18] debug  redis is conetcted 
-[Jan 24, 2022 11:38:18] debug  redis is conetcted 
-[Jan 24, 2022 11:38:18] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAARkK","isLogin":true}}
-[Jan 24, 2022 11:38:47] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:38:47] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:38:47] debug  Master 9125 is running 
-[Jan 24, 2022 11:38:48] debug  redis is conetcted 
-[Jan 24, 2022 11:38:50] debug  redis is conetcted 
-[Jan 24, 2022 11:38:50] debug  redis is conetcted 
-[Jan 24, 2022 11:38:50] debug  redis is conetcted 
-[Jan 24, 2022 11:38:50] debug  redis is conetcted 
-[Jan 24, 2022 11:38:54] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:38:54] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:38:54] debug  Master 9148 is running 
-[Jan 24, 2022 11:38:54] debug  redis is conetcted 
-[Jan 24, 2022 11:38:56] debug  redis is conetcted 
-[Jan 24, 2022 11:38:56] debug  redis is conetcted 
-[Jan 24, 2022 11:38:56] debug  redis is conetcted 
-[Jan 24, 2022 11:38:56] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAAb69","isLogin":true}}
-[Jan 24, 2022 11:38:56] debug  redis is conetcted 
-[Jan 24, 2022 11:39:00] info  redis {"url":"redis://:redis9394@localhost:6379"}
-[Jan 24, 2022 11:39:00] debug  Total Number of Cores:4 
-[Jan 24, 2022 11:39:00] debug  Master 9173 is running 
-[Jan 24, 2022 11:39:00] debug  redis is conetcted 
-[Jan 24, 2022 11:39:04] debug  redis is conetcted 
-[Jan 24, 2022 11:39:04] debug  redis is conetcted 
-[Jan 24, 2022 11:39:04] debug  redis is conetcted 
-[Jan 24, 2022 11:39:04] debug  redis is conetcted 
-[Jan 24, 2022 11:39:04] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAAcf7","isLogin":true}}
-[Jan 24, 2022 11:39:08] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAAdzj","isLogin":true}}
-[Jan 24, 2022 11:39:57] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAApm2","isLogin":true}}

+ 0 - 0
logs/error.log


+ 1 - 1
package.json

@@ -4,7 +4,7 @@
   "description": "",
   "main": "index.js",
   "scripts": {
-    "dev": " NODE_ENV=development DEBUG=* node index.js",
+    "dev": "cross-env NODE_ENV=development node index.js",
     "hot-serve": "cross-env NODE_ENV=development npx nodemon index.js"
   },
   "type": "module",

+ 14 - 16
src/controller/basicController.js

@@ -1,17 +1,18 @@
 import { pubClient } from "../connection/redis.js";
 import { EVENT } from "../enum/event.js";
 import { roomController } from "./roomController.js";
+import { syncActionController } from "./syncActionController.js";
 
-const clientSyncAction = (socket) => {
-  socket.on(EVENT.clientSyncAction, (data) => {
-    socket.broadcast.to(clientRoom).emit(EVENT.clientSyncAction, data);
-  });
-};
-const webSyncAction = (socket) => {
-  socket.on(EVENT.webSyncAction, (data) => {
-    socket.broadcast.to(webRoomId).emit(EVENT.webSyncAction, data);
-  });
-};
+// const clientSyncAction = (socket) => {
+//   socket.on(EVENT.clientSyncAction, (data) => {
+//     socket.broadcast.to(clientRoom).emit(EVENT.clientSyncAction, data);
+//   });
+// };
+// const webSyncAction = (socket) => {
+//   socket.on(EVENT.webSyncAction, (data) => {
+//     socket.broadcast.to(webRoomId).emit(EVENT.webSyncAction, data);
+//   });
+// };
 const action = (socket) => {
   socket.on(EVENT.action, (data) => {
     socket.broadcast.to(roomId).emit(EVENT.action, data);
@@ -25,10 +26,7 @@ export async function basicController(socket) {
   //     next();
   //   });
 
-  clientSyncAction(socket);
-  webSyncAction(socket);
-  roomController(socket);
-
-  //   console.log("pubClient", pubClient);
-  //   await pubClient.HSET(user.userId, "value", user);
+  //   webSyncAction(socket);
+  await roomController(socket);
+  await syncActionController(socket);
 }

+ 4 - 3
src/controller/roomController.js

@@ -89,7 +89,7 @@ const joinRoomAction = async (roomId, userId, user, socket) => {
  * @param {*} socket
  */
 const leaveRoomAction = async (roomId, userId, user, socket) => {
-  console.log("离开房间", userId);
+  logger.info("离开房间", userId);
   socket.leave(roomId);
   leaveRoom(roomId, userId);
   socket.broadcast.emit(EVENT.roomOut, {
@@ -102,7 +102,7 @@ const leaveRoomAction = async (roomId, userId, user, socket) => {
 
 export async function roomController(socket) {
   let user = socket.handshake.query;
-  const { roomId, userId, sceneNum, isClient, role, userLimitNum, roomType } = user;
+  const { roomId, userId, sceneNum, isClient, role, userLimitNum, roomType, from } = user;
   if (user) {
     const webRoomId = `${roomId}_${sceneNum}_web`;
     // const clientRoom = `${userId}${roomId}`;
@@ -113,7 +113,8 @@ export async function roomController(socket) {
       await pubClient.hSet(userUniqueId, user);
       await pubClient.expire(userUniqueId, 60 * 60 * 1);
       // 房主自动创建房间
-      if (isHoster(role)) {
+
+      if (isHoster(role) && Number(from) === 0) {
         logger.debug("房主自动创建房间 :", { roomId: roomUniqueId, userId: userUniqueId, user });
         buildRoom(roomUniqueId, userUniqueId, user);
         socket.join(roomUniqueId);

+ 3 - 1
src/controller/roomStatusController.js

@@ -1,3 +1,5 @@
+import { logger } from "../core/logger";
+
 /**
  * 检查房主存不存在
  * @param {*} roomUniqueId
@@ -16,7 +18,7 @@ const checkRoomStatus = async (roomUniqueId, socket) => {
     console.log("room watch", roomUniqueId, values);
     const existMaster = values.find((item) => String(JSON.parse(item).role).toLowerCase() === ROLES.LEADER);
     if (!existMaster) {
-      console.log("不存在房主");
+      logger.info("不存在房主", roomUniqueId);
       setTimeout(async () => {
         socket.emit(EVENT.roomClose, { code: 3001, msg: CODEMEG[3001] });
         await pubClient.del(roomUniqueId);

+ 27 - 0
src/controller/syncActionController.js

@@ -0,0 +1,27 @@
+import { logger } from "../core/logger.js";
+import { pubClient } from "../connection/redis.js";
+
+const joinSyncClient = async (syncId, userId, from, socket) => {
+  //   socket.join(syncId);
+  logger.debug("syncId", { syncId, userId, from });
+  try {
+    await pubClient.hSet(syncId, from, userId);
+    socket.join(syncId);
+  } catch (error) {
+    logger.error("joinSyncClient", error);
+  }
+};
+
+export async function syncActionController(socket) {
+  let user = socket.handshake.query;
+  const { roomId, userId, sceneNum, isClient, role, userLimitNum, roomType, from } = user;
+
+  const syncId = `sync-${userId}${roomId}`;
+  if (user) {
+    if ("roomId" in user && "userId" in user) {
+      //   await pubClient.set("test");
+      console.log("from-sync", from);
+      joinSyncClient(syncId, userId, from, socket);
+    }
+  }
+}

+ 5 - 5
src/core/cluster.js

@@ -17,7 +17,7 @@ export class CoreCluster {
   }
   attachThead() {
     if (cluster.isMaster) {
-      logger.debug("Total Number of Cores:" + numCPUs);
+      logger.debug("Total Number of Cores:", numCPUs);
       logger.debug(`Master ${process.pid} is running`);
 
       // setup sticky sessions
@@ -33,20 +33,20 @@ export class CoreCluster {
       });
 
       httpServer.listen(this.port);
-      console.log(`server  is running on port ${this.port}`);
+      logger.debug(`server  is running on port ${this.port}`);
 
       for (let i = 0; i < numCPUs; i++) {
         cluster.fork();
       }
       cluster.on("exit", (worker) => {
-        logger.log(`Worker ${worker.process.pid} died`);
+        logger.debug(`Worker ${worker.process.pid} died`);
         cluster.fork();
       });
       cluster.on("online", (worker) => {
-        console.log("Worker %o is listening", worker.process.pid);
+        logger.debug("Worker %o is listening", worker.process.pid);
       });
     } else {
-      console.log(`Worker ${process.pid} started`);
+      logger.debug(`Worker ${process.pid} started`);
       // use the cluster adapter
       io.adapter(createAdapter());
 

+ 2 - 2
src/core/io.js

@@ -28,10 +28,10 @@ instrument(io, {
 Promise.all([pubClient.connect(), subClient.connect()])
   .then(() => {
     io.adapter(createAdapter(pubClient, subClient));
-    logger.debug("redis is conetcted");
+    logger.info("redis is conetcted");
   })
   .catch((error) => {
-    logger.error("redis is connect fail" + JSON.stringify(error));
+    logger.error("redis is connect fail", error);
   });
 
 export { io };

+ 0 - 2
src/core/logger.js

@@ -6,8 +6,6 @@ import { fileURLToPath } from "url";
 const __filename = fileURLToPath(import.meta.url);
 const __dirname = dirname(__filename);
 
-// const logFormat = format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}` + (info.splat !== undefined ? `${info.splat}` : " "));
-
 const formatMeta = (meta) => {
   // You can format the splat yourself
   const splat = meta[Symbol.for("splat")];