@cocreate/socket-server 1.4.18 → 1.4.20
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 +14 -0
- package/package.json +1 -1
- package/src/index.js +42 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.4.20](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.4.19...v1.4.20) (2022-12-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* comment syncServer requires security improvements ([60f73de](https://github.com/CoCreate-app/CoCreate-socket-server/commit/60f73ded3927f7c6a5005b0f339e846ead920c2e))
|
|
7
|
+
|
|
8
|
+
## [1.4.19](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.4.18...v1.4.19) (2022-12-07)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* organization_id ([37b7b72](https://github.com/CoCreate-app/CoCreate-socket-server/commit/37b7b72918fdd6a28ec04b1b26a1822d2d36e1e3))
|
|
14
|
+
|
|
1
15
|
## [1.4.18](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.4.17...v1.4.18) (2022-12-04)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -63,7 +63,7 @@ class SocketServer extends EventEmitter{
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
addClient(socket) {
|
|
66
|
-
let organization_id = socket.config.
|
|
66
|
+
let organization_id = socket.config.organization_id
|
|
67
67
|
let key = socket.config.key
|
|
68
68
|
let room_clients = this.clients.get(key);
|
|
69
69
|
if (room_clients) {
|
|
@@ -84,14 +84,14 @@ class SocketServer extends EventEmitter{
|
|
|
84
84
|
this.clients.forEach((c) => total_cnt += c.length)
|
|
85
85
|
|
|
86
86
|
this.emit("createMetrics", null, {
|
|
87
|
-
|
|
87
|
+
organization_id,
|
|
88
88
|
client_cnt: room_clients.length,
|
|
89
89
|
total_cnt: total_cnt
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
removeClient(socket) {
|
|
94
|
-
let organization_id = socket.config.
|
|
94
|
+
let organization_id = socket.config.organization_id
|
|
95
95
|
let user_id = socket.config.user_id
|
|
96
96
|
let key = socket.config.key
|
|
97
97
|
let room_clients = this.clients.get(key)
|
|
@@ -105,7 +105,7 @@ class SocketServer extends EventEmitter{
|
|
|
105
105
|
if (user_id)
|
|
106
106
|
this.emit('userStatus', socket, {user_id, status: 'off', organization_id});
|
|
107
107
|
|
|
108
|
-
this.emit("removeMetrics", null, {
|
|
108
|
+
this.emit("removeMetrics", null, { organization_id });
|
|
109
109
|
|
|
110
110
|
this.asyncMessages.delete(key);
|
|
111
111
|
} else {
|
|
@@ -113,7 +113,7 @@ class SocketServer extends EventEmitter{
|
|
|
113
113
|
this.clients.forEach((c) => total_cnt += c.length)
|
|
114
114
|
|
|
115
115
|
this.emit("changeCountMetrics", null, {
|
|
116
|
-
|
|
116
|
+
organization_id,
|
|
117
117
|
total_cnt,
|
|
118
118
|
client_cnt: room_clients.length
|
|
119
119
|
});
|
|
@@ -123,23 +123,37 @@ class SocketServer extends EventEmitter{
|
|
|
123
123
|
|
|
124
124
|
async onMessage(req, socket, message) {
|
|
125
125
|
try {
|
|
126
|
-
const organization_id = socket.config.
|
|
127
|
-
this.recordTransfer('in', message, organization_id)
|
|
126
|
+
const organization_id = socket.config.organization_id
|
|
128
127
|
|
|
129
128
|
// ToDo: remove
|
|
130
|
-
if (message instanceof Buffer) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
129
|
+
// if (message instanceof Buffer) {
|
|
130
|
+
// this.emit('importFile2DB', socket, message);
|
|
131
|
+
// console.log('importFile2DB', socket, message);
|
|
132
|
+
// return;
|
|
133
|
+
// }
|
|
135
134
|
|
|
136
|
-
const
|
|
135
|
+
const {action, data} = JSON.parse(message)
|
|
136
|
+
|
|
137
|
+
if (action) {
|
|
138
|
+
this.recordTransfer('in', message, organization_id)
|
|
137
139
|
|
|
138
|
-
if (requestData.action) {
|
|
139
140
|
let user_id = null;
|
|
140
|
-
if (this.authInstance)
|
|
141
|
+
if (this.authInstance)
|
|
141
142
|
user_id = await this.authInstance.getUserId(req);
|
|
143
|
+
|
|
144
|
+
//. check permission
|
|
145
|
+
if (this.permissionInstance) {
|
|
146
|
+
const passStatus = await this.permissionInstance.check(action, data, req, user_id)
|
|
147
|
+
if (passStatus !== true) {
|
|
148
|
+
// if (action == 'syncServer' && passStatus.database === true)
|
|
149
|
+
// if (action == 'syncServer')
|
|
150
|
+
// this.emit(action, socket, data);
|
|
151
|
+
// else
|
|
152
|
+
this.send(socket, 'Access Denied', passStatus)
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
142
155
|
}
|
|
156
|
+
|
|
143
157
|
if (user_id) {
|
|
144
158
|
if (!socket.config.user_id ) {
|
|
145
159
|
socket.config.user_id = user_id
|
|
@@ -147,17 +161,8 @@ class SocketServer extends EventEmitter{
|
|
|
147
161
|
this.emit('userStatus', socket, {user_id, userStatus: 'on', organization_id});
|
|
148
162
|
}
|
|
149
163
|
|
|
150
|
-
//. check permission
|
|
151
|
-
if (this.permissionInstance) {
|
|
152
|
-
let passStatus = await this.permissionInstance.check(requestData.action, requestData.data, req, user_id)
|
|
153
|
-
if (!passStatus) {
|
|
154
|
-
this.send(socket, 'permissionError', requestData.data)
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
164
|
//. checking async status....
|
|
160
|
-
if (
|
|
165
|
+
if (data.async == true) {
|
|
161
166
|
console.log('async true')
|
|
162
167
|
const asyncMessage = this.asyncMessages.get(socket.config.key);
|
|
163
168
|
socket.config.asyncId = uid.generate();
|
|
@@ -165,7 +170,8 @@ class SocketServer extends EventEmitter{
|
|
|
165
170
|
asyncMessage.defineMessage(socket.config.asyncId);
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
|
-
|
|
173
|
+
|
|
174
|
+
this.emit(action, socket, data);
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
} catch(e) {
|
|
@@ -189,7 +195,7 @@ class SocketServer extends EventEmitter{
|
|
|
189
195
|
isAsync = true;
|
|
190
196
|
}
|
|
191
197
|
|
|
192
|
-
let organization_id = socket.config.
|
|
198
|
+
let organization_id = socket.config.organization_id;
|
|
193
199
|
let url = `/${this.prefix}/${organization_id}`;
|
|
194
200
|
|
|
195
201
|
let namespace = data.namespace;
|
|
@@ -257,8 +263,8 @@ class SocketServer extends EventEmitter{
|
|
|
257
263
|
socket.send(responseData);
|
|
258
264
|
}
|
|
259
265
|
|
|
260
|
-
if (socket.config && socket.config.
|
|
261
|
-
this.recordTransfer('out', responseData, socket.config.
|
|
266
|
+
if (socket.config && socket.config.organization_id)
|
|
267
|
+
this.recordTransfer('out', responseData, socket.config.organization_id)
|
|
262
268
|
|
|
263
269
|
}
|
|
264
270
|
|
|
@@ -277,22 +283,22 @@ class SocketServer extends EventEmitter{
|
|
|
277
283
|
}
|
|
278
284
|
if (path.length > 0) {
|
|
279
285
|
params.type = path[1];
|
|
280
|
-
params.
|
|
286
|
+
params.organization_id = path[2]
|
|
281
287
|
}
|
|
282
288
|
return params
|
|
283
289
|
}
|
|
284
290
|
|
|
285
291
|
|
|
286
|
-
sendBinary(socket, data,
|
|
292
|
+
sendBinary(socket, data, organization_id) {
|
|
287
293
|
socket.send(data, {binary: true});
|
|
288
|
-
this.recordTransfer('out', data,
|
|
294
|
+
this.recordTransfer('out', data, organization_id)
|
|
289
295
|
}
|
|
290
296
|
|
|
291
|
-
recordTransfer(type, data,
|
|
297
|
+
recordTransfer(type, data, organization_id) {
|
|
292
298
|
this.emit("setBandwidth", null, {
|
|
293
299
|
type,
|
|
294
300
|
data,
|
|
295
|
-
|
|
301
|
+
organization_id
|
|
296
302
|
});
|
|
297
303
|
|
|
298
304
|
// let date = new Date();
|
|
@@ -306,8 +312,8 @@ class SocketServer extends EventEmitter{
|
|
|
306
312
|
// size = Buffer.byteLength(data, 'utf8');
|
|
307
313
|
// }
|
|
308
314
|
|
|
309
|
-
// if (size > 0 &&
|
|
310
|
-
// console.log (`${
|
|
315
|
+
// if (size > 0 && organization_id) {
|
|
316
|
+
// console.log (`${organization_id} ---- ${type} \t ${date.toISOString()} \t ${size}`);
|
|
311
317
|
// }
|
|
312
318
|
}
|
|
313
319
|
}
|