@eleven-am/pondsocket 0.1.176 → 0.1.178
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/redisClient.js +123 -40
- package/errors/httpError.js +33 -0
- package/errors/redisError.js +10 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/types.d.ts +7 -0
- package/wrappers/pondChannel.js +15 -7
package/abstracts/redisClient.js
CHANGED
|
@@ -33,16 +33,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
33
33
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34
34
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
35
35
|
};
|
|
36
|
-
var _RedisClient_instances, _RedisClient_redisClient, _RedisClient_pubClient, _RedisClient_subClient, _RedisClient_instanceId, _RedisClient_assignsPublisher, _RedisClient_presencePublisher, _RedisClient_userLeavesPublisher, _RedisClient_channelMessagePublisher,
|
|
36
|
+
var _RedisClient_instances, _RedisClient_heartbeatInterval, _RedisClient_cleanupInterval, _RedisClient_instanceTtl, _RedisClient_redisClient, _RedisClient_pubClient, _RedisClient_subClient, _RedisClient_instanceId, _RedisClient_assignsPublisher, _RedisClient_presencePublisher, _RedisClient_userLeavesPublisher, _RedisClient_channelMessagePublisher, _RedisClient_heartbeatTimer, _RedisClient_cleanupTimer, _RedisClient_presence_changes_channel_get, _RedisClient_assigns_changes_channel_get, _RedisClient_channel_messages_channel_get, _RedisClient_user_leaves_channel_get, _RedisClient_cleanup, _RedisClient_handleErrors, _RedisClient_getPresenceCacheChannel, _RedisClient_getAssignsCacheChannel, _RedisClient_publishPresenceChange, _RedisClient_publishAssignsChange, _RedisClient_publishChannelMessage, _RedisClient_publishUserLeave, _RedisClient_getPresenceCache, _RedisClient_getAssignsCache, _RedisClient_registerInstance, _RedisClient_unregisterInstance, _RedisClient_unsubscribeFromChannels, _RedisClient_subscribeToChannels, _RedisClient_startHeartbeat, _RedisClient_startPeriodicCleanup, _RedisClient_performConsistencyCheck, _RedisClient_getActiveInstances, _RedisClient_handleRedisMessage, _RedisClient_publishCacheMessage, _RedisClient_readCachedData, _RedisClient_subscribeToCacheChanges, _RedisClient_subscribeToChannelMessages, _RedisClient_subscribeToUserLeaves, _RedisClient_handleExit;
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.RedisClient = void 0;
|
|
39
39
|
const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
|
|
40
40
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
41
|
+
const redisError_1 = require("../errors/redisError");
|
|
41
42
|
class RedisClient {
|
|
42
|
-
constructor(
|
|
43
|
+
constructor(config) {
|
|
44
|
+
var _a, _b, _c;
|
|
43
45
|
_RedisClient_instances.add(this);
|
|
44
|
-
this
|
|
45
|
-
this
|
|
46
|
+
_RedisClient_heartbeatInterval.set(this, void 0);
|
|
47
|
+
_RedisClient_cleanupInterval.set(this, void 0);
|
|
48
|
+
_RedisClient_instanceTtl.set(this, void 0);
|
|
46
49
|
_RedisClient_redisClient.set(this, void 0);
|
|
47
50
|
_RedisClient_pubClient.set(this, void 0);
|
|
48
51
|
_RedisClient_subClient.set(this, void 0);
|
|
@@ -51,10 +54,14 @@ class RedisClient {
|
|
|
51
54
|
_RedisClient_presencePublisher.set(this, void 0);
|
|
52
55
|
_RedisClient_userLeavesPublisher.set(this, void 0);
|
|
53
56
|
_RedisClient_channelMessagePublisher.set(this, void 0);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
__classPrivateFieldSet(this,
|
|
57
|
-
__classPrivateFieldSet(this,
|
|
57
|
+
_RedisClient_heartbeatTimer.set(this, void 0);
|
|
58
|
+
_RedisClient_cleanupTimer.set(this, void 0);
|
|
59
|
+
__classPrivateFieldSet(this, _RedisClient_instanceTtl, (_a = config.instanceTtl) !== null && _a !== void 0 ? _a : 90, "f");
|
|
60
|
+
__classPrivateFieldSet(this, _RedisClient_heartbeatInterval, (_b = config.heartbeatInterval) !== null && _b !== void 0 ? _b : 10 * 1000, "f");
|
|
61
|
+
__classPrivateFieldSet(this, _RedisClient_cleanupInterval, (_c = config.cleanupInterval) !== null && _c !== void 0 ? _c : 60 * 1000, "f");
|
|
62
|
+
__classPrivateFieldSet(this, _RedisClient_redisClient, new ioredis_1.default(config), "f");
|
|
63
|
+
__classPrivateFieldSet(this, _RedisClient_pubClient, new ioredis_1.default(config), "f");
|
|
64
|
+
__classPrivateFieldSet(this, _RedisClient_subClient, new ioredis_1.default(config), "f");
|
|
58
65
|
__classPrivateFieldSet(this, _RedisClient_assignsPublisher, new pondsocket_common_1.Subject(), "f");
|
|
59
66
|
__classPrivateFieldSet(this, _RedisClient_presencePublisher, new pondsocket_common_1.Subject(), "f");
|
|
60
67
|
__classPrivateFieldSet(this, _RedisClient_userLeavesPublisher, new pondsocket_common_1.Subject(), "f");
|
|
@@ -79,8 +86,9 @@ class RedisClient {
|
|
|
79
86
|
initialize() {
|
|
80
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
88
|
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_handleErrors).call(this);
|
|
82
|
-
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_startTTLRefresh).call(this);
|
|
83
89
|
yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_registerInstance).call(this);
|
|
90
|
+
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_startHeartbeat).call(this);
|
|
91
|
+
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_startPeriodicCleanup).call(this);
|
|
84
92
|
yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribeToChannels).call(this);
|
|
85
93
|
process.on('SIGINT', __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_handleExit).bind(this));
|
|
86
94
|
process.on('SIGTERM', __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_handleExit).bind(this));
|
|
@@ -88,7 +96,8 @@ class RedisClient {
|
|
|
88
96
|
}
|
|
89
97
|
shutdown() {
|
|
90
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
clearInterval(__classPrivateFieldGet(this,
|
|
99
|
+
clearInterval(__classPrivateFieldGet(this, _RedisClient_heartbeatTimer, "f"));
|
|
100
|
+
clearInterval(__classPrivateFieldGet(this, _RedisClient_cleanupTimer, "f"));
|
|
92
101
|
yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_unsubscribeFromChannels).call(this);
|
|
93
102
|
yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_unregisterInstance).call(this);
|
|
94
103
|
yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_cleanup).call(this);
|
|
@@ -96,7 +105,7 @@ class RedisClient {
|
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
107
|
exports.RedisClient = RedisClient;
|
|
99
|
-
_RedisClient_redisClient = new WeakMap(), _RedisClient_pubClient = new WeakMap(), _RedisClient_subClient = new WeakMap(), _RedisClient_instanceId = new WeakMap(), _RedisClient_assignsPublisher = new WeakMap(), _RedisClient_presencePublisher = new WeakMap(), _RedisClient_userLeavesPublisher = new WeakMap(), _RedisClient_channelMessagePublisher = new WeakMap(),
|
|
108
|
+
_RedisClient_heartbeatInterval = new WeakMap(), _RedisClient_cleanupInterval = new WeakMap(), _RedisClient_instanceTtl = new WeakMap(), _RedisClient_redisClient = new WeakMap(), _RedisClient_pubClient = new WeakMap(), _RedisClient_subClient = new WeakMap(), _RedisClient_instanceId = new WeakMap(), _RedisClient_assignsPublisher = new WeakMap(), _RedisClient_presencePublisher = new WeakMap(), _RedisClient_userLeavesPublisher = new WeakMap(), _RedisClient_channelMessagePublisher = new WeakMap(), _RedisClient_heartbeatTimer = new WeakMap(), _RedisClient_cleanupTimer = new WeakMap(), _RedisClient_instances = new WeakSet(), _RedisClient_presence_changes_channel_get = function _RedisClient_presence_changes_channel_get() {
|
|
100
109
|
return 'presence_changes';
|
|
101
110
|
}, _RedisClient_assigns_changes_channel_get = function _RedisClient_assigns_changes_channel_get() {
|
|
102
111
|
return 'assigns_changes';
|
|
@@ -118,9 +127,9 @@ _RedisClient_redisClient = new WeakMap(), _RedisClient_pubClient = new WeakMap()
|
|
|
118
127
|
__classPrivateFieldGet(this, _RedisClient_pubClient, "f").on('error', (err) => console.error('Redis pub client error:', err));
|
|
119
128
|
__classPrivateFieldGet(this, _RedisClient_subClient, "f").on('error', (err) => console.error('Redis sub client error:', err));
|
|
120
129
|
}, _RedisClient_getPresenceCacheChannel = function _RedisClient_getPresenceCacheChannel(endpointId, channelId) {
|
|
121
|
-
return `presence_cache:${endpointId}:${channelId}`;
|
|
130
|
+
return `presence_cache:${__classPrivateFieldGet(this, _RedisClient_instanceId, "f")}:${endpointId}:${channelId}`;
|
|
122
131
|
}, _RedisClient_getAssignsCacheChannel = function _RedisClient_getAssignsCacheChannel(endpointId, channelId) {
|
|
123
|
-
return `assigns_cache:${endpointId}:${channelId}`;
|
|
132
|
+
return `assigns_cache:${__classPrivateFieldGet(this, _RedisClient_instanceId, "f")}:${endpointId}:${channelId}`;
|
|
124
133
|
}, _RedisClient_publishPresenceChange = function _RedisClient_publishPresenceChange(endpointId, channelId, userId, state) {
|
|
125
134
|
const message = {
|
|
126
135
|
userId,
|
|
@@ -160,33 +169,31 @@ _RedisClient_redisClient = new WeakMap(), _RedisClient_pubClient = new WeakMap()
|
|
|
160
169
|
yield __classPrivateFieldGet(this, _RedisClient_pubClient, "f").publish(__classPrivateFieldGet(this, _RedisClient_instances, "a", _RedisClient_user_leaves_channel_get), message);
|
|
161
170
|
});
|
|
162
171
|
}, _RedisClient_getPresenceCache = function _RedisClient_getPresenceCache(endpointId, channelId) {
|
|
163
|
-
|
|
164
|
-
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_readCachedData).call(this, cacheKey);
|
|
172
|
+
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_readCachedData).call(this, endpointId, channelId, 'presence_cache:*');
|
|
165
173
|
}, _RedisClient_getAssignsCache = function _RedisClient_getAssignsCache(endpointId, channelId) {
|
|
166
|
-
|
|
167
|
-
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_readCachedData).call(this, cacheKey);
|
|
168
|
-
}, _RedisClient_sendHeartbeat = function _RedisClient_sendHeartbeat() {
|
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").expire(`instance:${__classPrivateFieldGet(this, _RedisClient_instanceId, "f")}`, this.INSTANCE_TTL);
|
|
171
|
-
});
|
|
172
|
-
}, _RedisClient_startTTLRefresh = function _RedisClient_startTTLRefresh() {
|
|
173
|
-
__classPrivateFieldSet(this, _RedisClient_ttlRefreshInterval, setInterval(() => __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_sendHeartbeat).call(this), this.TTL_REFRESH_INTERVAL), "f");
|
|
174
|
+
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_readCachedData).call(this, endpointId, channelId, 'assigns_cache:*');
|
|
174
175
|
}, _RedisClient_registerInstance = function _RedisClient_registerInstance() {
|
|
175
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
177
|
const multi = __classPrivateFieldGet(this, _RedisClient_redisClient, "f").multi();
|
|
177
|
-
multi.sadd('distributed_instances
|
|
178
|
-
multi.
|
|
179
|
-
|
|
178
|
+
multi.sadd('distributed_instances', __classPrivateFieldGet(this, _RedisClient_instanceId, "f"));
|
|
179
|
+
multi.set(`heartbeat:${__classPrivateFieldGet(this, _RedisClient_instanceId, "f")}`, Date.now().toString(), 'EX', __classPrivateFieldGet(this, _RedisClient_instanceTtl, "f"));
|
|
180
|
+
try {
|
|
181
|
+
yield multi.exec();
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
throw new redisError_1.RedisError('Error registering instance');
|
|
185
|
+
}
|
|
180
186
|
});
|
|
181
187
|
}, _RedisClient_unregisterInstance = function _RedisClient_unregisterInstance() {
|
|
182
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
189
|
const multi = __classPrivateFieldGet(this, _RedisClient_redisClient, "f").multi();
|
|
184
190
|
multi.srem('distributed_instances', __classPrivateFieldGet(this, _RedisClient_instanceId, "f"));
|
|
185
|
-
multi.del(`
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
multi.del(`heartbeat:${__classPrivateFieldGet(this, _RedisClient_instanceId, "f")}`);
|
|
192
|
+
try {
|
|
193
|
+
yield multi.exec();
|
|
194
|
+
}
|
|
195
|
+
catch (_a) {
|
|
196
|
+
// no-op as we're shutting down
|
|
190
197
|
}
|
|
191
198
|
});
|
|
192
199
|
}, _RedisClient_unsubscribeFromChannels = function _RedisClient_unsubscribeFromChannels() {
|
|
@@ -205,6 +212,51 @@ _RedisClient_redisClient = new WeakMap(), _RedisClient_pubClient = new WeakMap()
|
|
|
205
212
|
});
|
|
206
213
|
__classPrivateFieldGet(this, _RedisClient_subClient, "f").on('message', __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_handleRedisMessage).bind(this));
|
|
207
214
|
});
|
|
215
|
+
}, _RedisClient_startHeartbeat = function _RedisClient_startHeartbeat() {
|
|
216
|
+
__classPrivateFieldSet(this, _RedisClient_heartbeatTimer, setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
try {
|
|
218
|
+
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").set(`heartbeat:${__classPrivateFieldGet(this, _RedisClient_instanceId, "f")}`, Date.now().toString(), 'EX', __classPrivateFieldGet(this, _RedisClient_instanceTtl, "f"));
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
throw new redisError_1.RedisError('Error setting heartbeat');
|
|
222
|
+
}
|
|
223
|
+
}), __classPrivateFieldGet(this, _RedisClient_heartbeatInterval, "f")), "f");
|
|
224
|
+
}, _RedisClient_startPeriodicCleanup = function _RedisClient_startPeriodicCleanup() {
|
|
225
|
+
__classPrivateFieldSet(this, _RedisClient_cleanupTimer, setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
try {
|
|
227
|
+
yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_performConsistencyCheck).call(this);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
throw new redisError_1.RedisError('Error performing consistency check');
|
|
231
|
+
}
|
|
232
|
+
}), __classPrivateFieldGet(this, _RedisClient_cleanupInterval, "f")), "f");
|
|
233
|
+
}, _RedisClient_performConsistencyCheck = function _RedisClient_performConsistencyCheck() {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
const activeInstances = yield __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_getActiveInstances).call(this);
|
|
236
|
+
const allKeys = yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").keys('*_cache:*');
|
|
237
|
+
for (const key of allKeys) {
|
|
238
|
+
const [_, instanceId] = key.split(':');
|
|
239
|
+
if (!activeInstances.has(instanceId)) {
|
|
240
|
+
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").del(key);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}, _RedisClient_getActiveInstances = function _RedisClient_getActiveInstances() {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
const instances = yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").smembers('distributed_instances');
|
|
247
|
+
const activeInstances = new Set();
|
|
248
|
+
for (const instanceId of instances) {
|
|
249
|
+
const lastHeartbeat = yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").get(`heartbeat:${instanceId}`);
|
|
250
|
+
if (lastHeartbeat && Date.now() - parseInt(lastHeartbeat, 10) < __classPrivateFieldGet(this, _RedisClient_instanceTtl, "f") * 1000) {
|
|
251
|
+
activeInstances.add(instanceId);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").srem('distributed_instances', instanceId);
|
|
255
|
+
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").del(`heartbeat:${instanceId}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return activeInstances;
|
|
259
|
+
});
|
|
208
260
|
}, _RedisClient_handleRedisMessage = function _RedisClient_handleRedisMessage(channel, message) {
|
|
209
261
|
const data = JSON.parse(message);
|
|
210
262
|
switch (channel) {
|
|
@@ -234,16 +286,47 @@ _RedisClient_redisClient = new WeakMap(), _RedisClient_pubClient = new WeakMap()
|
|
|
234
286
|
}
|
|
235
287
|
yield __classPrivateFieldGet(this, _RedisClient_pubClient, "f").publish(key, messageData);
|
|
236
288
|
});
|
|
237
|
-
}, _RedisClient_readCachedData = function _RedisClient_readCachedData(cacheKey) {
|
|
289
|
+
}, _RedisClient_readCachedData = function _RedisClient_readCachedData(endpointId, channelId, cacheKey) {
|
|
238
290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
291
|
+
const response = new Map();
|
|
292
|
+
const activeInstances = new Set(yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").smembers('distributed_instances'));
|
|
293
|
+
let cursor = '0';
|
|
294
|
+
do {
|
|
295
|
+
const [nextCursor, keys] = yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").scan(cursor, 'MATCH', cacheKey, 'COUNT', '100');
|
|
296
|
+
cursor = nextCursor;
|
|
297
|
+
const pipeline = __classPrivateFieldGet(this, _RedisClient_redisClient, "f").pipeline();
|
|
298
|
+
keys.forEach((key) => {
|
|
299
|
+
const [_, instanceId, keyEndpointId, keyChannelId] = key.split(':');
|
|
300
|
+
if (keyEndpointId === endpointId && keyChannelId === channelId) {
|
|
301
|
+
if (activeInstances.has(instanceId)) {
|
|
302
|
+
pipeline.hgetall(key);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
pipeline.del(key);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
const results = yield pipeline.exec();
|
|
310
|
+
if (results) {
|
|
311
|
+
results.forEach(([error, data]) => {
|
|
312
|
+
if (!error && data && typeof data === 'object') {
|
|
313
|
+
Object.entries(data)
|
|
314
|
+
.forEach(([userId, value]) => {
|
|
315
|
+
try {
|
|
316
|
+
const parsedData = JSON.parse(value);
|
|
317
|
+
if (typeof parsedData === 'object' && parsedData !== null) {
|
|
318
|
+
response.set(userId, parsedData);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (e) {
|
|
322
|
+
throw new redisError_1.RedisError('Error parsing cached data');
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
} while (cursor !== '0');
|
|
329
|
+
return response;
|
|
247
330
|
});
|
|
248
331
|
}, _RedisClient_subscribeToCacheChanges = function _RedisClient_subscribeToCacheChanges(endpoint, channel, presence, callback) {
|
|
249
332
|
const subject = presence ? __classPrivateFieldGet(this, _RedisClient_presencePublisher, "f") : __classPrivateFieldGet(this, _RedisClient_assignsPublisher, "f");
|
package/errors/httpError.js
CHANGED
|
@@ -6,6 +6,39 @@ class HttpError extends Error {
|
|
|
6
6
|
super(message);
|
|
7
7
|
this.statusCode = statusCode;
|
|
8
8
|
this.name = 'HttpError';
|
|
9
|
+
this.statusText = HttpError.getStatusText(statusCode);
|
|
10
|
+
}
|
|
11
|
+
static getStatusText(statusCode) {
|
|
12
|
+
switch (statusCode) {
|
|
13
|
+
case 400:
|
|
14
|
+
return 'Bad Request';
|
|
15
|
+
case 401:
|
|
16
|
+
return 'Unauthorized';
|
|
17
|
+
case 403:
|
|
18
|
+
return 'Forbidden';
|
|
19
|
+
case 404:
|
|
20
|
+
return 'Not Found';
|
|
21
|
+
case 405:
|
|
22
|
+
return 'Method Not Allowed';
|
|
23
|
+
case 406:
|
|
24
|
+
return 'Not Acceptable';
|
|
25
|
+
case 409:
|
|
26
|
+
return 'Conflict';
|
|
27
|
+
case 429:
|
|
28
|
+
return 'Too Many Requests';
|
|
29
|
+
case 500:
|
|
30
|
+
return 'Internal Server Error';
|
|
31
|
+
case 501:
|
|
32
|
+
return 'Not Implemented';
|
|
33
|
+
case 502:
|
|
34
|
+
return 'Bad Gateway';
|
|
35
|
+
case 503:
|
|
36
|
+
return 'Service Unavailable';
|
|
37
|
+
case 504:
|
|
38
|
+
return 'Gateway Timeout';
|
|
39
|
+
default:
|
|
40
|
+
return 'Unknown Error';
|
|
41
|
+
}
|
|
9
42
|
}
|
|
10
43
|
}
|
|
11
44
|
exports.HttpError = HttpError;
|
package/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisError = void 0;
|
|
3
4
|
const server_1 = require("./server/server");
|
|
5
|
+
var redisError_1 = require("./errors/redisError");
|
|
6
|
+
Object.defineProperty(exports, "RedisError", { enumerable: true, get: function () { return redisError_1.RedisError; } });
|
|
4
7
|
exports.default = server_1.PondSocket;
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export interface RedisOptions {
|
|
|
23
23
|
db?: number;
|
|
24
24
|
username?: string;
|
|
25
25
|
password?: string;
|
|
26
|
+
instanceTtl?: number;
|
|
27
|
+
heartbeatInterval?: number;
|
|
28
|
+
cleanupInterval?: number;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export interface LeaveEvent<EventTypes extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|
|
@@ -472,3 +475,7 @@ export declare class EventResponse<EventType extends PondEventMap = PondEventMap
|
|
|
472
475
|
*/
|
|
473
476
|
evictUser(reason: string, userId?: string): EventResponse;
|
|
474
477
|
}
|
|
478
|
+
|
|
479
|
+
export declare class RedisError extends Error {
|
|
480
|
+
constructor(message: string);
|
|
481
|
+
}
|
package/wrappers/pondChannel.js
CHANGED
|
@@ -10,12 +10,13 @@ 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 _PondChannel_lobby;
|
|
13
|
+
var _PondChannel_instances, _PondChannel_lobby, _PondChannel_getChannel;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PondChannel = void 0;
|
|
16
16
|
const channel_1 = require("./channel");
|
|
17
17
|
class PondChannel {
|
|
18
18
|
constructor(lobby) {
|
|
19
|
+
_PondChannel_instances.add(this);
|
|
19
20
|
_PondChannel_lobby.set(this, void 0);
|
|
20
21
|
__classPrivateFieldSet(this, _PondChannel_lobby, lobby, "f");
|
|
21
22
|
}
|
|
@@ -28,21 +29,28 @@ class PondChannel {
|
|
|
28
29
|
return this;
|
|
29
30
|
}
|
|
30
31
|
getChannel(channelName) {
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
try {
|
|
33
|
+
return __classPrivateFieldGet(this, _PondChannel_instances, "m", _PondChannel_getChannel).call(this, channelName);
|
|
34
|
+
}
|
|
35
|
+
catch (_a) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
39
|
broadcast(channelName, event, payload) {
|
|
35
|
-
this.
|
|
40
|
+
__classPrivateFieldGet(this, _PondChannel_instances, "m", _PondChannel_getChannel).call(this, channelName).broadcast(event, payload);
|
|
36
41
|
return this;
|
|
37
42
|
}
|
|
38
43
|
broadcastFrom(channelName, userId, event, payload) {
|
|
39
|
-
this.
|
|
44
|
+
__classPrivateFieldGet(this, _PondChannel_instances, "m", _PondChannel_getChannel).call(this, channelName).broadcastFrom(userId, event, payload);
|
|
40
45
|
return this;
|
|
41
46
|
}
|
|
42
47
|
broadcastTo(channelName, userIds, event, payload) {
|
|
43
|
-
this.
|
|
48
|
+
__classPrivateFieldGet(this, _PondChannel_instances, "m", _PondChannel_getChannel).call(this, channelName).broadcastTo(userIds, event, payload);
|
|
44
49
|
return this;
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
exports.PondChannel = PondChannel;
|
|
48
|
-
_PondChannel_lobby = new WeakMap()
|
|
53
|
+
_PondChannel_lobby = new WeakMap(), _PondChannel_instances = new WeakSet(), _PondChannel_getChannel = function _PondChannel_getChannel(channelName) {
|
|
54
|
+
const channel = __classPrivateFieldGet(this, _PondChannel_lobby, "f").getChannel(channelName);
|
|
55
|
+
return new channel_1.Channel(channel);
|
|
56
|
+
};
|