@cocreate/socket-server 1.28.1 → 1.28.3
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 +23 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.28.3](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.28.2...v1.28.3) (2024-02-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add host ([7542ee7](https://github.com/CoCreate-app/CoCreate-socket-server/commit/7542ee7cb28821515078a912e40574aa0c761b00))
|
|
7
|
+
|
|
8
|
+
## [1.28.2](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.28.1...v1.28.2) (2024-02-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* data.socket removal before sending ([ed9b6a1](https://github.com/CoCreate-app/CoCreate-socket-server/commit/ed9b6a19e8da58a48f5eabd44b2419cc13f3c433))
|
|
14
|
+
|
|
1
15
|
## [1.28.1](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.28.0...v1.28.1) (2024-02-05)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -73,6 +73,7 @@ class SocketServer extends EventEmitter {
|
|
|
73
73
|
let data = {
|
|
74
74
|
socket,
|
|
75
75
|
method: 'object.read',
|
|
76
|
+
host: socket.host,
|
|
76
77
|
array: 'message_log',
|
|
77
78
|
$filter: {
|
|
78
79
|
sort: [
|
|
@@ -95,7 +96,7 @@ class SocketServer extends EventEmitter {
|
|
|
95
96
|
|
|
96
97
|
if (self.authenticate) {
|
|
97
98
|
const { user_id, expires } = await self.authenticate.decodeToken(options.token, organization_id, options.clientId)
|
|
98
|
-
const userStatus = { socket, method: 'userStatus', user_id: options.user_id, clientId: options.clientId, userStatus: 'off', organization_id }
|
|
99
|
+
const userStatus = { socket, method: 'userStatus', host: socket.host, user_id: options.user_id, clientId: options.clientId, userStatus: 'off', organization_id }
|
|
99
100
|
if (user_id) {
|
|
100
101
|
options.user_id = user_id
|
|
101
102
|
socket.user_id = user_id;
|
|
@@ -188,7 +189,7 @@ class SocketServer extends EventEmitter {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
if (socket.user_id) {
|
|
191
|
-
this.emit('userStatus', { socket, user_id: socket.user_id, clientId: socket.clientId, userStatus: 'on', organization_id });
|
|
192
|
+
this.emit('userStatus', { socket, host: socket.host, user_id: socket.user_id, clientId: socket.clientId, userStatus: 'on', organization_id });
|
|
192
193
|
let user = this.users.get(socket.user_id)
|
|
193
194
|
|
|
194
195
|
if (!Array.isArray(user)) {
|
|
@@ -306,7 +307,7 @@ class SocketServer extends EventEmitter {
|
|
|
306
307
|
clearTimeout(userDebounceTimer);
|
|
307
308
|
userDebounceTimer = setTimeout(() => {
|
|
308
309
|
this.users.delete(socket.user_id);
|
|
309
|
-
this.emit('userStatus', { socket, user_id: socket.user_id, clientId: socket.clientId, userStatus: 'off', organization_id });
|
|
310
|
+
this.emit('userStatus', { socket, user_id: socket.user_id, host: socket.host, clientId: socket.clientId, userStatus: 'off', organization_id });
|
|
310
311
|
}, 10000);
|
|
311
312
|
|
|
312
313
|
this.users.set(socket.user_id, userDebounceTimer)
|
|
@@ -356,7 +357,7 @@ class SocketServer extends EventEmitter {
|
|
|
356
357
|
// data.error = 'Token expired'
|
|
357
358
|
// socket.send(JSON.stringify(data))
|
|
358
359
|
await this.send({
|
|
359
|
-
socket, method: 'updateUserStatus', user_id: socket.user_id, clientId: data.clientId, userStatus: 'off', socketId: data.socketId, organization_id
|
|
360
|
+
socket, method: 'updateUserStatus', user_id: socket.user_id, host: socket.host, clientId: data.clientId, userStatus: 'off', socketId: data.socketId, organization_id
|
|
360
361
|
})
|
|
361
362
|
socket.user_id = socket.expires = null
|
|
362
363
|
return
|
|
@@ -460,6 +461,7 @@ class SocketServer extends EventEmitter {
|
|
|
460
461
|
} else {
|
|
461
462
|
const sent = []
|
|
462
463
|
|
|
464
|
+
//TODO: get socket using clientId if socket has been deleted from data
|
|
463
465
|
const authorized = await this.authorize.check(data, socket.user_id)
|
|
464
466
|
if (authorized && authorized.authorized)
|
|
465
467
|
data = authorized.authorized
|
|
@@ -478,21 +480,32 @@ class SocketServer extends EventEmitter {
|
|
|
478
480
|
|
|
479
481
|
let sockets = this.get(data);
|
|
480
482
|
|
|
481
|
-
delete data.socket
|
|
483
|
+
// delete data.socket
|
|
482
484
|
|
|
483
485
|
for (let i = 0; i < sockets.length; i++) {
|
|
484
486
|
if (!sockets[i])
|
|
485
487
|
continue
|
|
486
488
|
|
|
487
489
|
const authorized = await this.authorize.check(data, sockets[i].user_id)
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
let Data
|
|
491
|
+
if (authorized && authorized.authorized) {
|
|
492
|
+
Data = { ...authorized.authorized }
|
|
493
|
+
} else {
|
|
494
|
+
Data = { ...data }
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// TODO: the following code can cause issues in client and improved approach is to check if user has permission and send or dont send
|
|
498
|
+
// if (Data.$filter && Data.$filter.query && Data.$filter.query._id && Data.$filter.query._id.$eq === '$user_id')
|
|
499
|
+
// delete Data.$filter.query._id
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
delete Data.socket
|
|
503
|
+
sockets[i].send(JSON.stringify(Data));
|
|
504
|
+
|
|
492
505
|
sent.push(socket.clientId)
|
|
493
506
|
this.emit("setBandwidth", {
|
|
494
507
|
type: 'out',
|
|
495
|
-
data:
|
|
508
|
+
data: Data,
|
|
496
509
|
organization_id: socket.organization_id
|
|
497
510
|
})
|
|
498
511
|
}
|