@cocreate/socket-server 1.35.1 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +657 -657
  2. package/package.json +3 -3
  3. package/src/index.js +23 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/socket-server",
3
- "version": "1.35.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.16.0",
37
- "@cocreate/utils": "^1.46.0",
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 = uuid(12);
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.emit("usage", {
567
+ this.server.usage.send({
568
+ organization_id: socket.organization_id,
556
569
  type: "ingress",
557
- data: message,
558
- organization_id: socket.organization_id
570
+ payload: message
559
571
  });
560
572
 
561
573
  let data;
@@ -565,8 +577,9 @@ export class SocketServer extends EventEmitter {
565
577
  return this._safeSend(socket, { error: "Invalid JSON payload" });
566
578
  }
567
579
 
568
- if (data.method) this.Message(socket, data);
569
- else {
580
+ if (data.method) {
581
+ this.Message(socket, data);
582
+ } else {
570
583
  data.error = "method is required";
571
584
  return this._safeSend(socket, data);
572
585
  }
@@ -744,7 +757,7 @@ export class SocketServer extends EventEmitter {
744
757
  this.emit("object.create", {
745
758
  method: "object.create",
746
759
  host: data.host || (socket && socket.host),
747
- array: "message_log",
760
+ array: "activities",
748
761
  object: logPayload,
749
762
  organization_id: data.organization_id
750
763
  });
@@ -804,10 +817,10 @@ export class SocketServer extends EventEmitter {
804
817
  sent.push(recipientSocket.clientId);
805
818
  }
806
819
 
807
- this.emit("usage", {
820
+ this.server.usage.send({
821
+ organization_id: recipientSocket.organization_id,
808
822
  type: "egress",
809
- data: finalDataObj,
810
- organization_id: recipientSocket.organization_id
823
+ payload: payloadStr
811
824
  });
812
825
  }
813
826