@cocreate/socket-server 1.4.18 → 1.4.19
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 +7 -0
- package/package.json +1 -1
- package/src/index.js +34 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.4.19](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.4.18...v1.4.19) (2022-12-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* organization_id ([37b7b72](https://github.com/CoCreate-app/CoCreate-socket-server/commit/37b7b72918fdd6a28ec04b1b26a1822d2d36e1e3))
|
|
7
|
+
|
|
1
8
|
## [1.4.18](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.4.17...v1.4.18) (2022-12-04)
|
|
2
9
|
|
|
3
10
|
|
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,33 @@ 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
135
|
const requestData = JSON.parse(message)
|
|
137
136
|
|
|
138
137
|
if (requestData.action) {
|
|
138
|
+
this.recordTransfer('in', message, organization_id)
|
|
139
|
+
|
|
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(requestData.action, requestData.data, req, user_id)
|
|
147
|
+
if (passStatus !== true) {
|
|
148
|
+
this.send(socket, 'Access Denied', passStatus)
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
142
151
|
}
|
|
152
|
+
|
|
143
153
|
if (user_id) {
|
|
144
154
|
if (!socket.config.user_id ) {
|
|
145
155
|
socket.config.user_id = user_id
|
|
@@ -147,15 +157,6 @@ class SocketServer extends EventEmitter{
|
|
|
147
157
|
this.emit('userStatus', socket, {user_id, userStatus: 'on', organization_id});
|
|
148
158
|
}
|
|
149
159
|
|
|
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
160
|
//. checking async status....
|
|
160
161
|
if (requestData.data.async == true) {
|
|
161
162
|
console.log('async true')
|
|
@@ -165,6 +166,7 @@ class SocketServer extends EventEmitter{
|
|
|
165
166
|
asyncMessage.defineMessage(socket.config.asyncId);
|
|
166
167
|
}
|
|
167
168
|
}
|
|
169
|
+
|
|
168
170
|
this.emit(requestData.action, socket, requestData.data);
|
|
169
171
|
}
|
|
170
172
|
|
|
@@ -189,7 +191,7 @@ class SocketServer extends EventEmitter{
|
|
|
189
191
|
isAsync = true;
|
|
190
192
|
}
|
|
191
193
|
|
|
192
|
-
let organization_id = socket.config.
|
|
194
|
+
let organization_id = socket.config.organization_id;
|
|
193
195
|
let url = `/${this.prefix}/${organization_id}`;
|
|
194
196
|
|
|
195
197
|
let namespace = data.namespace;
|
|
@@ -257,8 +259,8 @@ class SocketServer extends EventEmitter{
|
|
|
257
259
|
socket.send(responseData);
|
|
258
260
|
}
|
|
259
261
|
|
|
260
|
-
if (socket.config && socket.config.
|
|
261
|
-
this.recordTransfer('out', responseData, socket.config.
|
|
262
|
+
if (socket.config && socket.config.organization_id)
|
|
263
|
+
this.recordTransfer('out', responseData, socket.config.organization_id)
|
|
262
264
|
|
|
263
265
|
}
|
|
264
266
|
|
|
@@ -277,22 +279,22 @@ class SocketServer extends EventEmitter{
|
|
|
277
279
|
}
|
|
278
280
|
if (path.length > 0) {
|
|
279
281
|
params.type = path[1];
|
|
280
|
-
params.
|
|
282
|
+
params.organization_id = path[2]
|
|
281
283
|
}
|
|
282
284
|
return params
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
|
|
286
|
-
sendBinary(socket, data,
|
|
288
|
+
sendBinary(socket, data, organization_id) {
|
|
287
289
|
socket.send(data, {binary: true});
|
|
288
|
-
this.recordTransfer('out', data,
|
|
290
|
+
this.recordTransfer('out', data, organization_id)
|
|
289
291
|
}
|
|
290
292
|
|
|
291
|
-
recordTransfer(type, data,
|
|
293
|
+
recordTransfer(type, data, organization_id) {
|
|
292
294
|
this.emit("setBandwidth", null, {
|
|
293
295
|
type,
|
|
294
296
|
data,
|
|
295
|
-
|
|
297
|
+
organization_id
|
|
296
298
|
});
|
|
297
299
|
|
|
298
300
|
// let date = new Date();
|
|
@@ -306,8 +308,8 @@ class SocketServer extends EventEmitter{
|
|
|
306
308
|
// size = Buffer.byteLength(data, 'utf8');
|
|
307
309
|
// }
|
|
308
310
|
|
|
309
|
-
// if (size > 0 &&
|
|
310
|
-
// console.log (`${
|
|
311
|
+
// if (size > 0 && organization_id) {
|
|
312
|
+
// console.log (`${organization_id} ---- ${type} \t ${date.toISOString()} \t ${size}`);
|
|
311
313
|
// }
|
|
312
314
|
}
|
|
313
315
|
}
|