Prechádzať zdrojové kódy

fix: SOCKETS_FROM_USER shouldn't stop when it comes across logged-out visitors

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 4 rokov pred
rodič
commit
1c1c050354
1 zmenil súbory, kde vykonal 11 pridanie a 16 odobranie
  1. 11 16
      backend/logic/io.js

+ 11 - 16
backend/logic/io.js

@@ -148,21 +148,15 @@ class _IOModule extends CoreClass {
 					1,
 					(id, next) => {
 						const { session } = ns.connected[id];
-						CacheModule.runJob(
-							"HGET",
-							{
-								table: "sessions",
-								key: session.sessionId
-							},
-							this
-						)
-							.then(session => {
-								if (session && session.userId === payload.userId) sockets.push(ns.connected[id]);
-								next();
-							})
-							.catch(err => {
-								next(err);
-							});
+
+						if (session.sessionId) {
+							CacheModule.runJob("HGET", { table: "sessions", key: session.sessionId }, this)
+								.then(session => {
+									if (session && session.userId === payload.userId) sockets.push(ns.connected[id]);
+									next();
+								})
+								.catch(err => next(err));
+						} else next();
 					},
 					err => {
 						if (err) return reject(err);
@@ -191,6 +185,7 @@ class _IOModule extends CoreClass {
 					Object.keys(ns.connected),
 					(id, next) => {
 						const { session } = ns.connected[id];
+
 						CacheModule.runJob(
 							"HGET",
 							{
@@ -206,7 +201,7 @@ class _IOModule extends CoreClass {
 							.catch(() => next());
 					},
 					() => {
-						resolve({ sockets });
+						resolve(sockets);
 					}
 				);
 			}