@eleven-am/pondsocket 0.1.151 → 0.1.153
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/channel/channel.js +10 -1
- package/package.json +4 -4
- package/presence/presence.js +3 -2
- package/presence/presenceEngine.test.js +3 -0
- package/types.d.ts +7 -0
package/channel/channel.js
CHANGED
|
@@ -254,7 +254,7 @@ _ChannelEngine_receiver = new WeakMap(), _ChannelEngine_presenceEngine = new Wea
|
|
|
254
254
|
}
|
|
255
255
|
unsubscribe();
|
|
256
256
|
__classPrivateFieldGet(this, _ChannelEngine_users, "f").delete(userId);
|
|
257
|
-
const userPresence = (_a = __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f")) === null || _a === void 0 ? void 0 : _a.removePresence(userId);
|
|
257
|
+
const userPresence = (_a = __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f")) === null || _a === void 0 ? void 0 : _a.removePresence(userId, true);
|
|
258
258
|
if (__classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").leaveCallback) {
|
|
259
259
|
__classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").leaveCallback({
|
|
260
260
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -323,6 +323,15 @@ class Channel {
|
|
|
323
323
|
unsubscribeFrom(userId, channel) {
|
|
324
324
|
__classPrivateFieldGet(this, _Channel_engine, "f").unsubscribeFrom(userId, channel);
|
|
325
325
|
}
|
|
326
|
+
upsertPresence(userId, presence) {
|
|
327
|
+
const oldPresence = __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.getPresence()[userId];
|
|
328
|
+
if (oldPresence) {
|
|
329
|
+
__classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.updatePresence(userId, presence);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
__classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.trackPresence(userId, presence);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
326
335
|
}
|
|
327
336
|
exports.Channel = Channel;
|
|
328
337
|
_Channel_engine = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.153",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^29.5.12",
|
|
42
|
-
"@types/node": "^20.
|
|
42
|
+
"@types/node": "^20.12.5",
|
|
43
43
|
"@types/websocket": "^1.0.10",
|
|
44
44
|
"@types/ws": "^8.5.10",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
46
46
|
"eslint": "^8.57.0",
|
|
47
47
|
"eslint-plugin-file-progress": "^1.3.0",
|
|
48
48
|
"eslint-plugin-import": "^2.29.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"superwstest": "^2.0.3",
|
|
51
51
|
"ts-jest": "^29.1.2",
|
|
52
52
|
"ts-node": "^10.9.2",
|
|
53
|
-
"typescript": "^5.
|
|
53
|
+
"typescript": "^5.4.4"
|
|
54
54
|
},
|
|
55
55
|
"jest": {
|
|
56
56
|
"moduleFileExtensions": [
|
package/presence/presence.js
CHANGED
|
@@ -62,8 +62,9 @@ class PresenceEngine {
|
|
|
62
62
|
/**
|
|
63
63
|
* @desc Removes a presence from the presence engine
|
|
64
64
|
* @param presenceKey - The key of the presence
|
|
65
|
+
* @param safe - If true, it will not throw an error if the presence does not exist
|
|
65
66
|
*/
|
|
66
|
-
removePresence(presenceKey) {
|
|
67
|
+
removePresence(presenceKey, safe = false) {
|
|
67
68
|
const presence = __classPrivateFieldGet(this, _PresenceEngine_presenceMap, "f").get(presenceKey);
|
|
68
69
|
if (presence) {
|
|
69
70
|
__classPrivateFieldGet(this, _PresenceEngine_presenceMap, "f").delete(presenceKey);
|
|
@@ -72,7 +73,7 @@ class PresenceEngine {
|
|
|
72
73
|
presence: Array.from(__classPrivateFieldGet(this, _PresenceEngine_presenceMap, "f").values()),
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
|
-
else {
|
|
76
|
+
else if (!safe) {
|
|
76
77
|
const code = 404;
|
|
77
78
|
const message = `PresenceEngine: Presence with key ${presenceKey} does not exist`;
|
|
78
79
|
throw new pondError_1.PresenceError(message, code, __classPrivateFieldGet(this, _PresenceEngine_channel, "f").name, pondsocket_common_1.PresenceEventTypes.LEAVE);
|
|
@@ -114,6 +114,9 @@ describe('PresenceEngine', () => {
|
|
|
114
114
|
it('should throw an error if the presence does not exist', () => {
|
|
115
115
|
expect(() => presenceEngine.removePresence(presenceKey)).toThrowError(`PresenceEngine: Presence with key ${presenceKey} does not exist`);
|
|
116
116
|
});
|
|
117
|
+
it('should not throw an error if the safe flag is true', () => {
|
|
118
|
+
expect(() => presenceEngine.removePresence(presenceKey, true)).not.toThrow();
|
|
119
|
+
});
|
|
117
120
|
});
|
|
118
121
|
describe('getPresence', () => {
|
|
119
122
|
it('should return the presence', () => {
|
package/types.d.ts
CHANGED
|
@@ -216,6 +216,13 @@ export declare class Channel<EventType extends PondEventMap = PondEventMap, Pres
|
|
|
216
216
|
*/
|
|
217
217
|
updatePresence(userId: string, presence: PresenceType): void;
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* @desc Tracks or updates a user's presence in the channel
|
|
221
|
+
* @param userId - the id of the user to upsert
|
|
222
|
+
* @param presence - the presence data to upsert
|
|
223
|
+
*/
|
|
224
|
+
upsertPresence (userId: string, presence: PresenceType): void;
|
|
225
|
+
|
|
219
226
|
/**
|
|
220
227
|
* @desc Subscribes a user to a channel.
|
|
221
228
|
* @param {string} userId - The id of the user.
|