cyberia 3.1.3 → 3.2.5
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/.env.example +0 -2
- package/.github/workflows/engine-cyberia.cd.yml +10 -8
- package/.github/workflows/engine-cyberia.ci.yml +12 -29
- package/.github/workflows/ghpkg.ci.yml +4 -4
- package/.github/workflows/npmpkg.ci.yml +28 -11
- package/.github/workflows/publish.ci.yml +21 -2
- package/.github/workflows/pwa-microservices-template-page.cd.yml +4 -5
- package/.github/workflows/pwa-microservices-template-test.ci.yml +3 -3
- package/.github/workflows/release.cd.yml +13 -8
- package/CHANGELOG.md +433 -1
- package/CLI-HELP.md +57 -7
- package/Dockerfile +4 -2
- package/README.md +347 -22
- package/bin/build.js +5 -2
- package/bin/cyberia.js +1789 -112
- package/bin/deploy.js +177 -124
- package/bin/file.js +3 -0
- package/bin/index.js +1789 -112
- package/conf.js +64 -8
- package/deployment.yaml +92 -20
- package/hardhat/hardhat.config.js +13 -13
- package/hardhat/ignition/modules/ObjectLayerToken.js +1 -1
- package/hardhat/package-lock.json +2554 -5859
- package/hardhat/package.json +13 -22
- package/hardhat/scripts/deployObjectLayerToken.js +1 -1
- package/hardhat/test/ObjectLayerToken.js +4 -2
- package/hardhat/types/ethers-contracts/ObjectLayerToken.ts +690 -0
- package/hardhat/types/ethers-contracts/common.ts +92 -0
- package/hardhat/types/ethers-contracts/factories/ObjectLayerToken__factory.ts +1055 -0
- package/hardhat/types/ethers-contracts/factories/index.ts +4 -0
- package/hardhat/types/ethers-contracts/hardhat.d.ts +47 -0
- package/hardhat/types/ethers-contracts/index.ts +6 -0
- package/jsdoc.dd-cyberia.json +64 -55
- package/jsdoc.json +64 -55
- package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +5 -4
- package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +5 -4
- package/manifests/deployment/dd-cyberia-development/deployment.yaml +92 -20
- package/manifests/deployment/dd-cyberia-development/proxy.yaml +54 -18
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +88 -74
- package/manifests/deployment/dd-test-development/proxy.yaml +13 -4
- package/manifests/deployment/playwright/deployment.yaml +1 -1
- package/nodemon.json +1 -1
- package/package.json +22 -16
- package/proxy.yaml +54 -18
- package/scripts/rhel-grpc-setup.sh +56 -0
- package/src/api/atlas-sprite-sheet/atlas-sprite-sheet.controller.js +44 -0
- package/src/api/atlas-sprite-sheet/atlas-sprite-sheet.model.js +16 -0
- package/src/api/atlas-sprite-sheet/atlas-sprite-sheet.router.js +5 -0
- package/src/api/atlas-sprite-sheet/atlas-sprite-sheet.service.js +80 -7
- package/src/api/cyberia-dialogue/cyberia-dialogue.controller.js +93 -0
- package/src/api/cyberia-dialogue/cyberia-dialogue.model.js +36 -0
- package/src/api/cyberia-dialogue/cyberia-dialogue.router.js +29 -0
- package/src/api/cyberia-dialogue/cyberia-dialogue.service.js +51 -0
- package/src/api/cyberia-entity/cyberia-entity.controller.js +74 -0
- package/src/api/cyberia-entity/cyberia-entity.model.js +24 -0
- package/src/api/cyberia-entity/cyberia-entity.router.js +27 -0
- package/src/api/cyberia-entity/cyberia-entity.service.js +42 -0
- package/src/api/cyberia-instance/cyberia-fallback-world.js +368 -0
- package/src/api/cyberia-instance/cyberia-instance.controller.js +92 -0
- package/src/api/cyberia-instance/cyberia-instance.model.js +84 -0
- package/src/api/cyberia-instance/cyberia-instance.router.js +63 -0
- package/src/api/cyberia-instance/cyberia-instance.service.js +191 -0
- package/src/api/cyberia-instance/cyberia-portal-connector.js +486 -0
- package/src/api/cyberia-instance-conf/cyberia-instance-conf.controller.js +74 -0
- package/src/api/cyberia-instance-conf/cyberia-instance-conf.defaults.js +413 -0
- package/src/api/cyberia-instance-conf/cyberia-instance-conf.model.js +228 -0
- package/src/api/cyberia-instance-conf/cyberia-instance-conf.router.js +27 -0
- package/src/api/cyberia-instance-conf/cyberia-instance-conf.service.js +42 -0
- package/src/api/cyberia-map/cyberia-map.controller.js +79 -0
- package/src/api/cyberia-map/cyberia-map.model.js +30 -0
- package/src/api/cyberia-map/cyberia-map.router.js +40 -0
- package/src/api/cyberia-map/cyberia-map.service.js +74 -0
- package/src/api/file/file.ref.json +18 -0
- package/src/api/ipfs/ipfs.controller.js +4 -25
- package/src/api/ipfs/ipfs.model.js +43 -34
- package/src/api/ipfs/ipfs.router.js +8 -13
- package/src/api/ipfs/ipfs.service.js +54 -102
- package/src/api/object-layer/README.md +347 -22
- package/src/api/object-layer/object-layer.router.js +30 -0
- package/src/api/object-layer/object-layer.service.js +114 -31
- package/src/api/user/user.service.js +8 -7
- package/src/cli/cluster.js +7 -7
- package/src/cli/db.js +710 -827
- package/src/cli/deploy.js +151 -93
- package/src/cli/env.js +29 -0
- package/src/cli/fs.js +5 -2
- package/src/cli/index.js +48 -2
- package/src/cli/kubectl.js +211 -0
- package/src/cli/release.js +284 -0
- package/src/cli/repository.js +438 -75
- package/src/cli/run.js +195 -35
- package/src/cli/secrets.js +73 -0
- package/src/cli/test.js +3 -3
- package/src/client/Cryptokoyn.index.js +3 -4
- package/src/client/CyberiaPortal.index.js +3 -4
- package/src/client/Default.index.js +3 -4
- package/src/client/Itemledger.index.js +3 -4
- package/src/client/Underpost.index.js +3 -4
- package/src/client/components/core/AppStore.js +69 -0
- package/src/client/components/core/CalendarCore.js +2 -2
- package/src/client/components/core/DropDown.js +137 -17
- package/src/client/components/core/Keyboard.js +2 -2
- package/src/client/components/core/LogIn.js +2 -2
- package/src/client/components/core/LogOut.js +2 -2
- package/src/client/components/core/Modal.js +0 -1
- package/src/client/components/core/Panel.js +0 -1
- package/src/client/components/core/PanelForm.js +19 -19
- package/src/client/components/core/SocketIo.js +82 -29
- package/src/client/components/core/SocketIoHandler.js +75 -0
- package/src/client/components/core/Stream.js +143 -95
- package/src/client/components/core/Webhook.js +40 -7
- package/src/client/components/cryptokoyn/AppStoreCryptokoyn.js +5 -0
- package/src/client/components/cryptokoyn/LogInCryptokoyn.js +3 -3
- package/src/client/components/cryptokoyn/LogOutCryptokoyn.js +2 -2
- package/src/client/components/cryptokoyn/MenuCryptokoyn.js +3 -3
- package/src/client/components/cryptokoyn/SocketIoCryptokoyn.js +3 -51
- package/src/client/components/cyberia/InstanceEngineCyberia.js +700 -0
- package/src/client/components/cyberia/MapEngineCyberia.js +1359 -2
- package/src/client/components/cyberia/ObjectLayerEngineModal.js +17 -6
- package/src/client/components/cyberia/ObjectLayerEngineViewer.js +92 -54
- package/src/client/components/cyberia-portal/AppStoreCyberiaPortal.js +5 -0
- package/src/client/components/cyberia-portal/CommonCyberiaPortal.js +216 -30
- package/src/client/components/cyberia-portal/LogInCyberiaPortal.js +3 -3
- package/src/client/components/cyberia-portal/LogOutCyberiaPortal.js +2 -2
- package/src/client/components/cyberia-portal/MenuCyberiaPortal.js +40 -7
- package/src/client/components/cyberia-portal/RoutesCyberiaPortal.js +4 -0
- package/src/client/components/cyberia-portal/SocketIoCyberiaPortal.js +3 -49
- package/src/client/components/cyberia-portal/TranslateCyberiaPortal.js +4 -0
- package/src/client/components/default/AppStoreDefault.js +5 -0
- package/src/client/components/default/LogInDefault.js +3 -3
- package/src/client/components/default/LogOutDefault.js +2 -2
- package/src/client/components/default/MenuDefault.js +5 -5
- package/src/client/components/default/SocketIoDefault.js +3 -51
- package/src/client/components/itemledger/AppStoreItemledger.js +5 -0
- package/src/client/components/itemledger/LogInItemledger.js +3 -3
- package/src/client/components/itemledger/LogOutItemledger.js +2 -2
- package/src/client/components/itemledger/MenuItemledger.js +3 -3
- package/src/client/components/itemledger/SocketIoItemledger.js +3 -51
- package/src/client/components/underpost/AppStoreUnderpost.js +5 -0
- package/src/client/components/underpost/LogInUnderpost.js +3 -3
- package/src/client/components/underpost/LogOutUnderpost.js +2 -2
- package/src/client/components/underpost/MenuUnderpost.js +5 -5
- package/src/client/components/underpost/SocketIoUnderpost.js +3 -51
- package/src/client/services/core/core.service.js +20 -8
- package/src/client/services/cyberia-dialogue/cyberia-dialogue.service.js +105 -0
- package/src/client/services/cyberia-entity/cyberia-entity.management.js +57 -0
- package/src/client/services/cyberia-entity/cyberia-entity.service.js +105 -0
- package/src/client/services/cyberia-instance/cyberia-instance.management.js +194 -0
- package/src/client/services/cyberia-instance/cyberia-instance.service.js +122 -0
- package/src/client/services/cyberia-instance-conf/cyberia-instance-conf.service.js +105 -0
- package/src/client/services/cyberia-map/cyberia-map.management.js +193 -0
- package/src/client/services/cyberia-map/cyberia-map.service.js +126 -0
- package/src/client/services/instance/instance.management.js +2 -2
- package/src/client/services/ipfs/ipfs.service.js +3 -23
- package/src/client/services/object-layer/object-layer.management.js +3 -3
- package/src/client/services/object-layer/object-layer.service.js +21 -0
- package/src/client/services/user/user.management.js +2 -2
- package/src/client/ssr/pages/CyberiaServerMetrics.js +1 -1
- package/src/grpc/cyberia/OFF_CHAIN_ECONOMY.md +305 -0
- package/src/grpc/cyberia/README.md +326 -0
- package/src/grpc/cyberia/grpc-server.js +530 -0
- package/src/index.js +24 -1
- package/src/runtime/express/Dockerfile +4 -0
- package/src/runtime/express/Express.js +18 -1
- package/src/runtime/lampp/Dockerfile +13 -2
- package/src/runtime/lampp/Lampp.js +27 -4
- package/src/runtime/wp/Dockerfile +68 -0
- package/src/runtime/wp/Wp.js +639 -0
- package/src/server/auth.js +24 -1
- package/src/server/backup.js +37 -9
- package/src/server/client-build-docs.js +9 -2
- package/src/server/client-build.js +31 -31
- package/src/server/client-formatted.js +109 -57
- package/src/server/conf.js +24 -9
- package/src/server/cron.js +25 -23
- package/src/server/dns.js +2 -1
- package/src/server/ipfs-client.js +24 -1
- package/src/server/object-layer.js +149 -108
- package/src/server/peer.js +8 -0
- package/src/server/runtime.js +25 -1
- package/src/server/semantic-layer-generator-floor.js +359 -0
- package/src/server/semantic-layer-generator-skin.js +1294 -0
- package/src/server/semantic-layer-generator.js +116 -555
- package/src/server/start.js +2 -2
- package/src/ws/IoInterface.js +1 -10
- package/src/ws/IoServer.js +14 -33
- package/src/ws/core/channels/core.ws.chat.js +65 -20
- package/src/ws/core/channels/core.ws.mailer.js +113 -32
- package/src/ws/core/channels/core.ws.stream.js +90 -31
- package/src/ws/core/core.ws.connection.js +12 -33
- package/src/ws/core/core.ws.emit.js +10 -26
- package/src/ws/core/core.ws.server.js +25 -58
- package/src/ws/default/channels/default.ws.main.js +53 -12
- package/src/ws/default/default.ws.connection.js +26 -13
- package/src/ws/default/default.ws.server.js +30 -12
- package/src/client/components/cryptokoyn/CommonCryptokoyn.js +0 -29
- package/src/client/components/cryptokoyn/ElementsCryptokoyn.js +0 -38
- package/src/client/components/cyberia-portal/ElementsCyberiaPortal.js +0 -38
- package/src/client/components/default/ElementsDefault.js +0 -38
- package/src/client/components/itemledger/CommonItemledger.js +0 -29
- package/src/client/components/itemledger/ElementsItemledger.js +0 -38
- package/src/client/components/underpost/CommonUnderpost.js +0 -29
- package/src/client/components/underpost/ElementsUnderpost.js +0 -38
- package/src/ws/core/management/core.ws.chat.js +0 -8
- package/src/ws/core/management/core.ws.mailer.js +0 -16
- package/src/ws/core/management/core.ws.stream.js +0 -8
- package/src/ws/default/management/default.ws.main.js +0 -8
package/src/server/start.js
CHANGED
|
@@ -163,10 +163,9 @@ class UnderpostStartUp {
|
|
|
163
163
|
shellExec(`mkdir -p ${buildBasePath}/engine`);
|
|
164
164
|
shellExec(`cd ${buildBasePath} && sudo cp -a ./${repoName}/. ./engine`);
|
|
165
165
|
shellExec(`cd ${buildBasePath} && sudo rm -rf ./${repoName}`);
|
|
166
|
-
shellExec(`cd ${buildBasePath}/engine && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}-private`);
|
|
167
|
-
shellExec(`cd ${buildBasePath}/engine && sudo mv ./${repoName}-private ./engine-private`);
|
|
168
166
|
}
|
|
169
167
|
shellCd(`${buildBasePath}/engine`);
|
|
168
|
+
Underpost.repo.privateEngineRepoFactory(deployId);
|
|
170
169
|
shellExec(options?.underpostQuicklyInstall ? `underpost install` : `npm install`);
|
|
171
170
|
shellExec(`node bin env ${deployId} ${env}`);
|
|
172
171
|
if (fs.existsSync('./engine-private/itc-scripts')) {
|
|
@@ -197,6 +196,7 @@ class UnderpostStartUp {
|
|
|
197
196
|
shellExec(`node bin env ${deployId} ${env}`);
|
|
198
197
|
shellExec(`npm ${runCmd} ${deployId}`, { async: true });
|
|
199
198
|
await awaitDeployMonitor(true);
|
|
199
|
+
if (env === 'production' && Underpost.env.isInsideContainer()) Underpost.secret.globalSecretClean();
|
|
200
200
|
Underpost.env.set('container-status', `${deployId}-${env}-running-deployment`);
|
|
201
201
|
},
|
|
202
202
|
};
|
package/src/ws/IoInterface.js
CHANGED
|
@@ -126,13 +126,4 @@ class IoChannel {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
* Backward compatibility function to create a new channel instance.
|
|
131
|
-
* @memberof SocketIoInterface
|
|
132
|
-
* @function IoCreateChannel
|
|
133
|
-
* @param {ChannelInterface} IoInterface - The interface object defining the channel's behavior.
|
|
134
|
-
* @returns {IoChannel} An instance of the IoChannel class.
|
|
135
|
-
*/
|
|
136
|
-
const IoCreateChannel = (IoInterface) => new IoChannel(IoInterface);
|
|
137
|
-
|
|
138
|
-
export { IoChannel, IoCreateChannel };
|
|
129
|
+
export { IoChannel };
|
package/src/ws/IoServer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Module for creating and managing WebSocket servers.
|
|
3
|
-
* @module
|
|
4
|
-
* @namespace SocketIoServer
|
|
3
|
+
* @module ws/IoServer
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
'use strict';
|
|
@@ -9,33 +8,27 @@
|
|
|
9
8
|
import { Server } from 'socket.io';
|
|
10
9
|
import { loggerFactory } from '../server/logger.js';
|
|
11
10
|
import Underpost from '../index.js';
|
|
12
|
-
import http from 'http';
|
|
13
11
|
|
|
14
12
|
const logger = loggerFactory(import.meta);
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
|
-
* @class
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
20
|
-
* @classdesc Provides a static factory method to create and configure a Socket.IO server,
|
|
21
|
-
* encapsulating WebSocket server initialization logic and CORS configuration.
|
|
15
|
+
* @class IoServer
|
|
16
|
+
* @classdesc Factory for creating and configuring Socket.IO server instances
|
|
17
|
+
* with CORS configuration and HTTP server attachment.
|
|
22
18
|
*/
|
|
23
|
-
class
|
|
19
|
+
class IoServer {
|
|
24
20
|
/**
|
|
25
21
|
* Creates a new WebSocket server instance attached to an HTTP server.
|
|
26
22
|
*
|
|
27
23
|
* @static
|
|
28
|
-
* @param {http.Server} httpServer - The HTTP server instance to attach
|
|
29
|
-
* @param {Object} options - Configuration options
|
|
30
|
-
* @param {string[]} options.origins -
|
|
31
|
-
* @param {string} options.path -
|
|
32
|
-
* @param {function(import('socket.io').Socket): void}
|
|
33
|
-
* @returns {
|
|
34
|
-
* @returns {import('socket.io').ServerOptions} return.options - The final options object used to create the WebSocket server.
|
|
35
|
-
* @returns {import('socket.io').Server} return.ioServer - The created and listening WebSocket server instance.
|
|
36
|
-
* @returns {object} return.meta - The module's import meta object (`import.meta`).
|
|
24
|
+
* @param {import('http').Server} httpServer - The HTTP server instance to attach to.
|
|
25
|
+
* @param {Object} options - Configuration options.
|
|
26
|
+
* @param {string[]} options.origins - Allowed CORS origins.
|
|
27
|
+
* @param {string} options.path - Base API path. Socket.IO path is appended automatically.
|
|
28
|
+
* @param {function(import('socket.io').Socket): void} connectionHandler - Handler for new connections.
|
|
29
|
+
* @returns {{ options: import('socket.io').ServerOptions, ioServer: import('socket.io').Server, meta: ImportMeta }}
|
|
37
30
|
*/
|
|
38
|
-
static create(httpServer, options = {},
|
|
31
|
+
static create(httpServer, options = {}, connectionHandler = () => {}) {
|
|
39
32
|
logger.info('origins', options.origins);
|
|
40
33
|
const wsOptions = {
|
|
41
34
|
cors: {
|
|
@@ -55,12 +48,11 @@ class IoServerClass {
|
|
|
55
48
|
],
|
|
56
49
|
credentials: true,
|
|
57
50
|
},
|
|
58
|
-
// Ensure the path ends correctly, appending '/socket.io/'
|
|
59
51
|
path: options.path !== '/' ? `${options.path}/socket.io/` : '/socket.io/',
|
|
60
52
|
};
|
|
61
53
|
|
|
62
54
|
const ioServerInstance = Underpost.start.listenServerFactory(() =>
|
|
63
|
-
new Server(httpServer, wsOptions).on('connection',
|
|
55
|
+
new Server(httpServer, wsOptions).on('connection', connectionHandler),
|
|
64
56
|
);
|
|
65
57
|
|
|
66
58
|
logger.info('Socket.IO Server created and listening', { path: wsOptions.path });
|
|
@@ -73,15 +65,4 @@ class IoServerClass {
|
|
|
73
65
|
}
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
* Backward compatibility export for the server creation function.
|
|
78
|
-
* @memberof SocketIoServer
|
|
79
|
-
* @function IoServer
|
|
80
|
-
* @param {http.Server} httpServer - The HTTP server instance.
|
|
81
|
-
* @param {Object} options - Configuration options.
|
|
82
|
-
* @param {function(import('socket.io').Socket): void} ConnectionHandler - The connection handler function.
|
|
83
|
-
* @returns {Object} The server configuration object.
|
|
84
|
-
*/
|
|
85
|
-
const IoServer = IoServerClass.create;
|
|
86
|
-
|
|
87
|
-
export { IoServerClass, IoServer };
|
|
68
|
+
export { IoServer };
|
|
@@ -1,23 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Chat WebSocket channel — broadcasts messages to all connected sockets except the sender.
|
|
3
|
+
* @module ws/core/channels/core.ws.chat
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IoChannel } from '../../IoInterface.js';
|
|
7
|
+
import { CoreWsEmitter } from '../core.ws.emit.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class CoreWsChatChannel
|
|
11
|
+
* @classdesc Manages the chat WebSocket channel with per-instance state.
|
|
12
|
+
* Broadcasts incoming messages to all other connected sockets.
|
|
13
|
+
*/
|
|
14
|
+
class CoreWsChatChannel {
|
|
15
|
+
/** @type {Object.<string, Object>} Per-instance state keyed by wsManagementId. */
|
|
16
|
+
static #state = {};
|
|
17
|
+
|
|
18
|
+
/** @type {IoChannel} */
|
|
19
|
+
static #io = new IoChannel({
|
|
20
|
+
channel: 'chat',
|
|
21
|
+
controller(socket, client, payload, wsManagementId) {
|
|
22
|
+
for (const socketId of Object.keys(client)) {
|
|
23
|
+
if (socketId !== socket.id) {
|
|
24
|
+
CoreWsEmitter.emit('chat', client[socketId], { id: socket.id, ...payload });
|
|
25
|
+
}
|
|
14
26
|
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/** @returns {Object.<string, import('socket.io').Socket>} Connected sockets map. */
|
|
31
|
+
static get client() {
|
|
32
|
+
return this.#io.client;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @returns {string} Channel name. */
|
|
36
|
+
static get channel() {
|
|
37
|
+
return this.#io.channel;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Initializes state for a server instance.
|
|
42
|
+
* @param {string} wsManagementId - Unique server context ID.
|
|
43
|
+
*/
|
|
44
|
+
static init(wsManagementId) {
|
|
45
|
+
this.#state[wsManagementId] = {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Registers a socket connection.
|
|
50
|
+
* @param {import('socket.io').Socket} socket
|
|
51
|
+
* @param {string} wsManagementId
|
|
52
|
+
*/
|
|
53
|
+
static connection(socket, wsManagementId) {
|
|
54
|
+
return this.#io.connection(socket, wsManagementId);
|
|
55
|
+
}
|
|
20
56
|
|
|
21
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Handles socket disconnection.
|
|
59
|
+
* @param {import('socket.io').Socket} socket
|
|
60
|
+
* @param {string} reason
|
|
61
|
+
* @param {string} wsManagementId
|
|
62
|
+
*/
|
|
63
|
+
static disconnect(socket, reason, wsManagementId) {
|
|
64
|
+
return this.#io.disconnect(socket, reason, wsManagementId);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
22
67
|
|
|
23
|
-
export { CoreWsChatChannel
|
|
68
|
+
export { CoreWsChatChannel };
|
|
@@ -1,35 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Mailer WebSocket channel — manages user↔socket bidirectional mapping
|
|
3
|
+
* for targeted real-time pushes (e.g. email confirmation notifications).
|
|
4
|
+
* @module ws/core/channels/core.ws.mailer
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { IoChannel } from '../../IoInterface.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class CoreWsMailerChannel
|
|
11
|
+
* @classdesc Manages the mailer WebSocket channel with O(1) user↔socket lookup.
|
|
12
|
+
* Handles register/unregister messages and cleanup on disconnect.
|
|
13
|
+
*/
|
|
14
|
+
class CoreWsMailerChannel {
|
|
15
|
+
/** @type {Object.<string, Object.<string, { model: { user: Object } }>>} Socket data keyed by `[wsManagementId][socketId]`. */
|
|
16
|
+
static #data = {};
|
|
17
|
+
|
|
18
|
+
/** @type {Object.<string, Object.<string, string>>} Reverse index: `[wsManagementId][userId]` → socketId. */
|
|
19
|
+
static #userIndex = {};
|
|
20
|
+
|
|
21
|
+
/** @type {IoChannel} */
|
|
22
|
+
static #io = new IoChannel({
|
|
23
|
+
channel: 'mailer',
|
|
24
|
+
controller(socket, client, payload, wsManagementId) {
|
|
25
|
+
switch (payload.status) {
|
|
26
|
+
case 'register-user':
|
|
27
|
+
CoreWsMailerChannel.setUser(wsManagementId, socket.id, payload.user);
|
|
28
|
+
break;
|
|
29
|
+
case 'unregister-user':
|
|
30
|
+
CoreWsMailerChannel.removeSocket(wsManagementId, socket.id);
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
disconnect(socket, client, reason, wsManagementId) {
|
|
37
|
+
CoreWsMailerChannel.removeSocket(wsManagementId, socket.id);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** @returns {Object.<string, import('socket.io').Socket>} Connected sockets map. */
|
|
42
|
+
static get client() {
|
|
43
|
+
return this.#io.client;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @returns {string} Channel name. */
|
|
47
|
+
static get channel() {
|
|
48
|
+
return this.#io.channel;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initializes state for a server instance.
|
|
53
|
+
* @param {string} wsManagementId - Unique server context ID (`${host}${path}`).
|
|
54
|
+
*/
|
|
55
|
+
static init(wsManagementId) {
|
|
56
|
+
this.#data[wsManagementId] = {};
|
|
57
|
+
this.#userIndex[wsManagementId] = {};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Registers a socket connection.
|
|
62
|
+
* @param {import('socket.io').Socket} socket
|
|
63
|
+
* @param {string} wsManagementId
|
|
64
|
+
*/
|
|
65
|
+
static connection(socket, wsManagementId) {
|
|
66
|
+
return this.#io.connection(socket, wsManagementId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Handles socket disconnection.
|
|
71
|
+
* @param {import('socket.io').Socket} socket
|
|
72
|
+
* @param {string} reason
|
|
73
|
+
* @param {string} wsManagementId
|
|
74
|
+
*/
|
|
75
|
+
static disconnect(socket, reason, wsManagementId) {
|
|
76
|
+
return this.#io.disconnect(socket, reason, wsManagementId);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Registers a user↔socket mapping.
|
|
81
|
+
* @param {string} wsManagementId
|
|
82
|
+
* @param {string} socketId
|
|
83
|
+
* @param {Object} user - User data with `_id` property.
|
|
84
|
+
*/
|
|
85
|
+
static setUser(wsManagementId, socketId, user) {
|
|
86
|
+
this.#data[wsManagementId][socketId] = { model: { user } };
|
|
87
|
+
if (user?._id) {
|
|
88
|
+
this.#userIndex[wsManagementId][user._id.toString()] = socketId;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Removes a socket entry and its reverse user index.
|
|
94
|
+
* @param {string} wsManagementId
|
|
95
|
+
* @param {string} socketId
|
|
96
|
+
*/
|
|
97
|
+
static removeSocket(wsManagementId, socketId) {
|
|
98
|
+
const entry = this.#data[wsManagementId]?.[socketId];
|
|
99
|
+
if (entry?.model?.user?._id) {
|
|
100
|
+
delete this.#userIndex[wsManagementId][entry.model.user._id.toString()];
|
|
25
101
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
disconnect: function (socket, client, reason, wsManagementId) {
|
|
29
|
-
delete CoreWsMailerManagement.element[wsManagementId][socket.id];
|
|
30
|
-
},
|
|
31
|
-
};
|
|
102
|
+
delete this.#data[wsManagementId]?.[socketId];
|
|
103
|
+
}
|
|
32
104
|
|
|
33
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Finds the socket ID for a user (O(1) reverse index lookup).
|
|
107
|
+
* @param {string} wsManagementId
|
|
108
|
+
* @param {string} userId - The user `_id`.
|
|
109
|
+
* @returns {string|undefined} Socket ID, or `undefined` if not connected.
|
|
110
|
+
*/
|
|
111
|
+
static getUserWsId(wsManagementId, userId) {
|
|
112
|
+
return this.#userIndex[wsManagementId]?.[userId];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
34
115
|
|
|
35
|
-
export { CoreWsMailerChannel
|
|
116
|
+
export { CoreWsMailerChannel };
|
|
@@ -1,31 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Stream WebSocket channel — manages per-socket room membership and user tracking.
|
|
3
|
+
* @module ws/core/channels/core.ws.stream
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IoChannel } from '../../IoInterface.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @class CoreWsStreamChannel
|
|
10
|
+
* @classdesc Manages the stream WebSocket channel. Each socket can join a room
|
|
11
|
+
* and broadcast connection/disconnection events to other room members.
|
|
12
|
+
*/
|
|
13
|
+
class CoreWsStreamChannel {
|
|
14
|
+
/** @type {Object.<string, Object.<string, Array>>} Per-socket room/user args keyed by `[wsManagementId][socketId]`. */
|
|
15
|
+
static #state = {};
|
|
16
|
+
|
|
17
|
+
/** @type {IoChannel} */
|
|
18
|
+
static #io = new IoChannel({
|
|
19
|
+
channel: 'stream',
|
|
20
|
+
stream: true,
|
|
21
|
+
controller(socket, client, payload, wsManagementId, args) {
|
|
22
|
+
const [roomId, userId] = args;
|
|
23
|
+
|
|
24
|
+
// Collect existing users in the room before registering the new one
|
|
25
|
+
const existingUsers = [];
|
|
26
|
+
for (const entry of Object.values(CoreWsStreamChannel.#state[wsManagementId])) {
|
|
27
|
+
if (entry[0] === roomId && entry[1]) existingUsers.push(entry[1]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
CoreWsStreamChannel.#state[wsManagementId][socket.id] = args;
|
|
31
|
+
socket.join(roomId);
|
|
32
|
+
socket.to(roomId).emit('stream-user-connected', userId);
|
|
33
|
+
|
|
34
|
+
// Tell the joining user about everyone already in the room
|
|
35
|
+
if (existingUsers.length > 0) socket.emit('stream-existing-users', existingUsers);
|
|
36
|
+
},
|
|
37
|
+
connection(socket, client, wsManagementId) {
|
|
38
|
+
CoreWsStreamChannel.#state[wsManagementId][socket.id] = [];
|
|
39
|
+
},
|
|
40
|
+
disconnect(socket, client, reason, wsManagementId) {
|
|
41
|
+
const entry = CoreWsStreamChannel.#state[wsManagementId]?.[socket.id];
|
|
42
|
+
if (!entry || entry.length === 0) {
|
|
43
|
+
if (CoreWsStreamChannel.#state[wsManagementId]) delete CoreWsStreamChannel.#state[wsManagementId][socket.id];
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const [roomId, userId] = entry;
|
|
47
|
+
socket.to(roomId).emit('stream-user-disconnected', userId);
|
|
48
|
+
delete CoreWsStreamChannel.#state[wsManagementId][socket.id];
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/** @returns {Object.<string, import('socket.io').Socket>} Connected sockets map. */
|
|
53
|
+
static get client() {
|
|
54
|
+
return this.#io.client;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @returns {string} Channel name. */
|
|
58
|
+
static get channel() {
|
|
59
|
+
return this.#io.channel;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Initializes state for a server instance.
|
|
64
|
+
* @param {string} wsManagementId - Unique server context ID (`${host}${path}`).
|
|
65
|
+
*/
|
|
66
|
+
static init(wsManagementId) {
|
|
67
|
+
this.#state[wsManagementId] = {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Registers a socket connection.
|
|
72
|
+
* @param {import('socket.io').Socket} socket
|
|
73
|
+
* @param {string} wsManagementId
|
|
74
|
+
*/
|
|
75
|
+
static connection(socket, wsManagementId) {
|
|
76
|
+
return this.#io.connection(socket, wsManagementId);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Handles socket disconnection.
|
|
81
|
+
* @param {import('socket.io').Socket} socket
|
|
82
|
+
* @param {string} reason
|
|
83
|
+
* @param {string} wsManagementId
|
|
84
|
+
*/
|
|
85
|
+
static disconnect(socket, reason, wsManagementId) {
|
|
86
|
+
return this.#io.disconnect(socket, reason, wsManagementId);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { CoreWsStreamChannel };
|
|
@@ -1,47 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @module ws/core.ws.connection
|
|
4
|
-
* @namespace CoreWsConnection
|
|
2
|
+
* Core WebSocket connection handler — wires sockets to all channels.
|
|
3
|
+
* @module ws/core/core.ws.connection
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { loggerFactory } from '../../server/logger.js';
|
|
8
7
|
import { CoreWsChatChannel } from './channels/core.ws.chat.js';
|
|
9
8
|
import { CoreWsMailerChannel } from './channels/core.ws.mailer.js';
|
|
10
9
|
import { CoreWsStreamChannel } from './channels/core.ws.stream.js';
|
|
11
|
-
import { Socket } from 'socket.io'; // Added for JSDoc type hinting
|
|
12
10
|
|
|
13
11
|
const logger = loggerFactory(import.meta);
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
|
-
* @class
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
* @classdesc Manages the lifecycle of a new WebSocket connection, setting up listeners for
|
|
20
|
-
* all registered channels (Chat, Mailer, Stream) and handling disconnection by delegating to channel handlers.
|
|
14
|
+
* @class CoreWsConnectionHandler
|
|
15
|
+
* @classdesc Subscribes a new socket to all core channels (chat, mailer, stream)
|
|
16
|
+
* and delegates disconnect events to each channel.
|
|
21
17
|
*/
|
|
22
|
-
class
|
|
18
|
+
class CoreWsConnectionHandler {
|
|
23
19
|
/**
|
|
24
|
-
* Handles a new WebSocket connection
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @static
|
|
28
|
-
* @param {Socket} socket - The Socket.IO socket object representing the client connection.
|
|
29
|
-
* @param {string} wsManagementId - Unique identifier for the WebSocket management context.
|
|
30
|
-
* @returns {void}
|
|
20
|
+
* Handles a new WebSocket connection.
|
|
21
|
+
* @param {import('socket.io').Socket} socket
|
|
22
|
+
* @param {string} wsManagementId
|
|
31
23
|
*/
|
|
32
|
-
static
|
|
24
|
+
static handle(socket, wsManagementId) {
|
|
33
25
|
logger.info(`New connection established. Socket ID: ${socket.id}`);
|
|
34
26
|
|
|
35
|
-
// Subscribe socket to all channel connection handlers (assuming these channels are IoChannel instances)
|
|
36
27
|
CoreWsChatChannel.connection(socket, wsManagementId);
|
|
37
28
|
CoreWsMailerChannel.connection(socket, wsManagementId);
|
|
38
29
|
CoreWsStreamChannel.connection(socket, wsManagementId);
|
|
39
30
|
|
|
40
|
-
// Set up the disconnect listener
|
|
41
31
|
socket.on('disconnect', (reason) => {
|
|
42
|
-
logger.info(`Connection disconnected. Socket ID: ${socket.id}
|
|
32
|
+
logger.info(`Connection disconnected. Socket ID: ${socket.id}, reason: ${reason}`);
|
|
43
33
|
|
|
44
|
-
// Notify all channels of the disconnection
|
|
45
34
|
CoreWsChatChannel.disconnect(socket, reason, wsManagementId);
|
|
46
35
|
CoreWsMailerChannel.disconnect(socket, reason, wsManagementId);
|
|
47
36
|
CoreWsStreamChannel.disconnect(socket, reason, wsManagementId);
|
|
@@ -49,14 +38,4 @@ class CoreWsConnectionManager {
|
|
|
49
38
|
}
|
|
50
39
|
}
|
|
51
40
|
|
|
52
|
-
|
|
53
|
-
* Backward compatibility export for the connection handler function.
|
|
54
|
-
* @memberof CoreWsConnection
|
|
55
|
-
* @function CoreWsConnection
|
|
56
|
-
* @param {Socket} socket - The Socket.IO socket object.
|
|
57
|
-
* @param {string} wsManagementId - Unique identifier for the WebSocket management context.
|
|
58
|
-
* @returns {void}
|
|
59
|
-
*/
|
|
60
|
-
const CoreWsConnection = CoreWsConnectionManager.handleConnection;
|
|
61
|
-
|
|
62
|
-
export { CoreWsConnectionManager, CoreWsConnection };
|
|
41
|
+
export { CoreWsConnectionHandler };
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @module ws/core.ws.emit
|
|
4
|
-
* @namespace CoreWsEmitter
|
|
2
|
+
* Standardized WebSocket message emission.
|
|
3
|
+
* @module ws/core/core.ws.emit
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { loggerFactory } from '../../server/logger.js';
|
|
8
|
-
import { Socket } from 'socket.io';
|
|
9
7
|
|
|
10
8
|
const logger = loggerFactory(import.meta);
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* @class CoreWsEmitter
|
|
14
|
-
* @
|
|
15
|
-
* @memberof CoreWsEmitter
|
|
16
|
-
* @classdesc Provides a static utility method for safely emitting messages over a WebSocket connection.
|
|
12
|
+
* @classdesc Provides a static utility for safely emitting JSON-serialized messages over Socket.IO.
|
|
17
13
|
*/
|
|
18
14
|
class CoreWsEmitter {
|
|
19
15
|
/**
|
|
20
|
-
* Emits a payload to a
|
|
21
|
-
* The payload is automatically JSON stringified.
|
|
16
|
+
* Emits a JSON-stringified payload to a client on a given channel.
|
|
22
17
|
*
|
|
23
18
|
* @static
|
|
24
|
-
* @param {string}
|
|
25
|
-
* @param {Socket
|
|
26
|
-
* @param {Object}
|
|
19
|
+
* @param {string} channel - The channel/event name to emit on.
|
|
20
|
+
* @param {import('socket.io').Socket} client - The Socket.IO socket to emit to.
|
|
21
|
+
* @param {Object} payload - The data object to send.
|
|
27
22
|
* @returns {void}
|
|
28
23
|
*/
|
|
29
24
|
static emit(channel = '', client = {}, payload = {}) {
|
|
@@ -31,23 +26,12 @@ class CoreWsEmitter {
|
|
|
31
26
|
if (client && typeof client.emit === 'function') {
|
|
32
27
|
client.emit(channel, JSON.stringify(payload));
|
|
33
28
|
} else {
|
|
34
|
-
logger.error('Invalid client: Cannot emit message.', { channel,
|
|
29
|
+
logger.error('Invalid client: Cannot emit message.', { channel, payload });
|
|
35
30
|
}
|
|
36
31
|
} catch (error) {
|
|
37
|
-
logger.error(error, { channel,
|
|
32
|
+
logger.error(error, { channel, payload, stack: error.stack });
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
* Backward compatibility export for the `emit` function.
|
|
44
|
-
* @memberof CoreWsEmitter
|
|
45
|
-
* @function CoreWsEmit
|
|
46
|
-
* @param {string} [channel=''] - The name of the channel/event to emit on.
|
|
47
|
-
* @param {Socket | Object} [client={}] - The Socket.IO client/socket object.
|
|
48
|
-
* @param {Object} [payload={}] - The data object to send.
|
|
49
|
-
* @returns {void}
|
|
50
|
-
*/
|
|
51
|
-
const CoreWsEmit = CoreWsEmitter.emit;
|
|
52
|
-
|
|
53
|
-
export { CoreWsEmitter, CoreWsEmit };
|
|
37
|
+
export { CoreWsEmitter };
|