@eleven-am/pondsocket 0.1.155 → 0.1.157

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.
@@ -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, true);
257
+ const userPresence = (_a = __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f")) === null || _a === void 0 ? void 0 : _a.removePresence(userId);
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
@@ -317,6 +317,9 @@ class Channel {
317
317
  updatePresence(userId, presence) {
318
318
  __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.updatePresence(userId, presence);
319
319
  }
320
+ updateAssigns(userId, assigns) {
321
+ __classPrivateFieldGet(this, _Channel_engine, "f").updateAssigns(userId, assigns);
322
+ }
320
323
  subscribeTo(userId, channel) {
321
324
  __classPrivateFieldGet(this, _Channel_engine, "f").subscribeTo(userId, channel);
322
325
  }
@@ -121,14 +121,6 @@ class EndpointEngine {
121
121
  __classPrivateFieldGet(this, _EndpointEngine_sockets, "f").delete(cache.clientId);
122
122
  cache.subscriptions.forEach((unsubscribe) => unsubscribe());
123
123
  });
124
- const event = {
125
- event: pondsocket_common_1.Events.CONNECTION,
126
- action: pondsocket_common_1.ServerActions.CONNECT,
127
- channelName: pondsocket_common_1.SystemSender.ENDPOINT,
128
- requestId: (0, pondsocket_common_1.uuid)(),
129
- payload: {},
130
- };
131
- this.sendMessage(socket, event);
132
124
  }
133
125
  /**
134
126
  * @desc Retrieves a user from the endpoint
@@ -228,13 +228,12 @@ describe('endpoint', () => {
228
228
  }))
229
229
  .close();
230
230
  }));
231
- it('should throw an error if accept, reject is called more than once', () => __awaiter(void 0, void 0, void 0, function* () {
231
+ it('should throw an error if accept, reject / send 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
- res.accept();
237
- expect(() => res.decline()).toThrowError('Cannot execute response more than once');
236
+ expect(() => res.accept()).toThrowError('Cannot execute response more than once');
238
237
  });
239
238
  yield (0, superwstest_1.default)(server)
240
239
  .ws('/api/socket')
@@ -14,7 +14,6 @@ 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");
18
17
  const pondError_1 = require("../errors/pondError");
19
18
  class ConnectionResponse {
20
19
  constructor(webSocket, engine, clientId) {
@@ -86,9 +85,7 @@ class ConnectionResponse {
86
85
  * @param payload - the payload to send
87
86
  */
88
87
  reply(event, payload) {
89
- if (__classPrivateFieldGet(this, _ConnectionResponse_webSocket, "f").readyState !== ws_1.WebSocket.OPEN) {
90
- throw new pondError_1.EndpointError('Socket is not open', 400);
91
- }
88
+ __classPrivateFieldGet(this, _ConnectionResponse_instances, "m", _ConnectionResponse_performChecks).call(this);
92
89
  __classPrivateFieldGet(this, _ConnectionResponse_instances, "m", _ConnectionResponse_sendMessage).call(this, pondsocket_common_1.ServerActions.BROADCAST, event, payload);
93
90
  return this;
94
91
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseAddress = void 0;
3
+ exports.parseAddress = parseAddress;
4
4
  function pathToRegexp(path) {
5
5
  const parts = path.split('/');
6
6
  const regexpParts = parts.map((part) => {
@@ -72,4 +72,3 @@ function parseAddress(route, address) {
72
72
  query,
73
73
  };
74
74
  }
75
- exports.parseAddress = parseAddress;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.155",
3
+ "version": "0.1.157",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -35,22 +35,22 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@eleven-am/pondsocket-common": "^0.0.18",
38
- "ws": "^8.16.0"
38
+ "ws": "^8.17.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jest": "^29.5.12",
42
- "@types/node": "^20.12.5",
42
+ "@types/node": "^20.14.9",
43
43
  "@types/websocket": "^1.0.10",
44
44
  "@types/ws": "^8.5.10",
45
- "@typescript-eslint/eslint-plugin": "^7.5.0",
45
+ "@typescript-eslint/eslint-plugin": "^7.1.0",
46
46
  "eslint": "^8.57.0",
47
47
  "eslint-plugin-file-progress": "^1.3.0",
48
48
  "eslint-plugin-import": "^2.29.1",
49
49
  "jest": "^29.7.0",
50
50
  "superwstest": "^2.0.3",
51
- "ts-jest": "^29.1.2",
51
+ "ts-jest": "^29.1.5",
52
52
  "ts-node": "^10.9.2",
53
- "typescript": "^5.4.4"
53
+ "typescript": "^5.5.2"
54
54
  },
55
55
  "jest": {
56
56
  "moduleFileExtensions": [
@@ -62,9 +62,8 @@ 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
66
65
  */
67
- removePresence(presenceKey, safe = false) {
66
+ removePresence(presenceKey) {
68
67
  const presence = __classPrivateFieldGet(this, _PresenceEngine_presenceMap, "f").get(presenceKey);
69
68
  if (presence) {
70
69
  __classPrivateFieldGet(this, _PresenceEngine_presenceMap, "f").delete(presenceKey);
@@ -73,7 +72,7 @@ class PresenceEngine {
73
72
  presence: Array.from(__classPrivateFieldGet(this, _PresenceEngine_presenceMap, "f").values()),
74
73
  });
75
74
  }
76
- else if (!safe) {
75
+ else {
77
76
  const code = 404;
78
77
  const message = `PresenceEngine: Presence with key ${presenceKey} does not exist`;
79
78
  throw new pondError_1.PresenceError(message, code, __classPrivateFieldGet(this, _PresenceEngine_channel, "f").name, pondsocket_common_1.PresenceEventTypes.LEAVE);
@@ -114,9 +114,6 @@ 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
- });
120
117
  });
121
118
  describe('getPresence', () => {
122
119
  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 Updates a user's assigns in the channel
221
+ * @param userId - the id of the user to update
222
+ * @param assigns - the assigns data to update
223
+ */
224
+ updateAssigns(userId: string, assigns: AssignType): void;
225
+
219
226
  /**
220
227
  * @desc Tracks or updates a user's presence in the channel
221
228
  * @param userId - the id of the user to upsert