@nka212bg/backend-utils 0.1.43 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/db/dbUtils.js +0 -0
- package/db/mysql2.js +0 -0
- package/db/sqlite3.js +0 -0
- package/index.js +0 -0
- package/location/GeoLite2-City.mmdb +0 -0
- package/location/VPNs-master.zip +0 -0
- package/location/index.js +0 -0
- package/location/localelib.js +0 -0
- package/mailSmsTools/defaultTemplate.html +0 -0
- package/mailSmsTools/index.js +0 -0
- package/markdown/index.js +0 -0
- package/markdown/markdown.js +0 -0
- package/misc.js +0 -0
- package/os.js +0 -0
- package/package.json +1 -1
- package/socket.js +13 -4
- package/stripe.js +0 -0
- package/systemLog.js +0 -0
package/README.md
CHANGED
|
File without changes
|
package/db/dbUtils.js
CHANGED
|
File without changes
|
package/db/mysql2.js
CHANGED
|
File without changes
|
package/db/sqlite3.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/location/VPNs-master.zip
CHANGED
|
File without changes
|
package/location/index.js
CHANGED
|
File without changes
|
package/location/localelib.js
CHANGED
|
File without changes
|
|
File without changes
|
package/mailSmsTools/index.js
CHANGED
|
File without changes
|
package/markdown/index.js
CHANGED
|
File without changes
|
package/markdown/markdown.js
CHANGED
|
File without changes
|
package/misc.js
CHANGED
|
File without changes
|
package/os.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/socket.js
CHANGED
|
@@ -9,6 +9,7 @@ const parseParams = (url) => {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
module.exports = (server, { authenticate } = {}) => {
|
|
12
|
+
const hidden = new Set();
|
|
12
13
|
const socket = new WebSocket.Server({ server, noServer: !server });
|
|
13
14
|
socket.on("connection", (ws, req) => {
|
|
14
15
|
const params = parseParams(req.url);
|
|
@@ -22,7 +23,7 @@ module.exports = (server, { authenticate } = {}) => {
|
|
|
22
23
|
const userId = ws.params.userId;
|
|
23
24
|
|
|
24
25
|
// first tab of this user -> online
|
|
25
|
-
if (userId && !isConnected(userId, ws)) notifyWatchers(userId, 1);
|
|
26
|
+
if (userId && !hidden.has(userId) && !isConnected(userId, ws)) notifyWatchers(userId, 1);
|
|
26
27
|
|
|
27
28
|
// { watchStatuses: [userIds] } -> replies { statuses: { userId: 0 | 1 } }, then pushes { status: { userId, online } } on changes
|
|
28
29
|
ws.on("message", (raw) => {
|
|
@@ -35,7 +36,7 @@ module.exports = (server, { authenticate } = {}) => {
|
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
// last tab closed -> offline
|
|
38
|
-
ws.on("close", () => userId && !isConnected(userId, ws) && notifyWatchers(userId, 0));
|
|
39
|
+
ws.on("close", () => userId && !hidden.has(userId) && !isConnected(userId, ws) && notifyWatchers(userId, 0));
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
const isConnected = (userId, except) => {
|
|
@@ -43,7 +44,7 @@ module.exports = (server, { authenticate } = {}) => {
|
|
|
43
44
|
return false;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
const notifyWatchers = (userId, online) => {
|
|
47
|
+
const notifyWatchers = (userId, online) => {
|
|
47
48
|
const data = JSON.stringify({ statuses: { [userId]: online } });
|
|
48
49
|
for (const c of socket.clients) if (c.watching?.has(userId)) c.send(data);
|
|
49
50
|
};
|
|
@@ -97,12 +98,20 @@ module.exports = (server, { authenticate } = {}) => {
|
|
|
97
98
|
for (const client of socket.clients || []) {
|
|
98
99
|
if (!users.size) break;
|
|
99
100
|
const id = client.params?.userId;
|
|
100
|
-
if (users.delete(id)) usersObj[id] = 1;
|
|
101
|
+
if (!hidden.has(id) && users.delete(id)) usersObj[id] = 1;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
return usersObj;
|
|
104
105
|
};
|
|
105
106
|
|
|
107
|
+
socket.setStatuses = (userId, offline = true) => {
|
|
108
|
+
userId = String(userId);
|
|
109
|
+
if (!!offline === hidden.has(userId)) return; // no change
|
|
110
|
+
|
|
111
|
+
offline ? hidden.add(userId) : hidden.delete(userId);
|
|
112
|
+
if (isConnected(userId)) notifyWatchers(userId, offline ? 0 : 1);
|
|
113
|
+
};
|
|
114
|
+
|
|
106
115
|
return socket;
|
|
107
116
|
};
|
|
108
117
|
|
package/stripe.js
CHANGED
|
File without changes
|
package/systemLog.js
CHANGED
|
File without changes
|