@cocreate/socket-server 1.35.2 → 1.36.0
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/package.json +3 -3
- package/src/index.js +21 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/socket-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"description": "High-density multi-tenant WebSocket orchestration server for real-time state synchronization and cluster-mesh collaboration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"websocket-server",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://cocreate.app/docs/CoCreate-socket-server",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cocreate/config": "^1.
|
|
37
|
-
"@cocreate/utils": "^1.
|
|
36
|
+
"@cocreate/config": "^1.19.0",
|
|
37
|
+
"@cocreate/utils": "^1.52.0",
|
|
38
38
|
"ws": "^8.21.1"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export class SocketServer extends EventEmitter {
|
|
|
32
32
|
|
|
33
33
|
// Cache reference to primary server process manager - Must be defined
|
|
34
34
|
this.server = server;
|
|
35
|
-
this.serverId =
|
|
35
|
+
this.serverId = uuid(12);
|
|
36
36
|
|
|
37
37
|
// Dynamic reference tracking context bound to our cluster process topology
|
|
38
38
|
this.workerId = server.workerId;
|
|
@@ -413,6 +413,12 @@ export class SocketServer extends EventEmitter {
|
|
|
413
413
|
// We implement a resilient 60-second grace period (instead of 10 seconds)
|
|
414
414
|
// to gracefully handle page refreshes, cellular/Wi-Fi toggles, or fast disconnect-reconnect tunnels.
|
|
415
415
|
clearTimeout(organization.debounce);
|
|
416
|
+
|
|
417
|
+
// Guard: Prevent primary platform organization from being evicted when all clients disconnect
|
|
418
|
+
if (this.server && this.server.organization_id && organization_id === this.server.organization_id) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
|
|
416
422
|
organization.debounce = setTimeout(() => {
|
|
417
423
|
const currentOrg = this.organizations.get(organization_id);
|
|
418
424
|
if (currentOrg && currentOrg.clients.size === 0) {
|
|
@@ -473,12 +479,18 @@ export class SocketServer extends EventEmitter {
|
|
|
473
479
|
* Instantly evicts one or more organizations from this worker node,
|
|
474
480
|
* closing all active sockets, freeing maps, and emitting the unified orgDeleted event.
|
|
475
481
|
* Bypasses the 60-second grace period and avoids redundant master mesh IPC packets.
|
|
482
|
+
* Platform organization ID is explicitly excluded from eviction.
|
|
476
483
|
* @param {string|string[]} orgIds - Array of organization IDs to shed
|
|
477
484
|
*/
|
|
478
485
|
destroyOrganizations(orgIds) {
|
|
479
486
|
const ids = Array.isArray(orgIds) ? orgIds : [orgIds];
|
|
480
487
|
|
|
481
488
|
for (const orgId of ids) {
|
|
489
|
+
// Guard: Prevent platform organization ID from being evicted or triggering orgDeleted
|
|
490
|
+
if (this.server && this.server.organization_id && orgId === this.server.organization_id) {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
|
|
482
494
|
const org = this.organizations.get(orgId);
|
|
483
495
|
if (!org) continue;
|
|
484
496
|
|
|
@@ -552,10 +564,10 @@ export class SocketServer extends EventEmitter {
|
|
|
552
564
|
|
|
553
565
|
async onMessage(socket, message) {
|
|
554
566
|
try {
|
|
555
|
-
this.
|
|
567
|
+
this.server.usage.send({
|
|
568
|
+
organization_id: socket.organization_id,
|
|
556
569
|
type: "ingress",
|
|
557
|
-
|
|
558
|
-
organization_id: socket.organization_id
|
|
570
|
+
payload: message
|
|
559
571
|
});
|
|
560
572
|
|
|
561
573
|
let data;
|
|
@@ -565,7 +577,7 @@ export class SocketServer extends EventEmitter {
|
|
|
565
577
|
return this._safeSend(socket, { error: "Invalid JSON payload" });
|
|
566
578
|
}
|
|
567
579
|
|
|
568
|
-
if (data.method){
|
|
580
|
+
if (data.method) {
|
|
569
581
|
this.Message(socket, data);
|
|
570
582
|
} else {
|
|
571
583
|
data.error = "method is required";
|
|
@@ -745,7 +757,7 @@ export class SocketServer extends EventEmitter {
|
|
|
745
757
|
this.emit("object.create", {
|
|
746
758
|
method: "object.create",
|
|
747
759
|
host: data.host || (socket && socket.host),
|
|
748
|
-
array: "
|
|
760
|
+
array: "activities",
|
|
749
761
|
object: logPayload,
|
|
750
762
|
organization_id: data.organization_id
|
|
751
763
|
});
|
|
@@ -805,10 +817,10 @@ export class SocketServer extends EventEmitter {
|
|
|
805
817
|
sent.push(recipientSocket.clientId);
|
|
806
818
|
}
|
|
807
819
|
|
|
808
|
-
this.
|
|
820
|
+
this.server.usage.send({
|
|
821
|
+
organization_id: recipientSocket.organization_id,
|
|
809
822
|
type: "egress",
|
|
810
|
-
|
|
811
|
-
organization_id: recipientSocket.organization_id
|
|
823
|
+
payload: payloadStr
|
|
812
824
|
});
|
|
813
825
|
}
|
|
814
826
|
|