openportal 0.1.1 → 0.1.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/README.md +113 -0
- package/package.json +1 -1
- package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_buildManifest.js +4 -9
- package/web/.next/static/chunks/{2e7bfb90c343ca96.js → 35cc9dbdc670c73c.js} +4 -4
- package/web/.next/static/chunks/4147ffc67a7b837c.css +1 -0
- package/web/.next/static/chunks/{21ab2574b84ad2d1.js → 52b90bc1740162c2.js} +2 -2
- package/web/.next/static/chunks/{9b265e2198b5525f.js → 8644d68bf325ff24.js} +3 -3
- package/web/.next/static/chunks/{03e1846335a31354.js → 9865709466b09f79.js} +3 -3
- package/web/.next/static/chunks/{c20ae04df8cc28be.js → 9ba9a5774c9421bd.js} +3 -3
- package/web/.next/static/chunks/{967a1e0002fe9ae6.js → b5caad256518cb33.js} +3 -3
- package/web/.next/static/chunks/{turbopack-27558c851386934e.js → turbopack-26af71e419c11487.js} +1 -1
- package/web/.next/static/chunks/{turbopack-f4c0881f9723f5a5.js → turbopack-4ad0df7330c00c8d.js} +1 -1
- package/web/.next/static/chunks/{turbopack-26688626142ac58f.js → turbopack-8e653f3ad3a8ed18.js} +1 -1
- package/web/.next/static/chunks/{turbopack-c40ec6674624f1d7.js → turbopack-d5098189d63fd7b8.js} +1 -1
- package/web/apps/web/.next/BUILD_ID +1 -1
- package/web/apps/web/.next/build-manifest.json +14 -24
- package/web/apps/web/.next/routes-manifest.json +0 -12
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__f366ca98._.js +358 -0
- package/web/apps/web/.next/server/chunks/ssr/{[root-of-the-server]__dfeaf8cf._.js → [root-of-the-server]__1a54ba1e._.js} +3 -3
- package/web/apps/web/.next/server/middleware-build-manifest.js +12 -22
- package/web/apps/web/.next/server/next-font-manifest.js +1 -1
- package/web/apps/web/.next/server/next-font-manifest.json +0 -4
- package/web/apps/web/.next/server/pages/404.html +1 -1
- package/web/apps/web/.next/server/pages/500.html +1 -1
- package/web/apps/web/.next/server/pages/_app/build-manifest.json +3 -3
- package/web/apps/web/.next/server/pages/_app/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/api/[[...slugs]].js +1 -2
- package/web/apps/web/.next/server/pages/api/[[...slugs]].js.nft.json +1 -1
- package/web/apps/web/.next/server/pages/index/build-manifest.json +3 -3
- package/web/apps/web/.next/server/pages/index/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/index.html +1 -1
- package/web/apps/web/.next/server/pages/index.js.nft.json +1 -1
- package/web/apps/web/.next/server/pages/session/[id]/build-manifest.json +4 -4
- package/web/apps/web/.next/server/pages/session/[id]/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/session/[id].html +1 -1
- package/web/apps/web/.next/server/pages/session/[id].js.nft.json +1 -1
- package/web/apps/web/.next/server/pages/settings/build-manifest.json +3 -3
- package/web/apps/web/.next/server/pages/settings/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/settings.html +1 -1
- package/web/apps/web/.next/server/pages/settings.js.nft.json +1 -1
- package/web/apps/web/.next/server/pages-manifest.json +0 -2
- package/web/apps/web/package.json +1 -9
- package/web/.next/static/chunks/04d4692d75696297.css +0 -1
- package/web/.next/static/chunks/553710f60e2f2b11.js +0 -1
- package/web/.next/static/chunks/58acbbb4090e3362.js +0 -3
- package/web/.next/static/chunks/6ce1e2f08f961db5.js +0 -2
- package/web/.next/static/chunks/d316d63225992c76.js +0 -10
- package/web/.next/static/chunks/e0c97552ba7a9e3d.js +0 -1
- package/web/.next/static/chunks/fc9c4f2dabfb4e0e.css +0 -1
- package/web/.next/static/chunks/turbopack-1837909a677d116b.js +0 -3
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__0f75905d._.js +0 -3
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__89e85365._.js +0 -358
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__ae1361d0._.js +0 -3
- package/web/apps/web/.next/server/pages/api/terminal/ws/pages-manifest.json +0 -3
- package/web/apps/web/.next/server/pages/api/terminal/ws.js +0 -5
- package/web/apps/web/.next/server/pages/api/terminal/ws.js.map +0 -5
- package/web/apps/web/.next/server/pages/api/terminal/ws.js.nft.json +0 -1
- package/web/apps/web/.next/server/pages/terminal/build-manifest.json +0 -20
- package/web/apps/web/.next/server/pages/terminal/client-build-manifest.json +0 -5
- package/web/apps/web/.next/server/pages/terminal/next-font-manifest.json +0 -11
- package/web/apps/web/.next/server/pages/terminal/pages-manifest.json +0 -3
- package/web/apps/web/.next/server/pages/terminal/react-loadable-manifest.json +0 -1
- package/web/apps/web/.next/server/pages/terminal.html +0 -1
- package/web/apps/web/.next/server/pages/terminal.js.map +0 -5
- package/web/apps/web/.next/server/pages/terminal.js.nft.json +0 -1
- package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/cjs/index.js +0 -176
- package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/cjs/package.json +0 -4
- package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/package.json +0 -28
- package/web/node_modules/.bun/accepts@1.3.8/node_modules/accepts/index.js +0 -238
- package/web/node_modules/.bun/accepts@1.3.8/node_modules/accepts/package.json +0 -47
- package/web/node_modules/.bun/base64id@2.0.0/node_modules/base64id/lib/base64id.js +0 -103
- package/web/node_modules/.bun/base64id@2.0.0/node_modules/base64id/package.json +0 -13
- package/web/node_modules/.bun/cookie@0.7.2/node_modules/cookie/index.js +0 -335
- package/web/node_modules/.bun/cookie@0.7.2/node_modules/cookie/package.json +0 -44
- package/web/node_modules/.bun/cookie@1.1.1/node_modules/cookie/package.json +0 -47
- package/web/node_modules/.bun/cors@2.8.5/node_modules/cors/lib/index.js +0 -238
- package/web/node_modules/.bun/cors@2.8.5/node_modules/cors/package.json +0 -41
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/package.json +0 -60
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/browser.js +0 -271
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/common.js +0 -274
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/index.js +0 -10
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/node.js +0 -263
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/commons.js +0 -19
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/decodePacket.js +0 -59
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/encodePacket.js +0 -38
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/index.js +0 -164
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/package.json +0 -8
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/package.json +0 -46
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/engine.io.js +0 -54
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/parser-v3/index.js +0 -424
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/parser-v3/utf8.js +0 -187
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/server.js +0 -786
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/socket.js +0 -460
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transport.js +0 -117
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/index.js +0 -23
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/polling-jsonp.js +0 -41
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/polling.js +0 -332
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/websocket.js +0 -94
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/webtransport.js +0 -63
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/index.js +0 -8
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/polling.js +0 -364
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/websocket.js +0 -73
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/userver.js +0 -279
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/package.json +0 -70
- package/web/node_modules/.bun/has-flag@4.0.0/node_modules/has-flag/index.js +0 -8
- package/web/node_modules/.bun/has-flag@4.0.0/node_modules/has-flag/package.json +0 -46
- package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/db.json +0 -8519
- package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/index.js +0 -12
- package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/package.json +0 -60
- package/web/node_modules/.bun/mime-types@2.1.35/node_modules/mime-types/index.js +0 -188
- package/web/node_modules/.bun/mime-types@2.1.35/node_modules/mime-types/package.json +0 -44
- package/web/node_modules/.bun/ms@2.1.3/node_modules/ms/index.js +0 -162
- package/web/node_modules/.bun/ms@2.1.3/node_modules/ms/package.json +0 -38
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/index.js +0 -82
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/charset.js +0 -169
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/encoding.js +0 -184
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/language.js +0 -179
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/mediaType.js +0 -294
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/package.json +0 -42
- package/web/node_modules/.bun/object-assign@4.1.1/node_modules/object-assign/index.js +0 -90
- package/web/node_modules/.bun/object-assign@4.1.1/node_modules/object-assign/package.json +0 -42
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/cluster-adapter.js +0 -674
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/contrib/yeast.js +0 -55
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/in-memory-adapter.js +0 -394
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/index.js +0 -10
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/package.json +0 -39
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/binary.js +0 -88
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/index.js +0 -321
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/is-binary.js +0 -55
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/package.json +0 -3
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/package.json +0 -58
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.esm.min.js +0 -7
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.js +0 -4908
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.min.js +0 -7
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.msgpack.min.js +0 -7
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/broadcast-operator.js +0 -436
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/client.js +0 -268
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/index.js +0 -804
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/namespace.js +0 -581
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/parent-namespace.js +0 -88
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/socket-types.js +0 -11
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/socket.js +0 -977
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/typed-events.js +0 -81
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/uws.js +0 -136
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/package.json +0 -85
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/wrapper.mjs +0 -3
- package/web/node_modules/.bun/supports-color@7.2.0/node_modules/supports-color/index.js +0 -135
- package/web/node_modules/.bun/supports-color@7.2.0/node_modules/supports-color/package.json +0 -53
- package/web/node_modules/.bun/vary@1.1.2/node_modules/vary/index.js +0 -149
- package/web/node_modules/.bun/vary@1.1.2/node_modules/vary/package.json +0 -43
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/index.js +0 -13
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/buffer-util.js +0 -131
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/constants.js +0 -12
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/event-target.js +0 -292
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/extension.js +0 -203
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/limiter.js +0 -55
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/permessage-deflate.js +0 -514
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/receiver.js +0 -704
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/sender.js +0 -497
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/stream.js +0 -159
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/subprotocol.js +0 -62
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/validation.js +0 -130
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/websocket-server.js +0 -540
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/websocket.js +0 -1338
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/package.json +0 -69
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/buffer-util.js +0 -131
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/constants.js +0 -18
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/event-target.js +0 -292
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/extension.js +0 -203
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/limiter.js +0 -55
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js +0 -528
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/receiver.js +0 -706
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/sender.js +0 -602
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/stream.js +0 -161
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/subprotocol.js +0 -62
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/validation.js +0 -152
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/websocket-server.js +0 -550
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/websocket.js +0 -1388
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/package.json +0 -69
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/wrapper.mjs +0 -8
- /package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_clientMiddlewareManifest.json +0 -0
- /package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_ssgManifest.js +0 -0
|
@@ -1,674 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ClusterAdapterWithHeartbeat = exports.ClusterAdapter = exports.MessageType = void 0;
|
|
15
|
-
const in_memory_adapter_1 = require("./in-memory-adapter");
|
|
16
|
-
const debug_1 = require("debug");
|
|
17
|
-
const crypto_1 = require("crypto");
|
|
18
|
-
const debug = (0, debug_1.debug)("socket.io-adapter");
|
|
19
|
-
const EMITTER_UID = "emitter";
|
|
20
|
-
const DEFAULT_TIMEOUT = 5000;
|
|
21
|
-
function randomId() {
|
|
22
|
-
return (0, crypto_1.randomBytes)(8).toString("hex");
|
|
23
|
-
}
|
|
24
|
-
var MessageType;
|
|
25
|
-
(function (MessageType) {
|
|
26
|
-
MessageType[MessageType["INITIAL_HEARTBEAT"] = 1] = "INITIAL_HEARTBEAT";
|
|
27
|
-
MessageType[MessageType["HEARTBEAT"] = 2] = "HEARTBEAT";
|
|
28
|
-
MessageType[MessageType["BROADCAST"] = 3] = "BROADCAST";
|
|
29
|
-
MessageType[MessageType["SOCKETS_JOIN"] = 4] = "SOCKETS_JOIN";
|
|
30
|
-
MessageType[MessageType["SOCKETS_LEAVE"] = 5] = "SOCKETS_LEAVE";
|
|
31
|
-
MessageType[MessageType["DISCONNECT_SOCKETS"] = 6] = "DISCONNECT_SOCKETS";
|
|
32
|
-
MessageType[MessageType["FETCH_SOCKETS"] = 7] = "FETCH_SOCKETS";
|
|
33
|
-
MessageType[MessageType["FETCH_SOCKETS_RESPONSE"] = 8] = "FETCH_SOCKETS_RESPONSE";
|
|
34
|
-
MessageType[MessageType["SERVER_SIDE_EMIT"] = 9] = "SERVER_SIDE_EMIT";
|
|
35
|
-
MessageType[MessageType["SERVER_SIDE_EMIT_RESPONSE"] = 10] = "SERVER_SIDE_EMIT_RESPONSE";
|
|
36
|
-
MessageType[MessageType["BROADCAST_CLIENT_COUNT"] = 11] = "BROADCAST_CLIENT_COUNT";
|
|
37
|
-
MessageType[MessageType["BROADCAST_ACK"] = 12] = "BROADCAST_ACK";
|
|
38
|
-
MessageType[MessageType["ADAPTER_CLOSE"] = 13] = "ADAPTER_CLOSE";
|
|
39
|
-
})(MessageType = exports.MessageType || (exports.MessageType = {}));
|
|
40
|
-
function encodeOptions(opts) {
|
|
41
|
-
return {
|
|
42
|
-
rooms: [...opts.rooms],
|
|
43
|
-
except: [...opts.except],
|
|
44
|
-
flags: opts.flags,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function decodeOptions(opts) {
|
|
48
|
-
return {
|
|
49
|
-
rooms: new Set(opts.rooms),
|
|
50
|
-
except: new Set(opts.except),
|
|
51
|
-
flags: opts.flags,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A cluster-ready adapter. Any extending class must:
|
|
56
|
-
*
|
|
57
|
-
* - implement {@link ClusterAdapter#doPublish} and {@link ClusterAdapter#doPublishResponse}
|
|
58
|
-
* - call {@link ClusterAdapter#onMessage} and {@link ClusterAdapter#onResponse}
|
|
59
|
-
*/
|
|
60
|
-
class ClusterAdapter extends in_memory_adapter_1.Adapter {
|
|
61
|
-
constructor(nsp) {
|
|
62
|
-
super(nsp);
|
|
63
|
-
this.requests = new Map();
|
|
64
|
-
this.ackRequests = new Map();
|
|
65
|
-
this.uid = randomId();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Called when receiving a message from another member of the cluster.
|
|
69
|
-
*
|
|
70
|
-
* @param message
|
|
71
|
-
* @param offset
|
|
72
|
-
* @protected
|
|
73
|
-
*/
|
|
74
|
-
onMessage(message, offset) {
|
|
75
|
-
if (message.uid === this.uid) {
|
|
76
|
-
return debug("[%s] ignore message from self", this.uid);
|
|
77
|
-
}
|
|
78
|
-
debug("[%s] new event of type %d from %s", this.uid, message.type, message.uid);
|
|
79
|
-
switch (message.type) {
|
|
80
|
-
case MessageType.BROADCAST: {
|
|
81
|
-
const withAck = message.data.requestId !== undefined;
|
|
82
|
-
if (withAck) {
|
|
83
|
-
super.broadcastWithAck(message.data.packet, decodeOptions(message.data.opts), (clientCount) => {
|
|
84
|
-
debug("[%s] waiting for %d client acknowledgements", this.uid, clientCount);
|
|
85
|
-
this.publishResponse(message.uid, {
|
|
86
|
-
type: MessageType.BROADCAST_CLIENT_COUNT,
|
|
87
|
-
data: {
|
|
88
|
-
requestId: message.data.requestId,
|
|
89
|
-
clientCount,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}, (arg) => {
|
|
93
|
-
debug("[%s] received acknowledgement with value %j", this.uid, arg);
|
|
94
|
-
this.publishResponse(message.uid, {
|
|
95
|
-
type: MessageType.BROADCAST_ACK,
|
|
96
|
-
data: {
|
|
97
|
-
requestId: message.data.requestId,
|
|
98
|
-
packet: arg,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
const packet = message.data.packet;
|
|
105
|
-
const opts = decodeOptions(message.data.opts);
|
|
106
|
-
this.addOffsetIfNecessary(packet, opts, offset);
|
|
107
|
-
super.broadcast(packet, opts);
|
|
108
|
-
}
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
case MessageType.SOCKETS_JOIN:
|
|
112
|
-
super.addSockets(decodeOptions(message.data.opts), message.data.rooms);
|
|
113
|
-
break;
|
|
114
|
-
case MessageType.SOCKETS_LEAVE:
|
|
115
|
-
super.delSockets(decodeOptions(message.data.opts), message.data.rooms);
|
|
116
|
-
break;
|
|
117
|
-
case MessageType.DISCONNECT_SOCKETS:
|
|
118
|
-
super.disconnectSockets(decodeOptions(message.data.opts), message.data.close);
|
|
119
|
-
break;
|
|
120
|
-
case MessageType.FETCH_SOCKETS: {
|
|
121
|
-
debug("[%s] calling fetchSockets with opts %j", this.uid, message.data.opts);
|
|
122
|
-
super
|
|
123
|
-
.fetchSockets(decodeOptions(message.data.opts))
|
|
124
|
-
.then((localSockets) => {
|
|
125
|
-
this.publishResponse(message.uid, {
|
|
126
|
-
type: MessageType.FETCH_SOCKETS_RESPONSE,
|
|
127
|
-
data: {
|
|
128
|
-
requestId: message.data.requestId,
|
|
129
|
-
sockets: localSockets.map((socket) => {
|
|
130
|
-
// remove sessionStore from handshake, as it may contain circular references
|
|
131
|
-
const _a = socket.handshake, { sessionStore } = _a, handshake = __rest(_a, ["sessionStore"]);
|
|
132
|
-
return {
|
|
133
|
-
id: socket.id,
|
|
134
|
-
handshake,
|
|
135
|
-
rooms: [...socket.rooms],
|
|
136
|
-
data: socket.data,
|
|
137
|
-
};
|
|
138
|
-
}),
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case MessageType.SERVER_SIDE_EMIT: {
|
|
145
|
-
const packet = message.data.packet;
|
|
146
|
-
const withAck = message.data.requestId !== undefined;
|
|
147
|
-
if (!withAck) {
|
|
148
|
-
this.nsp._onServerSideEmit(packet);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
let called = false;
|
|
152
|
-
const callback = (arg) => {
|
|
153
|
-
// only one argument is expected
|
|
154
|
-
if (called) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
called = true;
|
|
158
|
-
debug("[%s] calling acknowledgement with %j", this.uid, arg);
|
|
159
|
-
this.publishResponse(message.uid, {
|
|
160
|
-
type: MessageType.SERVER_SIDE_EMIT_RESPONSE,
|
|
161
|
-
data: {
|
|
162
|
-
requestId: message.data.requestId,
|
|
163
|
-
packet: arg,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
this.nsp._onServerSideEmit([...packet, callback]);
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
case MessageType.BROADCAST_CLIENT_COUNT:
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
case MessageType.BROADCAST_ACK:
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
case MessageType.FETCH_SOCKETS_RESPONSE:
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
case MessageType.SERVER_SIDE_EMIT_RESPONSE:
|
|
178
|
-
// extending classes may not make a distinction between a ClusterMessage and a ClusterResponse payload and may
|
|
179
|
-
// always call the onMessage() method
|
|
180
|
-
this.onResponse(message);
|
|
181
|
-
break;
|
|
182
|
-
default:
|
|
183
|
-
debug("[%s] unknown message type: %s", this.uid, message.type);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Called when receiving a response from another member of the cluster.
|
|
188
|
-
*
|
|
189
|
-
* @param response
|
|
190
|
-
* @protected
|
|
191
|
-
*/
|
|
192
|
-
onResponse(response) {
|
|
193
|
-
var _a, _b;
|
|
194
|
-
const requestId = response.data.requestId;
|
|
195
|
-
debug("[%s] received response %s to request %s", this.uid, response.type, requestId);
|
|
196
|
-
switch (response.type) {
|
|
197
|
-
case MessageType.BROADCAST_CLIENT_COUNT: {
|
|
198
|
-
(_a = this.ackRequests
|
|
199
|
-
.get(requestId)) === null || _a === void 0 ? void 0 : _a.clientCountCallback(response.data.clientCount);
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case MessageType.BROADCAST_ACK: {
|
|
203
|
-
(_b = this.ackRequests.get(requestId)) === null || _b === void 0 ? void 0 : _b.ack(response.data.packet);
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
case MessageType.FETCH_SOCKETS_RESPONSE: {
|
|
207
|
-
const request = this.requests.get(requestId);
|
|
208
|
-
if (!request) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
request.current++;
|
|
212
|
-
response.data.sockets.forEach((socket) => request.responses.push(socket));
|
|
213
|
-
if (request.current === request.expected) {
|
|
214
|
-
clearTimeout(request.timeout);
|
|
215
|
-
request.resolve(request.responses);
|
|
216
|
-
this.requests.delete(requestId);
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
case MessageType.SERVER_SIDE_EMIT_RESPONSE: {
|
|
221
|
-
const request = this.requests.get(requestId);
|
|
222
|
-
if (!request) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
request.current++;
|
|
226
|
-
request.responses.push(response.data.packet);
|
|
227
|
-
if (request.current === request.expected) {
|
|
228
|
-
clearTimeout(request.timeout);
|
|
229
|
-
request.resolve(null, request.responses);
|
|
230
|
-
this.requests.delete(requestId);
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
default:
|
|
235
|
-
// @ts-ignore
|
|
236
|
-
debug("[%s] unknown response type: %s", this.uid, response.type);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
async broadcast(packet, opts) {
|
|
240
|
-
var _a;
|
|
241
|
-
const onlyLocal = (_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local;
|
|
242
|
-
if (!onlyLocal) {
|
|
243
|
-
try {
|
|
244
|
-
const offset = await this.publishAndReturnOffset({
|
|
245
|
-
type: MessageType.BROADCAST,
|
|
246
|
-
data: {
|
|
247
|
-
packet,
|
|
248
|
-
opts: encodeOptions(opts),
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
this.addOffsetIfNecessary(packet, opts, offset);
|
|
252
|
-
}
|
|
253
|
-
catch (e) {
|
|
254
|
-
return debug("[%s] error while broadcasting message: %s", this.uid, e.message);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
super.broadcast(packet, opts);
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Adds an offset at the end of the data array in order to allow the client to receive any missed packets when it
|
|
261
|
-
* reconnects after a temporary disconnection.
|
|
262
|
-
*
|
|
263
|
-
* @param packet
|
|
264
|
-
* @param opts
|
|
265
|
-
* @param offset
|
|
266
|
-
* @private
|
|
267
|
-
*/
|
|
268
|
-
addOffsetIfNecessary(packet, opts, offset) {
|
|
269
|
-
var _a;
|
|
270
|
-
if (!this.nsp.server.opts.connectionStateRecovery) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const isEventPacket = packet.type === 2;
|
|
274
|
-
// packets with acknowledgement are not stored because the acknowledgement function cannot be serialized and
|
|
275
|
-
// restored on another server upon reconnection
|
|
276
|
-
const withoutAcknowledgement = packet.id === undefined;
|
|
277
|
-
const notVolatile = ((_a = opts.flags) === null || _a === void 0 ? void 0 : _a.volatile) === undefined;
|
|
278
|
-
if (isEventPacket && withoutAcknowledgement && notVolatile) {
|
|
279
|
-
packet.data.push(offset);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
broadcastWithAck(packet, opts, clientCountCallback, ack) {
|
|
283
|
-
var _a;
|
|
284
|
-
const onlyLocal = (_a = opts === null || opts === void 0 ? void 0 : opts.flags) === null || _a === void 0 ? void 0 : _a.local;
|
|
285
|
-
if (!onlyLocal) {
|
|
286
|
-
const requestId = randomId();
|
|
287
|
-
this.ackRequests.set(requestId, {
|
|
288
|
-
clientCountCallback,
|
|
289
|
-
ack,
|
|
290
|
-
});
|
|
291
|
-
this.publish({
|
|
292
|
-
type: MessageType.BROADCAST,
|
|
293
|
-
data: {
|
|
294
|
-
packet,
|
|
295
|
-
requestId,
|
|
296
|
-
opts: encodeOptions(opts),
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
// we have no way to know at this level whether the server has received an acknowledgement from each client, so we
|
|
300
|
-
// will simply clean up the ackRequests map after the given delay
|
|
301
|
-
setTimeout(() => {
|
|
302
|
-
this.ackRequests.delete(requestId);
|
|
303
|
-
}, opts.flags.timeout);
|
|
304
|
-
}
|
|
305
|
-
super.broadcastWithAck(packet, opts, clientCountCallback, ack);
|
|
306
|
-
}
|
|
307
|
-
async addSockets(opts, rooms) {
|
|
308
|
-
var _a;
|
|
309
|
-
const onlyLocal = (_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local;
|
|
310
|
-
if (!onlyLocal) {
|
|
311
|
-
try {
|
|
312
|
-
await this.publishAndReturnOffset({
|
|
313
|
-
type: MessageType.SOCKETS_JOIN,
|
|
314
|
-
data: {
|
|
315
|
-
opts: encodeOptions(opts),
|
|
316
|
-
rooms,
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
catch (e) {
|
|
321
|
-
debug("[%s] error while publishing message: %s", this.uid, e.message);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
super.addSockets(opts, rooms);
|
|
325
|
-
}
|
|
326
|
-
async delSockets(opts, rooms) {
|
|
327
|
-
var _a;
|
|
328
|
-
const onlyLocal = (_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local;
|
|
329
|
-
if (!onlyLocal) {
|
|
330
|
-
try {
|
|
331
|
-
await this.publishAndReturnOffset({
|
|
332
|
-
type: MessageType.SOCKETS_LEAVE,
|
|
333
|
-
data: {
|
|
334
|
-
opts: encodeOptions(opts),
|
|
335
|
-
rooms,
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
catch (e) {
|
|
340
|
-
debug("[%s] error while publishing message: %s", this.uid, e.message);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
super.delSockets(opts, rooms);
|
|
344
|
-
}
|
|
345
|
-
async disconnectSockets(opts, close) {
|
|
346
|
-
var _a;
|
|
347
|
-
const onlyLocal = (_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local;
|
|
348
|
-
if (!onlyLocal) {
|
|
349
|
-
try {
|
|
350
|
-
await this.publishAndReturnOffset({
|
|
351
|
-
type: MessageType.DISCONNECT_SOCKETS,
|
|
352
|
-
data: {
|
|
353
|
-
opts: encodeOptions(opts),
|
|
354
|
-
close,
|
|
355
|
-
},
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
catch (e) {
|
|
359
|
-
debug("[%s] error while publishing message: %s", this.uid, e.message);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
super.disconnectSockets(opts, close);
|
|
363
|
-
}
|
|
364
|
-
async fetchSockets(opts) {
|
|
365
|
-
var _a;
|
|
366
|
-
const [localSockets, serverCount] = await Promise.all([
|
|
367
|
-
super.fetchSockets(opts),
|
|
368
|
-
this.serverCount(),
|
|
369
|
-
]);
|
|
370
|
-
const expectedResponseCount = serverCount - 1;
|
|
371
|
-
if (((_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local) || expectedResponseCount <= 0) {
|
|
372
|
-
return localSockets;
|
|
373
|
-
}
|
|
374
|
-
const requestId = randomId();
|
|
375
|
-
return new Promise((resolve, reject) => {
|
|
376
|
-
const timeout = setTimeout(() => {
|
|
377
|
-
const storedRequest = this.requests.get(requestId);
|
|
378
|
-
if (storedRequest) {
|
|
379
|
-
reject(new Error(`timeout reached: only ${storedRequest.current} responses received out of ${storedRequest.expected}`));
|
|
380
|
-
this.requests.delete(requestId);
|
|
381
|
-
}
|
|
382
|
-
}, opts.flags.timeout || DEFAULT_TIMEOUT);
|
|
383
|
-
const storedRequest = {
|
|
384
|
-
type: MessageType.FETCH_SOCKETS,
|
|
385
|
-
resolve,
|
|
386
|
-
timeout,
|
|
387
|
-
current: 0,
|
|
388
|
-
expected: expectedResponseCount,
|
|
389
|
-
responses: localSockets,
|
|
390
|
-
};
|
|
391
|
-
this.requests.set(requestId, storedRequest);
|
|
392
|
-
this.publish({
|
|
393
|
-
type: MessageType.FETCH_SOCKETS,
|
|
394
|
-
data: {
|
|
395
|
-
opts: encodeOptions(opts),
|
|
396
|
-
requestId,
|
|
397
|
-
},
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
async serverSideEmit(packet) {
|
|
402
|
-
const withAck = typeof packet[packet.length - 1] === "function";
|
|
403
|
-
if (!withAck) {
|
|
404
|
-
return this.publish({
|
|
405
|
-
type: MessageType.SERVER_SIDE_EMIT,
|
|
406
|
-
data: {
|
|
407
|
-
packet,
|
|
408
|
-
},
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
const ack = packet.pop();
|
|
412
|
-
const expectedResponseCount = (await this.serverCount()) - 1;
|
|
413
|
-
debug('[%s] waiting for %d responses to "serverSideEmit" request', this.uid, expectedResponseCount);
|
|
414
|
-
if (expectedResponseCount <= 0) {
|
|
415
|
-
return ack(null, []);
|
|
416
|
-
}
|
|
417
|
-
const requestId = randomId();
|
|
418
|
-
const timeout = setTimeout(() => {
|
|
419
|
-
const storedRequest = this.requests.get(requestId);
|
|
420
|
-
if (storedRequest) {
|
|
421
|
-
ack(new Error(`timeout reached: only ${storedRequest.current} responses received out of ${storedRequest.expected}`), storedRequest.responses);
|
|
422
|
-
this.requests.delete(requestId);
|
|
423
|
-
}
|
|
424
|
-
}, DEFAULT_TIMEOUT);
|
|
425
|
-
const storedRequest = {
|
|
426
|
-
type: MessageType.SERVER_SIDE_EMIT,
|
|
427
|
-
resolve: ack,
|
|
428
|
-
timeout,
|
|
429
|
-
current: 0,
|
|
430
|
-
expected: expectedResponseCount,
|
|
431
|
-
responses: [],
|
|
432
|
-
};
|
|
433
|
-
this.requests.set(requestId, storedRequest);
|
|
434
|
-
this.publish({
|
|
435
|
-
type: MessageType.SERVER_SIDE_EMIT,
|
|
436
|
-
data: {
|
|
437
|
-
requestId,
|
|
438
|
-
packet,
|
|
439
|
-
},
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
publish(message) {
|
|
443
|
-
this.publishAndReturnOffset(message).catch((err) => {
|
|
444
|
-
debug("[%s] error while publishing message: %s", this.uid, err);
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
publishAndReturnOffset(message) {
|
|
448
|
-
message.uid = this.uid;
|
|
449
|
-
message.nsp = this.nsp.name;
|
|
450
|
-
return this.doPublish(message);
|
|
451
|
-
}
|
|
452
|
-
publishResponse(requesterUid, response) {
|
|
453
|
-
response.uid = this.uid;
|
|
454
|
-
response.nsp = this.nsp.name;
|
|
455
|
-
this.doPublishResponse(requesterUid, response).catch((err) => {
|
|
456
|
-
debug("[%s] error while publishing response: %s", this.uid, err);
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
exports.ClusterAdapter = ClusterAdapter;
|
|
461
|
-
class ClusterAdapterWithHeartbeat extends ClusterAdapter {
|
|
462
|
-
constructor(nsp, opts) {
|
|
463
|
-
super(nsp);
|
|
464
|
-
this.nodesMap = new Map(); // uid => timestamp of last message
|
|
465
|
-
this.customRequests = new Map();
|
|
466
|
-
this._opts = Object.assign({
|
|
467
|
-
heartbeatInterval: 5000,
|
|
468
|
-
heartbeatTimeout: 10000,
|
|
469
|
-
}, opts);
|
|
470
|
-
this.cleanupTimer = setInterval(() => {
|
|
471
|
-
const now = Date.now();
|
|
472
|
-
this.nodesMap.forEach((lastSeen, uid) => {
|
|
473
|
-
const nodeSeemsDown = now - lastSeen > this._opts.heartbeatTimeout;
|
|
474
|
-
if (nodeSeemsDown) {
|
|
475
|
-
debug("[%s] node %s seems down", this.uid, uid);
|
|
476
|
-
this.removeNode(uid);
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
}, 1000);
|
|
480
|
-
}
|
|
481
|
-
init() {
|
|
482
|
-
this.publish({
|
|
483
|
-
type: MessageType.INITIAL_HEARTBEAT,
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
scheduleHeartbeat() {
|
|
487
|
-
if (this.heartbeatTimer) {
|
|
488
|
-
this.heartbeatTimer.refresh();
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
this.heartbeatTimer = setTimeout(() => {
|
|
492
|
-
this.publish({
|
|
493
|
-
type: MessageType.HEARTBEAT,
|
|
494
|
-
});
|
|
495
|
-
}, this._opts.heartbeatInterval);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
close() {
|
|
499
|
-
this.publish({
|
|
500
|
-
type: MessageType.ADAPTER_CLOSE,
|
|
501
|
-
});
|
|
502
|
-
clearTimeout(this.heartbeatTimer);
|
|
503
|
-
if (this.cleanupTimer) {
|
|
504
|
-
clearInterval(this.cleanupTimer);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
onMessage(message, offset) {
|
|
508
|
-
if (message.uid === this.uid) {
|
|
509
|
-
return debug("[%s] ignore message from self", this.uid);
|
|
510
|
-
}
|
|
511
|
-
if (message.uid && message.uid !== EMITTER_UID) {
|
|
512
|
-
// we track the UID of each sender, in order to know how many servers there are in the cluster
|
|
513
|
-
this.nodesMap.set(message.uid, Date.now());
|
|
514
|
-
}
|
|
515
|
-
debug("[%s] new event of type %d from %s", this.uid, message.type, message.uid);
|
|
516
|
-
switch (message.type) {
|
|
517
|
-
case MessageType.INITIAL_HEARTBEAT:
|
|
518
|
-
this.publish({
|
|
519
|
-
type: MessageType.HEARTBEAT,
|
|
520
|
-
});
|
|
521
|
-
break;
|
|
522
|
-
case MessageType.HEARTBEAT:
|
|
523
|
-
// nothing to do
|
|
524
|
-
break;
|
|
525
|
-
case MessageType.ADAPTER_CLOSE:
|
|
526
|
-
this.removeNode(message.uid);
|
|
527
|
-
break;
|
|
528
|
-
default:
|
|
529
|
-
super.onMessage(message, offset);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
serverCount() {
|
|
533
|
-
return Promise.resolve(1 + this.nodesMap.size);
|
|
534
|
-
}
|
|
535
|
-
publish(message) {
|
|
536
|
-
this.scheduleHeartbeat();
|
|
537
|
-
return super.publish(message);
|
|
538
|
-
}
|
|
539
|
-
async serverSideEmit(packet) {
|
|
540
|
-
const withAck = typeof packet[packet.length - 1] === "function";
|
|
541
|
-
if (!withAck) {
|
|
542
|
-
return this.publish({
|
|
543
|
-
type: MessageType.SERVER_SIDE_EMIT,
|
|
544
|
-
data: {
|
|
545
|
-
packet,
|
|
546
|
-
},
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
const ack = packet.pop();
|
|
550
|
-
const expectedResponseCount = this.nodesMap.size;
|
|
551
|
-
debug('[%s] waiting for %d responses to "serverSideEmit" request', this.uid, expectedResponseCount);
|
|
552
|
-
if (expectedResponseCount <= 0) {
|
|
553
|
-
return ack(null, []);
|
|
554
|
-
}
|
|
555
|
-
const requestId = randomId();
|
|
556
|
-
const timeout = setTimeout(() => {
|
|
557
|
-
const storedRequest = this.customRequests.get(requestId);
|
|
558
|
-
if (storedRequest) {
|
|
559
|
-
ack(new Error(`timeout reached: missing ${storedRequest.missingUids.size} responses`), storedRequest.responses);
|
|
560
|
-
this.customRequests.delete(requestId);
|
|
561
|
-
}
|
|
562
|
-
}, DEFAULT_TIMEOUT);
|
|
563
|
-
const storedRequest = {
|
|
564
|
-
type: MessageType.SERVER_SIDE_EMIT,
|
|
565
|
-
resolve: ack,
|
|
566
|
-
timeout,
|
|
567
|
-
missingUids: new Set([...this.nodesMap.keys()]),
|
|
568
|
-
responses: [],
|
|
569
|
-
};
|
|
570
|
-
this.customRequests.set(requestId, storedRequest);
|
|
571
|
-
this.publish({
|
|
572
|
-
type: MessageType.SERVER_SIDE_EMIT,
|
|
573
|
-
data: {
|
|
574
|
-
requestId,
|
|
575
|
-
packet,
|
|
576
|
-
},
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
async fetchSockets(opts) {
|
|
580
|
-
var _a;
|
|
581
|
-
const [localSockets, serverCount] = await Promise.all([
|
|
582
|
-
super.fetchSockets({
|
|
583
|
-
rooms: opts.rooms,
|
|
584
|
-
except: opts.except,
|
|
585
|
-
flags: {
|
|
586
|
-
local: true,
|
|
587
|
-
},
|
|
588
|
-
}),
|
|
589
|
-
this.serverCount(),
|
|
590
|
-
]);
|
|
591
|
-
const expectedResponseCount = serverCount - 1;
|
|
592
|
-
if (((_a = opts.flags) === null || _a === void 0 ? void 0 : _a.local) || expectedResponseCount <= 0) {
|
|
593
|
-
return localSockets;
|
|
594
|
-
}
|
|
595
|
-
const requestId = randomId();
|
|
596
|
-
return new Promise((resolve, reject) => {
|
|
597
|
-
const timeout = setTimeout(() => {
|
|
598
|
-
const storedRequest = this.customRequests.get(requestId);
|
|
599
|
-
if (storedRequest) {
|
|
600
|
-
reject(new Error(`timeout reached: missing ${storedRequest.missingUids.size} responses`));
|
|
601
|
-
this.customRequests.delete(requestId);
|
|
602
|
-
}
|
|
603
|
-
}, opts.flags.timeout || DEFAULT_TIMEOUT);
|
|
604
|
-
const storedRequest = {
|
|
605
|
-
type: MessageType.FETCH_SOCKETS,
|
|
606
|
-
resolve,
|
|
607
|
-
timeout,
|
|
608
|
-
missingUids: new Set([...this.nodesMap.keys()]),
|
|
609
|
-
responses: localSockets,
|
|
610
|
-
};
|
|
611
|
-
this.customRequests.set(requestId, storedRequest);
|
|
612
|
-
this.publish({
|
|
613
|
-
type: MessageType.FETCH_SOCKETS,
|
|
614
|
-
data: {
|
|
615
|
-
opts: encodeOptions(opts),
|
|
616
|
-
requestId,
|
|
617
|
-
},
|
|
618
|
-
});
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
onResponse(response) {
|
|
622
|
-
const requestId = response.data.requestId;
|
|
623
|
-
debug("[%s] received response %s to request %s", this.uid, response.type, requestId);
|
|
624
|
-
switch (response.type) {
|
|
625
|
-
case MessageType.FETCH_SOCKETS_RESPONSE: {
|
|
626
|
-
const request = this.customRequests.get(requestId);
|
|
627
|
-
if (!request) {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
response.data.sockets.forEach((socket) => request.responses.push(socket));
|
|
631
|
-
request.missingUids.delete(response.uid);
|
|
632
|
-
if (request.missingUids.size === 0) {
|
|
633
|
-
clearTimeout(request.timeout);
|
|
634
|
-
request.resolve(request.responses);
|
|
635
|
-
this.customRequests.delete(requestId);
|
|
636
|
-
}
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
case MessageType.SERVER_SIDE_EMIT_RESPONSE: {
|
|
640
|
-
const request = this.customRequests.get(requestId);
|
|
641
|
-
if (!request) {
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
request.responses.push(response.data.packet);
|
|
645
|
-
request.missingUids.delete(response.uid);
|
|
646
|
-
if (request.missingUids.size === 0) {
|
|
647
|
-
clearTimeout(request.timeout);
|
|
648
|
-
request.resolve(null, request.responses);
|
|
649
|
-
this.customRequests.delete(requestId);
|
|
650
|
-
}
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
default:
|
|
654
|
-
super.onResponse(response);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
removeNode(uid) {
|
|
658
|
-
this.customRequests.forEach((request, requestId) => {
|
|
659
|
-
request.missingUids.delete(uid);
|
|
660
|
-
if (request.missingUids.size === 0) {
|
|
661
|
-
clearTimeout(request.timeout);
|
|
662
|
-
if (request.type === MessageType.FETCH_SOCKETS) {
|
|
663
|
-
request.resolve(request.responses);
|
|
664
|
-
}
|
|
665
|
-
else if (request.type === MessageType.SERVER_SIDE_EMIT) {
|
|
666
|
-
request.resolve(null, request.responses);
|
|
667
|
-
}
|
|
668
|
-
this.customRequests.delete(requestId);
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
this.nodesMap.delete(uid);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
exports.ClusterAdapterWithHeartbeat = ClusterAdapterWithHeartbeat;
|