@eleven-am/pondsocket 0.1.178 → 0.1.180
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 +105 -79
- package/engines/endpointEngine.js +3 -12
- package/engines/lobbyEngine.js +5 -16
- package/managers/distributedManager.js +34 -45
- package/managers/manager.js +0 -1
- package/managers/managerFactory.js +10 -21
- package/package.json +2 -2
package/abstracts/redisClient.js
CHANGED
|
@@ -33,7 +33,7 @@ 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_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,
|
|
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_stateSyncPublisher, _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_registerInstance, _RedisClient_unregisterInstance, _RedisClient_unsubscribeFromChannels, _RedisClient_subscribeToChannels, _RedisClient_startHeartbeat, _RedisClient_startPeriodicCleanup, _RedisClient_performConsistencyCheck, _RedisClient_handleRedisMessage, _RedisClient_publishCacheMessage, _RedisClient_emitStateSyncEvent, _RedisClient_subscribeToCacheChanges, _RedisClient_subscribeToChannelMessages, _RedisClient_subscribeToUserLeaves, _RedisClient_subscribeToStateSync, _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");
|
|
@@ -54,6 +54,7 @@ class RedisClient {
|
|
|
54
54
|
_RedisClient_presencePublisher.set(this, void 0);
|
|
55
55
|
_RedisClient_userLeavesPublisher.set(this, void 0);
|
|
56
56
|
_RedisClient_channelMessagePublisher.set(this, void 0);
|
|
57
|
+
_RedisClient_stateSyncPublisher.set(this, void 0);
|
|
57
58
|
_RedisClient_heartbeatTimer.set(this, void 0);
|
|
58
59
|
_RedisClient_cleanupTimer.set(this, void 0);
|
|
59
60
|
__classPrivateFieldSet(this, _RedisClient_instanceTtl, (_a = config.instanceTtl) !== null && _a !== void 0 ? _a : 90, "f");
|
|
@@ -66,13 +67,12 @@ class RedisClient {
|
|
|
66
67
|
__classPrivateFieldSet(this, _RedisClient_presencePublisher, new pondsocket_common_1.Subject(), "f");
|
|
67
68
|
__classPrivateFieldSet(this, _RedisClient_userLeavesPublisher, new pondsocket_common_1.Subject(), "f");
|
|
68
69
|
__classPrivateFieldSet(this, _RedisClient_channelMessagePublisher, new pondsocket_common_1.Subject(), "f");
|
|
70
|
+
__classPrivateFieldSet(this, _RedisClient_stateSyncPublisher, new pondsocket_common_1.Subject(), "f");
|
|
69
71
|
__classPrivateFieldSet(this, _RedisClient_instanceId, (0, pondsocket_common_1.uuid)(), "f");
|
|
70
72
|
}
|
|
71
73
|
buildClient(endpointId) {
|
|
72
74
|
return (channelId) => ({
|
|
73
75
|
channelId,
|
|
74
|
-
getPresenceCache: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_getPresenceCache).bind(this, endpointId, channelId),
|
|
75
|
-
getAssignsCache: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_getAssignsCache).bind(this, endpointId, channelId),
|
|
76
76
|
publishPresenceChange: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_publishPresenceChange).bind(this, endpointId, channelId),
|
|
77
77
|
publishAssignsChange: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_publishAssignsChange).bind(this, endpointId, channelId),
|
|
78
78
|
publishChannelMessage: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_publishChannelMessage).bind(this, endpointId, channelId),
|
|
@@ -81,6 +81,7 @@ class RedisClient {
|
|
|
81
81
|
subscribeToPresenceChanges: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribeToCacheChanges).bind(this, endpointId, channelId, true),
|
|
82
82
|
subscribeToAssignsChanges: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribeToCacheChanges).bind(this, endpointId, channelId, false),
|
|
83
83
|
subscribeToChannelMessages: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribeToChannelMessages).bind(this, endpointId, channelId),
|
|
84
|
+
subscribeToStateSync: __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_subscribeToStateSync).bind(this, endpointId, channelId),
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
initialize() {
|
|
@@ -105,7 +106,7 @@ class RedisClient {
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
exports.RedisClient = RedisClient;
|
|
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() {
|
|
109
|
+
_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_stateSyncPublisher = 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() {
|
|
109
110
|
return 'presence_changes';
|
|
110
111
|
}, _RedisClient_assigns_changes_channel_get = function _RedisClient_assigns_changes_channel_get() {
|
|
111
112
|
return 'assigns_changes';
|
|
@@ -168,10 +169,6 @@ _RedisClient_heartbeatInterval = new WeakMap(), _RedisClient_cleanupInterval = n
|
|
|
168
169
|
});
|
|
169
170
|
yield __classPrivateFieldGet(this, _RedisClient_pubClient, "f").publish(__classPrivateFieldGet(this, _RedisClient_instances, "a", _RedisClient_user_leaves_channel_get), message);
|
|
170
171
|
});
|
|
171
|
-
}, _RedisClient_getPresenceCache = function _RedisClient_getPresenceCache(endpointId, channelId) {
|
|
172
|
-
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_readCachedData).call(this, endpointId, channelId, 'presence_cache:*');
|
|
173
|
-
}, _RedisClient_getAssignsCache = function _RedisClient_getAssignsCache(endpointId, channelId) {
|
|
174
|
-
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_readCachedData).call(this, endpointId, channelId, 'assigns_cache:*');
|
|
175
172
|
}, _RedisClient_registerInstance = function _RedisClient_registerInstance() {
|
|
176
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
174
|
const multi = __classPrivateFieldGet(this, _RedisClient_redisClient, "f").multi();
|
|
@@ -232,30 +229,44 @@ _RedisClient_heartbeatInterval = new WeakMap(), _RedisClient_cleanupInterval = n
|
|
|
232
229
|
}), __classPrivateFieldGet(this, _RedisClient_cleanupInterval, "f")), "f");
|
|
233
230
|
}, _RedisClient_performConsistencyCheck = function _RedisClient_performConsistencyCheck() {
|
|
234
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
232
|
+
const consistencyCheckScript = `
|
|
233
|
+
local active_instances = redis.call('SMEMBERS', 'distributed_instances')
|
|
234
|
+
local all_keys = redis.call('KEYS', '*_cache:*')
|
|
235
|
+
local inactive_keys = {}
|
|
236
|
+
local unique_pairs = {}
|
|
237
|
+
|
|
238
|
+
for _, key in ipairs(all_keys) do
|
|
239
|
+
local parts = {}
|
|
240
|
+
for part in string.gmatch(key, '[^:]+') do
|
|
241
|
+
table.insert(parts, part)
|
|
242
|
+
end
|
|
243
|
+
local instance_id, endpoint_id, channel_id = parts[2], parts[3], parts[4]
|
|
244
|
+
|
|
245
|
+
if not (active_instances[instance_id]) then
|
|
246
|
+
table.insert(inactive_keys, key)
|
|
247
|
+
local pair = endpoint_id .. ':' .. channel_id
|
|
248
|
+
unique_pairs[pair] = true
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
if #inactive_keys > 0 then
|
|
253
|
+
redis.call('DEL', unpack(inactive_keys))
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
local unique_pairs_list = {}
|
|
257
|
+
for pair in pairs(unique_pairs) do
|
|
258
|
+
table.insert(unique_pairs_list, pair)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
return unique_pairs_list
|
|
262
|
+
`;
|
|
263
|
+
const [response] = yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").eval(consistencyCheckScript, 0);
|
|
264
|
+
const uniquePairs = Array.isArray(response) ? response : [response];
|
|
265
|
+
const promises = uniquePairs.map((pair) => {
|
|
266
|
+
const [endpointId, channelId] = pair.split(':');
|
|
267
|
+
return __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_emitStateSyncEvent).call(this, endpointId, channelId);
|
|
268
|
+
});
|
|
269
|
+
yield Promise.all(promises);
|
|
259
270
|
});
|
|
260
271
|
}, _RedisClient_handleRedisMessage = function _RedisClient_handleRedisMessage(channel, message) {
|
|
261
272
|
const data = JSON.parse(message);
|
|
@@ -277,56 +288,58 @@ _RedisClient_heartbeatInterval = new WeakMap(), _RedisClient_cleanupInterval = n
|
|
|
277
288
|
}
|
|
278
289
|
}, _RedisClient_publishCacheMessage = function _RedisClient_publishCacheMessage(key, cacheKey, message) {
|
|
279
290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const script = `
|
|
292
|
+
local messageData = ARGV[1]
|
|
293
|
+
local userId = ARGV[2]
|
|
294
|
+
local state = ARGV[3]
|
|
295
|
+
|
|
296
|
+
if state ~= '' then
|
|
297
|
+
redis.call('HSET', KEYS[1], userId, state)
|
|
298
|
+
else
|
|
299
|
+
redis.call('HDEL', KEYS[1], userId)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
redis.call('PUBLISH', KEYS[2], messageData)
|
|
303
|
+
|
|
304
|
+
return 1
|
|
305
|
+
`;
|
|
280
306
|
const messageData = JSON.stringify(message);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").hdel(cacheKey, message.userId);
|
|
286
|
-
}
|
|
287
|
-
yield __classPrivateFieldGet(this, _RedisClient_pubClient, "f").publish(key, messageData);
|
|
307
|
+
const state = message.state ? JSON.stringify(message.state) : '';
|
|
308
|
+
yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").eval(script, 2, cacheKey, key, messageData, message.userId, state);
|
|
288
309
|
});
|
|
289
|
-
},
|
|
310
|
+
}, _RedisClient_emitStateSyncEvent = function _RedisClient_emitStateSyncEvent(endpointId, channelId) {
|
|
290
311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
throw new redisError_1.RedisError('Error parsing cached data');
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
} while (cursor !== '0');
|
|
329
|
-
return response;
|
|
312
|
+
const script = `
|
|
313
|
+
local active_instances = redis.call('SMEMBERS', 'distributed_instances')
|
|
314
|
+
local presence_data = {}
|
|
315
|
+
local assigns_data = {}
|
|
316
|
+
|
|
317
|
+
for _, instance in ipairs(active_instances) do
|
|
318
|
+
local presence_key = 'presence_cache:' .. instance .. ':' .. ARGV[1] .. ':' .. ARGV[2]
|
|
319
|
+
local assigns_key = 'assigns_cache:' .. instance .. ':' .. ARGV[1] .. ':' .. ARGV[2]
|
|
320
|
+
|
|
321
|
+
local presence = redis.call('HGETALL', presence_key)
|
|
322
|
+
local assigns = redis.call('HGETALL', assigns_key)
|
|
323
|
+
|
|
324
|
+
for i = 1, #presence, 2 do
|
|
325
|
+
presence_data[presence[i]] = presence[i+1]
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
for i = 1, #assigns, 2 do
|
|
329
|
+
assigns_data[assigns[i]] = assigns[i+1]
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
return {cjson.encode(presence_data), cjson.encode(assigns_data)}
|
|
334
|
+
`;
|
|
335
|
+
const [presenceData, assignsData] = yield __classPrivateFieldGet(this, _RedisClient_redisClient, "f").eval(script, 0, endpointId, channelId);
|
|
336
|
+
const event = {
|
|
337
|
+
endpointId,
|
|
338
|
+
channelId,
|
|
339
|
+
presence: new Map(Object.entries(JSON.parse(presenceData))),
|
|
340
|
+
assigns: new Map(Object.entries(JSON.parse(assignsData))),
|
|
341
|
+
};
|
|
342
|
+
__classPrivateFieldGet(this, _RedisClient_stateSyncPublisher, "f").publish(event);
|
|
330
343
|
});
|
|
331
344
|
}, _RedisClient_subscribeToCacheChanges = function _RedisClient_subscribeToCacheChanges(endpoint, channel, presence, callback) {
|
|
332
345
|
const subject = presence ? __classPrivateFieldGet(this, _RedisClient_presencePublisher, "f") : __classPrivateFieldGet(this, _RedisClient_assignsPublisher, "f");
|
|
@@ -348,6 +361,19 @@ _RedisClient_heartbeatInterval = new WeakMap(), _RedisClient_cleanupInterval = n
|
|
|
348
361
|
return callback(userId);
|
|
349
362
|
}
|
|
350
363
|
});
|
|
364
|
+
}, _RedisClient_subscribeToStateSync = function _RedisClient_subscribeToStateSync(endpoint, channel, callback) {
|
|
365
|
+
const interval = setInterval(() => __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_emitStateSyncEvent).call(this, endpoint, channel), __classPrivateFieldGet(this, _RedisClient_heartbeatInterval, "f") * 10);
|
|
366
|
+
const subscription = __classPrivateFieldGet(this, _RedisClient_stateSyncPublisher, "f").subscribe((_a) => {
|
|
367
|
+
var { endpointId, channelId } = _a, data = __rest(_a, ["endpointId", "channelId"]);
|
|
368
|
+
if (endpointId === endpoint && channelId === channel) {
|
|
369
|
+
return callback(data);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
void __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_emitStateSyncEvent).call(this, endpoint, channel);
|
|
373
|
+
return () => {
|
|
374
|
+
clearInterval(interval);
|
|
375
|
+
subscription();
|
|
376
|
+
};
|
|
351
377
|
}, _RedisClient_handleExit = function _RedisClient_handleExit() {
|
|
352
378
|
return __awaiter(this, void 0, void 0, function* () {
|
|
353
379
|
try {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -45,7 +36,7 @@ class EndpointEngine {
|
|
|
45
36
|
}
|
|
46
37
|
createChannel(path, handler) {
|
|
47
38
|
const pondChannel = new lobbyEngine_1.LobbyEngine(this);
|
|
48
|
-
__classPrivateFieldGet(this, _EndpointEngine_middleware, "f").use((user, joinParams, next) =>
|
|
39
|
+
__classPrivateFieldGet(this, _EndpointEngine_middleware, "f").use((user, joinParams, next) => {
|
|
49
40
|
const event = (0, matcher_1.parseAddress)(path, user.channelName);
|
|
50
41
|
if (event) {
|
|
51
42
|
const options = {
|
|
@@ -54,13 +45,13 @@ class EndpointEngine {
|
|
|
54
45
|
params: event,
|
|
55
46
|
joinParams,
|
|
56
47
|
};
|
|
57
|
-
const channel =
|
|
48
|
+
const channel = pondChannel.getOrCreateChannel(user.channelName);
|
|
58
49
|
const request = new joinRequest_1.JoinRequest(options, channel);
|
|
59
50
|
const response = new joinResponse_1.JoinResponse(user, channel);
|
|
60
51
|
return handler(request, response, next);
|
|
61
52
|
}
|
|
62
53
|
next();
|
|
63
|
-
})
|
|
54
|
+
});
|
|
64
55
|
__classPrivateFieldGet(this, _EndpointEngine_lobbyEngines, "f").set(path, pondChannel);
|
|
65
56
|
return new pondChannel_1.PondChannel(pondChannel);
|
|
66
57
|
}
|
package/engines/lobbyEngine.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -69,11 +60,9 @@ exports.LobbyEngine = LobbyEngine;
|
|
|
69
60
|
_LobbyEngine_channels = new WeakMap(), _LobbyEngine_instances = new WeakSet(), _LobbyEngine_getChannel = function _LobbyEngine_getChannel(channelName) {
|
|
70
61
|
return __classPrivateFieldGet(this, _LobbyEngine_channels, "f").get(channelName) || null;
|
|
71
62
|
}, _LobbyEngine_createChannel = function _LobbyEngine_createChannel(channelName) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return channel;
|
|
78
|
-
});
|
|
63
|
+
const onManagerClose = __classPrivateFieldGet(this, _LobbyEngine_channels, "f").delete.bind(__classPrivateFieldGet(this, _LobbyEngine_channels, "f"), channelName);
|
|
64
|
+
const manager = this.parent.createManager(channelName, onManagerClose);
|
|
65
|
+
const channel = new channelEngine_1.ChannelEngine(this, channelName, manager);
|
|
66
|
+
__classPrivateFieldGet(this, _LobbyEngine_channels, "f").set(channelName, channel);
|
|
67
|
+
return channel;
|
|
79
68
|
};
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -66,44 +57,42 @@ class DistributedManager extends manager_1.Manager {
|
|
|
66
57
|
__classPrivateFieldGet(this, _DistributedManager_client, "f").publishChannelMessage(message);
|
|
67
58
|
}
|
|
68
59
|
initialize(unsubscribe) {
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
super.initialize(unsubscribe);
|
|
61
|
+
const leaveSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToUserLeaves((userId) => {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = this.userSubscriptions.get(userId)) === null || _a === void 0 ? void 0 : _a();
|
|
64
|
+
this.userSubscriptions.delete(userId);
|
|
65
|
+
});
|
|
66
|
+
const presenceSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToPresenceChanges(({ userId, state }) => {
|
|
67
|
+
if (state) {
|
|
68
|
+
this.presenceCache.set(userId, state);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.presenceCache.delete(userId);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const assignSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToAssignsChanges(({ userId, state }) => {
|
|
75
|
+
if (state) {
|
|
76
|
+
this.assignsCache.set(userId, state);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.assignsCache.delete(userId);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const messageSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToChannelMessages((message) => {
|
|
83
|
+
this.publisher.publish(message);
|
|
71
84
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.presenceCache =
|
|
75
|
-
this.assignsCache = yield __classPrivateFieldGet(this, _DistributedManager_client, "f").getAssignsCache();
|
|
76
|
-
const leaveSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToUserLeaves((userId) => {
|
|
77
|
-
var _a;
|
|
78
|
-
(_a = this.userSubscriptions.get(userId)) === null || _a === void 0 ? void 0 : _a();
|
|
79
|
-
this.userSubscriptions.delete(userId);
|
|
80
|
-
});
|
|
81
|
-
const presenceSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToPresenceChanges(({ userId, state }) => {
|
|
82
|
-
if (state) {
|
|
83
|
-
this.presenceCache.set(userId, state);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.presenceCache.delete(userId);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
const assignSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToAssignsChanges(({ userId, state }) => {
|
|
90
|
-
if (state) {
|
|
91
|
-
this.assignsCache.set(userId, state);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.assignsCache.delete(userId);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
const messageSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToChannelMessages((message) => {
|
|
98
|
-
this.publisher.publish(message);
|
|
99
|
-
});
|
|
100
|
-
__classPrivateFieldSet(this, _DistributedManager_subscriptions, () => {
|
|
101
|
-
leaveSubscription();
|
|
102
|
-
presenceSubscription();
|
|
103
|
-
assignSubscription();
|
|
104
|
-
messageSubscription();
|
|
105
|
-
}, "f");
|
|
85
|
+
const stateSyncSubscription = __classPrivateFieldGet(this, _DistributedManager_client, "f").subscribeToStateSync((state) => {
|
|
86
|
+
this.assignsCache = new Map(state.assigns);
|
|
87
|
+
this.presenceCache = new Map(state.presence);
|
|
106
88
|
});
|
|
89
|
+
__classPrivateFieldSet(this, _DistributedManager_subscriptions, () => {
|
|
90
|
+
leaveSubscription();
|
|
91
|
+
presenceSubscription();
|
|
92
|
+
assignSubscription();
|
|
93
|
+
messageSubscription();
|
|
94
|
+
stateSyncSubscription();
|
|
95
|
+
}, "f");
|
|
107
96
|
}
|
|
108
97
|
close() {
|
|
109
98
|
var _a;
|
package/managers/manager.js
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ManagerFactory = void 0;
|
|
13
4
|
const distributedManager_1 = require("./distributedManager");
|
|
14
5
|
const localManager_1 = require("./localManager");
|
|
15
6
|
class ManagerFactory {
|
|
16
7
|
static create(channelId, clientFactory, onClose) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return manager;
|
|
28
|
-
});
|
|
8
|
+
let manager;
|
|
9
|
+
if (clientFactory) {
|
|
10
|
+
const client = clientFactory(channelId);
|
|
11
|
+
manager = new distributedManager_1.DistributedManager(client);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
manager = new localManager_1.LocalManager(channelId);
|
|
15
|
+
}
|
|
16
|
+
manager.initialize(onClose);
|
|
17
|
+
return manager;
|
|
29
18
|
}
|
|
30
19
|
}
|
|
31
20
|
exports.ManagerFactory = ManagerFactory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.180",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"eslint-config-prettier": "^9.1.0",
|
|
50
50
|
"eslint-import-resolver-node": "^0.3.9",
|
|
51
51
|
"eslint-plugin-file-progress": "^1.5.0",
|
|
52
|
-
"eslint-plugin-import": "^2.
|
|
52
|
+
"eslint-plugin-import": "^2.31.0",
|
|
53
53
|
"eslint-plugin-prettier": "^5.2.1",
|
|
54
54
|
"jest": "^29.7.0",
|
|
55
55
|
"nodemon": "^3.1.7",
|