@cocreate/socket-server 1.8.0 → 1.8.2
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 +15 -0
- package/package.json +3 -3
- package/src/index.js +56 -70
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.8.2](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.8.1...v1.8.2) (2023-05-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Refactor socket server to track and limit server bandwidth usage. ([0c4c0f4](https://github.com/CoCreate-app/CoCreate-socket-server/commit/0c4c0f438a27e75d659044bfdcc19f422df67347))
|
|
7
|
+
|
|
8
|
+
## [1.8.1](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.8.0...v1.8.1) (2023-05-20)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Refactor socket server code to re check permissions using platformId when organization.dbUrl is false. ([e0cae7a](https://github.com/CoCreate-app/CoCreate-socket-server/commit/e0cae7a0a2eb9c740f36a3306fc038a9c68329ab))
|
|
14
|
+
* updated dependencies to their latest versions ([84d2f1d](https://github.com/CoCreate-app/CoCreate-socket-server/commit/84d2f1d0a67b021682f5b9b543ededb995830231))
|
|
15
|
+
|
|
1
16
|
# [1.8.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.7.7...v1.8.0) (2023-05-19)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/socket-server",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
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/docs": "^1.
|
|
44
|
-
"@cocreate/uuid": "^1.
|
|
43
|
+
"@cocreate/docs": "^1.7.11",
|
|
44
|
+
"@cocreate/uuid": "^1.4.10"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"express": "^4.17.1",
|
package/src/index.js
CHANGED
|
@@ -87,7 +87,7 @@ class SocketServer extends EventEmitter {
|
|
|
87
87
|
let total_cnt = 0;
|
|
88
88
|
this.clients.forEach((c) => total_cnt += c.length)
|
|
89
89
|
|
|
90
|
-
this.emit("createMetrics",
|
|
90
|
+
this.emit("createMetrics", {
|
|
91
91
|
organization_id,
|
|
92
92
|
client_cnt: room_clients.length,
|
|
93
93
|
total_cnt: total_cnt
|
|
@@ -109,7 +109,7 @@ class SocketServer extends EventEmitter {
|
|
|
109
109
|
if (user_id)
|
|
110
110
|
this.emit('userStatus', socket, { user_id, status: 'off', organization_id });
|
|
111
111
|
|
|
112
|
-
this.emit("deleteMetrics",
|
|
112
|
+
this.emit("deleteMetrics", { organization_id });
|
|
113
113
|
this.emit("deletePermissions", organization_id);
|
|
114
114
|
this.emit('disconnect', organization_id)
|
|
115
115
|
this.asyncMessages.delete(key);
|
|
@@ -117,7 +117,7 @@ class SocketServer extends EventEmitter {
|
|
|
117
117
|
let total_cnt = 0;
|
|
118
118
|
this.clients.forEach((c) => total_cnt += c.length)
|
|
119
119
|
|
|
120
|
-
this.emit("changeCountMetrics",
|
|
120
|
+
this.emit("changeCountMetrics", {
|
|
121
121
|
organization_id,
|
|
122
122
|
total_cnt,
|
|
123
123
|
client_cnt: room_clients.length
|
|
@@ -129,19 +129,14 @@ class SocketServer extends EventEmitter {
|
|
|
129
129
|
async onMessage(req, socket, message) {
|
|
130
130
|
try {
|
|
131
131
|
const organization_id = socket.config.organization_id
|
|
132
|
-
|
|
133
|
-
// TODO: remove
|
|
134
|
-
// if (message instanceof Buffer) {
|
|
135
|
-
// this.emit('importFile2DB', socket, message);
|
|
136
|
-
// console.log('importFile2DB', socket, message);
|
|
137
|
-
// return;
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
132
|
const { action, data } = JSON.parse(message)
|
|
141
133
|
|
|
142
134
|
if (action) {
|
|
143
|
-
this.
|
|
144
|
-
|
|
135
|
+
this.emit("setBandwidth", {
|
|
136
|
+
type: 'in',
|
|
137
|
+
data: message,
|
|
138
|
+
organization_id
|
|
139
|
+
});
|
|
145
140
|
let user_id = null;
|
|
146
141
|
if (this.authInstance)
|
|
147
142
|
user_id = await this.authInstance.getUserId(req);
|
|
@@ -149,57 +144,47 @@ class SocketServer extends EventEmitter {
|
|
|
149
144
|
if (this.permissionInstance) {
|
|
150
145
|
const permission = await this.permissionInstance.check(action, data, req, user_id)
|
|
151
146
|
if (!permission || permission.error) {
|
|
152
|
-
|
|
153
|
-
// if (action == 'syncServer')
|
|
154
|
-
// this.emit('createDocument', socket, data);
|
|
155
|
-
// else
|
|
156
|
-
if (user_id && permission.dbUrl === false && action.includes('Document') && (data.collection == 'organizations' || data.collection == 'users')) {
|
|
147
|
+
if (permission.dbUrl === false) {
|
|
157
148
|
data.database = process.env.organization_id
|
|
158
149
|
data.organization_id = process.env.organization_id
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (data.collection == 'organizations' && data.document._id !== socket.config.organization_id)
|
|
164
|
-
return this.send(socket, 'Access Denied', { action, permission, ...data })
|
|
165
|
-
else if (data.collection == 'users' && data.document._id !== user_id)
|
|
166
|
-
return this.send(socket, 'Access Denied', { action, permission, ...data })
|
|
150
|
+
|
|
151
|
+
const permission2 = await this.permissionInstance.check(action, data, req, user_id)
|
|
152
|
+
if (!permission2 || permission2.error) {
|
|
153
|
+
return this.send(socket, 'Access Denied', { action, permission2, ...data })
|
|
167
154
|
}
|
|
168
|
-
|
|
169
|
-
delete data.document.organization_id
|
|
170
|
-
if (action == 'updateDocument')
|
|
171
|
-
data.upsert = false
|
|
172
|
-
} else if (action === 'createOrganization' || action === 'signIn') {
|
|
173
|
-
data.database = process.env.organization_id
|
|
174
|
-
data.organization_id = process.env.organization_id
|
|
175
|
-
} else {
|
|
155
|
+
} else if (!user_id) {
|
|
176
156
|
return this.send(socket, 'Access Denied', { action, permission, ...data })
|
|
177
157
|
}
|
|
158
|
+
// dburl is true and db does not have 'keys' collection
|
|
159
|
+
// action: syncCollection data{collection: 'keys', document[]}
|
|
160
|
+
// actions: add keys as once keys are added admin user can do anything
|
|
161
|
+
|
|
162
|
+
|
|
178
163
|
}
|
|
179
|
-
}
|
|
180
164
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
165
|
+
if (user_id) {
|
|
166
|
+
if (!socket.config.user_id) {
|
|
167
|
+
socket.config.user_id = user_id
|
|
168
|
+
this.emit('userStatus', socket, { user_id, userStatus: 'on', organization_id });
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
this.send(socket, 'updateUserStatus', { userStatus: 'off', clientId: data.clientId, organization_id })
|
|
185
172
|
}
|
|
186
|
-
} else {
|
|
187
|
-
this.send(socket, 'updateUserStatus', { userStatus: 'off', clientId: data.clientId, organization_id })
|
|
188
|
-
}
|
|
189
173
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
174
|
+
//. checking async status....
|
|
175
|
+
if (data.async == true) {
|
|
176
|
+
console.log('async true')
|
|
177
|
+
const asyncMessage = this.asyncMessages.get(socket.config.key);
|
|
178
|
+
socket.config.asyncId = uid.generate();
|
|
179
|
+
if (asyncMessage) {
|
|
180
|
+
asyncMessage.defineMessage(socket.config.asyncId);
|
|
181
|
+
}
|
|
197
182
|
}
|
|
198
|
-
}
|
|
199
183
|
|
|
200
|
-
|
|
201
|
-
}
|
|
184
|
+
this.emit(action, socket, data);
|
|
202
185
|
|
|
186
|
+
}
|
|
187
|
+
}
|
|
203
188
|
} catch (e) {
|
|
204
189
|
console.log(e);
|
|
205
190
|
}
|
|
@@ -244,9 +229,14 @@ class SocketServer extends EventEmitter {
|
|
|
244
229
|
if (isAsync) {
|
|
245
230
|
asyncData.push({ socket: client, message: responseData })
|
|
246
231
|
} else {
|
|
232
|
+
// TODO: check permission and remove any items client does not have a permission
|
|
247
233
|
client.send(responseData);
|
|
248
234
|
}
|
|
249
|
-
|
|
235
|
+
this.emit("setBandwidth", {
|
|
236
|
+
type: 'out',
|
|
237
|
+
data: responseData,
|
|
238
|
+
organization_id
|
|
239
|
+
})
|
|
250
240
|
}
|
|
251
241
|
})
|
|
252
242
|
}
|
|
@@ -260,9 +250,15 @@ class SocketServer extends EventEmitter {
|
|
|
260
250
|
if (isAsync) {
|
|
261
251
|
asyncData.push({ socket: client, message: responseData })
|
|
262
252
|
} else {
|
|
253
|
+
// TODO: check permission and remove any items client does not have a permission
|
|
263
254
|
client.send(responseData);
|
|
264
255
|
}
|
|
265
|
-
|
|
256
|
+
this.emit("setBandwidth", {
|
|
257
|
+
type: 'out',
|
|
258
|
+
data: responseData,
|
|
259
|
+
organization_id
|
|
260
|
+
})
|
|
261
|
+
|
|
266
262
|
}
|
|
267
263
|
})
|
|
268
264
|
}
|
|
@@ -286,12 +282,16 @@ class SocketServer extends EventEmitter {
|
|
|
286
282
|
if (asyncId && socket.config && socket.config.key) {
|
|
287
283
|
this.asyncMessages.get(socket.config.key).setMessage(asyncId, [{ socket, message: responseData }]);
|
|
288
284
|
} else {
|
|
285
|
+
// TODO: check permission and remove any items client does not have a permission
|
|
289
286
|
socket.send(responseData);
|
|
290
287
|
}
|
|
291
288
|
|
|
292
289
|
if (socket.config && socket.config.organization_id)
|
|
293
|
-
this.
|
|
294
|
-
|
|
290
|
+
this.emit("setBandwidth", {
|
|
291
|
+
type: 'out',
|
|
292
|
+
data: responseData,
|
|
293
|
+
organization_id: socket.config.organization_id
|
|
294
|
+
})
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
// addAsyncMessage(key) {
|
|
@@ -313,20 +313,6 @@ class SocketServer extends EventEmitter {
|
|
|
313
313
|
}
|
|
314
314
|
return params
|
|
315
315
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
sendBinary(socket, data, organization_id) {
|
|
319
|
-
socket.send(data, { binary: true });
|
|
320
|
-
this.recordTransfer('out', data, organization_id)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
recordTransfer(type, data, organization_id) {
|
|
324
|
-
this.emit("setBandwidth", null, {
|
|
325
|
-
type,
|
|
326
|
-
data,
|
|
327
|
-
organization_id
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
316
|
}
|
|
331
317
|
|
|
332
318
|
|