@cocreate/socket-server 1.18.0 → 1.18.1
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/CHANGELOG.md +9 -0
- package/CoCreate.config.js +24 -24
- package/package.json +3 -3
- package/src/index.js +15 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [1.18.1](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.18.0...v1.18.1) (2023-09-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Add path and pathname ([5b5fb7e](https://github.com/CoCreate-app/CoCreate-socket-server/commit/5b5fb7e6d718f916dfdbfc3754cb63c6b1a51c47))
|
|
7
|
+
* Update clients array to use map for improved management of each client ([cff2f2a](https://github.com/CoCreate-app/CoCreate-socket-server/commit/cff2f2ad3d34ac1d7b926180da508c65e5855b37))
|
|
8
|
+
* Update dCoCreate dpendencies to latest versions ([03fa429](https://github.com/CoCreate-app/CoCreate-socket-server/commit/03fa429efc31db9f0ed5aec41dbf5b471475e0ba))
|
|
9
|
+
|
|
1
10
|
# [1.18.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.17.0...v1.18.0) (2023-09-17)
|
|
2
11
|
|
|
3
12
|
|
package/CoCreate.config.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"organization_id": "",
|
|
3
|
-
"key": "",
|
|
4
|
-
"host": "",
|
|
5
|
-
"sources": [
|
|
6
|
-
{
|
|
7
|
-
"array": "files",
|
|
8
|
-
"object": {
|
|
9
|
-
"_id": "6204254580b409001727b744",
|
|
10
|
-
"name": "index.html",
|
|
11
|
-
"path": "/docs/socket-server
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
"organization_id": "",
|
|
3
|
+
"key": "",
|
|
4
|
+
"host": "",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"array": "files",
|
|
8
|
+
"object": {
|
|
9
|
+
"_id": "6204254580b409001727b744",
|
|
10
|
+
"name": "index.html",
|
|
11
|
+
"path": "/docs/socket-server",
|
|
12
|
+
"pathname": "/docs/socket-server/index.html",
|
|
13
|
+
"src": "{{./docs/index.html}}",
|
|
14
|
+
"host": [
|
|
15
|
+
"*",
|
|
16
|
+
"general.cocreate.app"
|
|
17
|
+
],
|
|
18
|
+
"directory": "socket-server",
|
|
19
|
+
"content-type": "text/html",
|
|
20
|
+
"public": "true"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/socket-server",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "CoCreate-socket-server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cocreate-socket",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://cocreate.app/docs/CoCreate-socket-server",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cocreate/config": "^1.5.
|
|
44
|
-
"@cocreate/uuid": "^1.7.
|
|
43
|
+
"@cocreate/config": "^1.5.1",
|
|
44
|
+
"@cocreate/uuid": "^1.7.1",
|
|
45
45
|
"ws": "7.5.9"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/index.js
CHANGED
|
@@ -68,13 +68,14 @@ class SocketServer extends EventEmitter {
|
|
|
68
68
|
let user_id = socket.config.user_id
|
|
69
69
|
let key = socket.config.key
|
|
70
70
|
let clients = this.clients.get(key);
|
|
71
|
-
if (clients) {
|
|
72
|
-
clients
|
|
73
|
-
|
|
74
|
-
clients = [socket];
|
|
71
|
+
if (!clients) {
|
|
72
|
+
clients = new Map();
|
|
73
|
+
this.clients.set(key, clients);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (!clients.has(socket))
|
|
76
|
+
clients.set(socket, true);
|
|
77
|
+
else
|
|
78
|
+
console.log('has client')
|
|
78
79
|
if (user_id)
|
|
79
80
|
this.emit('userStatus', socket, { socket, user_id, userStatus: 'on', organization_id });
|
|
80
81
|
}
|
|
@@ -83,18 +84,15 @@ class SocketServer extends EventEmitter {
|
|
|
83
84
|
let organization_id = socket.config.organization_id
|
|
84
85
|
let user_id = socket.config.user_id
|
|
85
86
|
let key = socket.config.key
|
|
86
|
-
let clients = this.clients.get(key)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (index > -1) {
|
|
90
|
-
clients.splice(index, 1);
|
|
91
|
-
}
|
|
87
|
+
let clients = this.clients.get(key);
|
|
88
|
+
clients.delete(socket);
|
|
92
89
|
|
|
93
90
|
if (user_id)
|
|
94
91
|
this.emit('userStatus', socket, { socket, user_id, status: 'off', organization_id });
|
|
95
92
|
|
|
96
|
-
if (clients.
|
|
93
|
+
if (clients.size == 0) {
|
|
97
94
|
this.organizations.delete(organization_id)
|
|
95
|
+
// this.clients.delete(key);
|
|
98
96
|
this.emit('disconnect', organization_id)
|
|
99
97
|
}
|
|
100
98
|
|
|
@@ -138,7 +136,7 @@ class SocketServer extends EventEmitter {
|
|
|
138
136
|
if (!user_id)
|
|
139
137
|
this.send({ socket, method: 'updateUserStatus', userStatus: 'off', clientId: data.clientId, organization_id })
|
|
140
138
|
|
|
141
|
-
return this.send({ method: 'Access Denied', authorized, ...data })
|
|
139
|
+
return this.send({ socket, method: 'Access Denied', authorized, ...data })
|
|
142
140
|
}
|
|
143
141
|
// dburl is true and db does not have 'keys' array
|
|
144
142
|
// action: syncCollection data{array: 'keys', object[]}
|
|
@@ -172,7 +170,7 @@ class SocketServer extends EventEmitter {
|
|
|
172
170
|
if (!data.uid)
|
|
173
171
|
data.uid = uid.generate()
|
|
174
172
|
|
|
175
|
-
let organization_id = socket.config.organization_id;
|
|
173
|
+
let organization_id = data.socket.config.organization_id;
|
|
176
174
|
let url = `/${this.prefix}/${organization_id}`;
|
|
177
175
|
|
|
178
176
|
let namespace = data.namespace;
|
|
@@ -202,12 +200,12 @@ class SocketServer extends EventEmitter {
|
|
|
202
200
|
|
|
203
201
|
let clients
|
|
204
202
|
if (!url)
|
|
205
|
-
clients = [socket]
|
|
203
|
+
clients = new Map([[socket, true]])
|
|
206
204
|
else
|
|
207
205
|
clients = this.clients.get(url);
|
|
208
206
|
|
|
209
207
|
if (clients) {
|
|
210
|
-
for (let client of clients) {
|
|
208
|
+
for (let client of clients.keys()) {
|
|
211
209
|
if (socket != client && data.broadcast != false || socket == client && data.broadcastSender != false) {
|
|
212
210
|
const authorized = await this.authorize.check(data, socket.config.user_id)
|
|
213
211
|
if (authorized && authorized.authorized)
|