@eleven-am/pondsocket 0.1.152 → 0.1.154
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
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
|
|
@@ -228,12 +228,13 @@ describe('endpoint', () => {
|
|
|
228
228
|
}))
|
|
229
229
|
.close();
|
|
230
230
|
}));
|
|
231
|
-
it('should throw an error if accept, reject
|
|
231
|
+
it('should throw an error if accept, reject is called more than once', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
232
|
socket.createEndpoint('/api/:room', (_, res) => {
|
|
233
233
|
res.reply('hello', {
|
|
234
234
|
test: 'test',
|
|
235
235
|
});
|
|
236
|
-
|
|
236
|
+
res.accept();
|
|
237
|
+
expect(() => res.decline()).toThrowError('Cannot execute response more than once');
|
|
237
238
|
});
|
|
238
239
|
yield (0, superwstest_1.default)(server)
|
|
239
240
|
.ws('/api/socket')
|
package/endpoint/response.js
CHANGED
|
@@ -14,6 +14,7 @@ var _ConnectionResponse_instances, _ConnectionResponse_webSocket, _ConnectionRes
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ConnectionResponse = void 0;
|
|
16
16
|
const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
|
|
17
|
+
const ws_1 = require("ws");
|
|
17
18
|
const pondError_1 = require("../errors/pondError");
|
|
18
19
|
class ConnectionResponse {
|
|
19
20
|
constructor(webSocket, engine, clientId) {
|
|
@@ -85,7 +86,9 @@ class ConnectionResponse {
|
|
|
85
86
|
* @param payload - the payload to send
|
|
86
87
|
*/
|
|
87
88
|
reply(event, payload) {
|
|
88
|
-
__classPrivateFieldGet(this,
|
|
89
|
+
if (__classPrivateFieldGet(this, _ConnectionResponse_webSocket, "f").readyState !== ws_1.WebSocket.OPEN) {
|
|
90
|
+
throw new pondError_1.EndpointError('Socket is not open', 400);
|
|
91
|
+
}
|
|
89
92
|
__classPrivateFieldGet(this, _ConnectionResponse_instances, "m", _ConnectionResponse_sendMessage).call(this, pondsocket_common_1.ServerActions.BROADCAST, event, payload);
|
|
90
93
|
return this;
|
|
91
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.154",
|
|
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', () => {
|