@eleven-am/pondsocket 0.1.213 → 0.1.215
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/abstracts/distributor.d.ts +13 -0
- package/abstracts/distributor.js +121 -54
- package/abstracts/middleware.d.ts +22 -0
- package/abstracts/middleware.js +8 -1
- package/abstracts/types.d.ts +64 -0
- package/abstracts/types.js +0 -14
- package/contexts/baseContext.d.ts +20 -0
- package/contexts/baseContext.js +17 -25
- package/contexts/connectionContext.d.ts +66 -0
- package/contexts/eventContext.d.ts +15 -0
- package/contexts/eventContext.js +5 -49
- package/contexts/joinContext.d.ts +17 -0
- package/contexts/joinContext.js +5 -54
- package/contexts/outgoingContext.d.ts +28 -0
- package/contexts/outgoingContext.js +3 -0
- package/engines/channelEngine.d.ts +26 -0
- package/engines/channelEngine.js +212 -192
- package/engines/endpointEngine.d.ts +34 -0
- package/engines/endpointEngine.js +15 -7
- package/engines/lobbyEngine.d.ts +54 -0
- package/engines/lobbyEngine.js +1 -1
- package/engines/presenceEngine.d.ts +15 -0
- package/engines/presenceEngine.js +6 -59
- package/errors/httpError.d.ts +6 -0
- package/errors/httpError.js +2 -0
- package/index.d.ts +14 -5
- package/index.js +37 -3
- package/matcher/matcher.d.ts +2 -0
- package/matcher/matcher.js +5 -5
- package/package.json +41 -18
- package/server/server.d.ts +21 -0
- package/server/server.js +48 -12
- package/types.d.ts +32 -621
- package/types.js +16 -0
- package/wrappers/channel.d.ts +54 -0
- package/wrappers/endpoint.d.ts +10 -0
- package/wrappers/pondChannel.d.ts +15 -0
package/server/server.js
CHANGED
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _PondSocket_instances, _PondSocket_server, _PondSocket_exclusiveServer, _PondSocket_socketServer, _PondSocket_backend, _PondSocket_middleware, _PondSocket_handleUpgrade, _PondSocket_manageHeartbeat, _PondSocket_init, _PondSocket_getCookies;
|
|
13
|
+
var _PondSocket_instances, _PondSocket_server, _PondSocket_exclusiveServer, _PondSocket_socketServer, _PondSocket_backend, _PondSocket_middleware, _PondSocket_maxMessageSize, _PondSocket_heartbeatMs, _PondSocket_heartbeatTimer, _PondSocket_handleUpgrade, _PondSocket_manageHeartbeat, _PondSocket_init, _PondSocket_getCookies;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PondSocket = void 0;
|
|
16
16
|
const http_1 = require("http");
|
|
@@ -22,17 +22,22 @@ const endpointEngine_1 = require("../engines/endpointEngine");
|
|
|
22
22
|
const matcher_1 = require("../matcher/matcher");
|
|
23
23
|
const endpoint_1 = require("../wrappers/endpoint");
|
|
24
24
|
class PondSocket {
|
|
25
|
-
constructor({ server, socketServer, exclusiveServer = true, distributedBackend, } = {}) {
|
|
25
|
+
constructor({ server, socketServer, exclusiveServer = true, distributedBackend, maxMessageSize = 1024 * 1024, heartbeatInterval = 30000, } = {}) {
|
|
26
26
|
_PondSocket_instances.add(this);
|
|
27
27
|
_PondSocket_server.set(this, void 0);
|
|
28
28
|
_PondSocket_exclusiveServer.set(this, void 0);
|
|
29
29
|
_PondSocket_socketServer.set(this, void 0);
|
|
30
30
|
_PondSocket_backend.set(this, void 0);
|
|
31
31
|
_PondSocket_middleware.set(this, void 0);
|
|
32
|
+
_PondSocket_maxMessageSize.set(this, void 0);
|
|
33
|
+
_PondSocket_heartbeatMs.set(this, void 0);
|
|
34
|
+
_PondSocket_heartbeatTimer.set(this, null);
|
|
32
35
|
__classPrivateFieldSet(this, _PondSocket_middleware, new middleware_1.Middleware(), "f");
|
|
33
36
|
__classPrivateFieldSet(this, _PondSocket_exclusiveServer, exclusiveServer, "f");
|
|
34
37
|
__classPrivateFieldSet(this, _PondSocket_server, server !== null && server !== void 0 ? server : new http_1.Server(), "f");
|
|
35
38
|
__classPrivateFieldSet(this, _PondSocket_backend, distributedBackend !== null && distributedBackend !== void 0 ? distributedBackend : null, "f");
|
|
39
|
+
__classPrivateFieldSet(this, _PondSocket_maxMessageSize, maxMessageSize, "f");
|
|
40
|
+
__classPrivateFieldSet(this, _PondSocket_heartbeatMs, heartbeatInterval, "f");
|
|
36
41
|
__classPrivateFieldSet(this, _PondSocket_socketServer, socketServer !== null && socketServer !== void 0 ? socketServer : new ws_1.WebSocketServer({ noServer: true }), "f");
|
|
37
42
|
__classPrivateFieldGet(this, _PondSocket_instances, "m", _PondSocket_init).call(this);
|
|
38
43
|
}
|
|
@@ -45,14 +50,34 @@ class PondSocket {
|
|
|
45
50
|
/**
|
|
46
51
|
* Close the server
|
|
47
52
|
*/
|
|
48
|
-
close(callback) {
|
|
53
|
+
close(callback, timeout = 5000) {
|
|
54
|
+
if (__classPrivateFieldGet(this, _PondSocket_heartbeatTimer, "f")) {
|
|
55
|
+
clearInterval(__classPrivateFieldGet(this, _PondSocket_heartbeatTimer, "f"));
|
|
56
|
+
__classPrivateFieldSet(this, _PondSocket_heartbeatTimer, null, "f");
|
|
57
|
+
}
|
|
58
|
+
__classPrivateFieldGet(this, _PondSocket_socketServer, "f").clients.forEach((socket) => {
|
|
59
|
+
if (socket.readyState === ws_1.WebSocket.OPEN) {
|
|
60
|
+
socket.close(1001, 'Server shutting down');
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const forceClose = setTimeout(() => {
|
|
64
|
+
__classPrivateFieldGet(this, _PondSocket_socketServer, "f").clients.forEach((socket) => {
|
|
65
|
+
if (socket.readyState !== ws_1.WebSocket.CLOSED) {
|
|
66
|
+
socket.terminate();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
__classPrivateFieldGet(this, _PondSocket_socketServer, "f").close();
|
|
70
|
+
}, timeout);
|
|
71
|
+
__classPrivateFieldGet(this, _PondSocket_socketServer, "f").close(() => {
|
|
72
|
+
clearTimeout(forceClose);
|
|
73
|
+
});
|
|
49
74
|
return __classPrivateFieldGet(this, _PondSocket_server, "f").close(callback);
|
|
50
75
|
}
|
|
51
76
|
/**
|
|
52
77
|
* Create a new endpoint
|
|
53
78
|
*/
|
|
54
79
|
createEndpoint(path, handler) {
|
|
55
|
-
const endpoint = new endpointEngine_1.EndpointEngine(String(path), __classPrivateFieldGet(this, _PondSocket_backend, "f"));
|
|
80
|
+
const endpoint = new endpointEngine_1.EndpointEngine(String(path), __classPrivateFieldGet(this, _PondSocket_backend, "f"), __classPrivateFieldGet(this, _PondSocket_maxMessageSize, "f"));
|
|
56
81
|
__classPrivateFieldGet(this, _PondSocket_middleware, "f").use((req, params, next) => {
|
|
57
82
|
const event = (0, matcher_1.parseAddress)(path, req.address);
|
|
58
83
|
if (!event) {
|
|
@@ -71,8 +96,8 @@ class PondSocket {
|
|
|
71
96
|
}
|
|
72
97
|
}
|
|
73
98
|
exports.PondSocket = PondSocket;
|
|
74
|
-
_PondSocket_server = new WeakMap(), _PondSocket_exclusiveServer = new WeakMap(), _PondSocket_socketServer = new WeakMap(), _PondSocket_backend = new WeakMap(), _PondSocket_middleware = new WeakMap(), _PondSocket_instances = new WeakSet(), _PondSocket_handleUpgrade = function _PondSocket_handleUpgrade(req, socket, head) {
|
|
75
|
-
const clientId =
|
|
99
|
+
_PondSocket_server = new WeakMap(), _PondSocket_exclusiveServer = new WeakMap(), _PondSocket_socketServer = new WeakMap(), _PondSocket_backend = new WeakMap(), _PondSocket_middleware = new WeakMap(), _PondSocket_maxMessageSize = new WeakMap(), _PondSocket_heartbeatMs = new WeakMap(), _PondSocket_heartbeatTimer = new WeakMap(), _PondSocket_instances = new WeakSet(), _PondSocket_handleUpgrade = function _PondSocket_handleUpgrade(req, socket, head) {
|
|
100
|
+
const clientId = (0, pondsocket_common_1.uuid)();
|
|
76
101
|
const request = {
|
|
77
102
|
id: clientId,
|
|
78
103
|
headers: req.headers,
|
|
@@ -110,15 +135,21 @@ _PondSocket_server = new WeakMap(), _PondSocket_exclusiveServer = new WeakMap(),
|
|
|
110
135
|
socket.isAlive = false;
|
|
111
136
|
socket.ping();
|
|
112
137
|
});
|
|
113
|
-
},
|
|
138
|
+
}, __classPrivateFieldGet(this, _PondSocket_heartbeatMs, "f"));
|
|
114
139
|
}, _PondSocket_init = function _PondSocket_init() {
|
|
115
|
-
|
|
140
|
+
__classPrivateFieldSet(this, _PondSocket_heartbeatTimer, __classPrivateFieldGet(this, _PondSocket_instances, "m", _PondSocket_manageHeartbeat).call(this), "f");
|
|
116
141
|
__classPrivateFieldGet(this, _PondSocket_server, "f").on('error', (error) => {
|
|
117
|
-
|
|
142
|
+
if (__classPrivateFieldGet(this, _PondSocket_heartbeatTimer, "f")) {
|
|
143
|
+
clearInterval(__classPrivateFieldGet(this, _PondSocket_heartbeatTimer, "f"));
|
|
144
|
+
__classPrivateFieldSet(this, _PondSocket_heartbeatTimer, null, "f");
|
|
145
|
+
}
|
|
118
146
|
throw new Error(error.message);
|
|
119
147
|
});
|
|
120
148
|
__classPrivateFieldGet(this, _PondSocket_server, "f").on('close', () => {
|
|
121
|
-
|
|
149
|
+
if (__classPrivateFieldGet(this, _PondSocket_heartbeatTimer, "f")) {
|
|
150
|
+
clearInterval(__classPrivateFieldGet(this, _PondSocket_heartbeatTimer, "f"));
|
|
151
|
+
__classPrivateFieldSet(this, _PondSocket_heartbeatTimer, null, "f");
|
|
152
|
+
}
|
|
122
153
|
});
|
|
123
154
|
__classPrivateFieldGet(this, _PondSocket_server, "f").on('upgrade', __classPrivateFieldGet(this, _PondSocket_instances, "m", _PondSocket_handleUpgrade).bind(this));
|
|
124
155
|
}, _PondSocket_getCookies = function _PondSocket_getCookies(headers) {
|
|
@@ -128,8 +159,13 @@ _PondSocket_server = new WeakMap(), _PondSocket_exclusiveServer = new WeakMap(),
|
|
|
128
159
|
}
|
|
129
160
|
return cookieHeader.split(';')
|
|
130
161
|
.reduce((cookies, cookie) => {
|
|
131
|
-
const
|
|
132
|
-
|
|
162
|
+
const trimmed = cookie.trim();
|
|
163
|
+
const eqIndex = trimmed.indexOf('=');
|
|
164
|
+
if (eqIndex === -1) {
|
|
165
|
+
return cookies;
|
|
166
|
+
}
|
|
167
|
+
const name = trimmed.slice(0, eqIndex);
|
|
168
|
+
const value = trimmed.slice(eqIndex + 1);
|
|
133
169
|
cookies[name] = decodeURIComponent(value);
|
|
134
170
|
return cookies;
|
|
135
171
|
}, {});
|