@eleven-am/pondsocket 0.1.70 → 0.1.71

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/README.md CHANGED
@@ -259,7 +259,7 @@ profanityChannel.onEvent('message', (req, res) => {
259
259
  res.accept();
260
260
  }
261
261
 
262
- // for more complete access to the channel, you can use the client object
262
+ // for more complete access to the channel, you can use the channel instance
263
263
  // const channel = req.channel;
264
264
  });
265
265
 
@@ -350,7 +350,7 @@ The `JoinRequest` class represents the request object when a client joins a chan
350
350
 
351
351
  - `user: UserData`: The user data associated with the client.
352
352
 
353
- - `client: Client`: The Client instance associated with the request.
353
+ - `channel: Channel`: The Channel instance associated with the request.
354
354
 
355
355
  ### JoinResponse
356
356
 
@@ -400,7 +400,7 @@ The `EventRequest` class represents the request object when an event is received
400
400
 
401
401
  - `user: UserData`: The user data associated with the client.
402
402
 
403
- - `client: Client`: The Client instance associated with the request.
403
+ - `channel: Channel`: The Channel instance associated with the request.
404
404
 
405
405
  ### EventResponse
406
406
 
@@ -472,7 +472,7 @@ The `PondClient` class represents a client that connects to the PondSocket serve
472
472
 
473
473
  - `disconnect(): void`: Disconnects the socket.
474
474
 
475
- - `createChannel(name: string, params?: JoinParams): Channel`: Creates a channel with the given name and optional join parameters.
475
+ - `createChannel(name: string, params?: JoinParams): ClientChannel`: Creates a channel with the given name and optional join parameters.
476
476
 
477
477
  - `onConnectionChange(callback: (state: boolean) => void): Unsubscribe`: Subscribes to the connection state changes and calls the provided callback when the state changes.
478
478
 
@@ -91,7 +91,8 @@ class ChannelEngine {
91
91
  */
92
92
  kickUser(userId, reason) {
93
93
  this.sendMessage(enums_1.SystemSender.CHANNEL, [userId], enums_1.ServerActions.SYSTEM, 'kicked_out', {
94
- message: reason !== null && reason !== void 0 ? reason : 'You have been kicked out of the channel',
94
+ message: reason,
95
+ code: 403,
95
96
  });
96
97
  this.removeUser(userId);
97
98
  this.sendMessage(enums_1.SystemSender.CHANNEL, enums_1.ChannelReceiver.ALL_USERS, enums_1.ServerActions.SYSTEM, 'kicked', {
@@ -197,24 +198,14 @@ class ChannelEngine {
197
198
  });
198
199
  });
199
200
  }
200
- /**
201
- * @desc Begins tracking a user's presence
202
- * @param userId - The id of the user to track
203
- * @param presence - The initial presence of the user
204
- */
205
- trackPresence(userId, presence) {
206
- var _a;
207
- if (!__classPrivateFieldGet(this, _ChannelEngine_users, "f").has(userId)) {
208
- throw new pondError_1.ChannelError(`ChannelEngine: User with id ${userId} does not exist in channel ${this.name}`, 404, this.name);
209
- }
210
- __classPrivateFieldSet(this, _ChannelEngine_presenceEngine, (_a = __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f")) !== null && _a !== void 0 ? _a : new presence_1.PresenceEngine(this), "f");
211
- __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f").trackPresence(userId, presence);
212
- }
213
201
  /**
214
202
  * @desc Gets the presence engine for the channel
215
203
  */
216
204
  get presenceEngine() {
217
- return __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f");
205
+ var _a;
206
+ const presenceEngine = (_a = __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f")) !== null && _a !== void 0 ? _a : new presence_1.PresenceEngine(this);
207
+ __classPrivateFieldSet(this, _ChannelEngine_presenceEngine, presenceEngine, "f");
208
+ return presenceEngine;
218
209
  }
219
210
  /**
220
211
  * @desc Gets the number of users in the channel
@@ -283,15 +274,13 @@ class Channel {
283
274
  __classPrivateFieldGet(this, _Channel_engine, "f").kickUser(userId, reason !== null && reason !== void 0 ? reason : 'You have been banned from the channel');
284
275
  }
285
276
  trackPresence(userId, presence) {
286
- __classPrivateFieldGet(this, _Channel_engine, "f").trackPresence(userId, presence);
277
+ __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.trackPresence(userId, presence);
287
278
  }
288
279
  removePresence(userId) {
289
- var _a;
290
- (_a = __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.removePresence(userId);
280
+ __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.removePresence(userId);
291
281
  }
292
282
  updatePresence(userId, presence) {
293
- var _a;
294
- (_a = __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.updatePresence(userId, presence);
283
+ __classPrivateFieldGet(this, _Channel_engine, "f").presenceEngine.updatePresence(userId, presence);
295
284
  }
296
285
  }
297
286
  exports.Channel = Channel;
@@ -94,8 +94,8 @@ class EventResponse extends abstractResponse_1.PondResponse {
94
94
  * @param presence - the initial presence data
95
95
  * @param userId - the id of the user to track
96
96
  */
97
- trackPresence(presence, userId) {
98
- __classPrivateFieldGet(this, _EventResponse_engine, "f").trackPresence(userId || __classPrivateFieldGet(this, _EventResponse_event, "f").sender, presence);
97
+ trackPresence(presence, userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
98
+ __classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine.trackPresence(userId, presence);
99
99
  return this;
100
100
  }
101
101
  /**
@@ -103,19 +103,16 @@ class EventResponse extends abstractResponse_1.PondResponse {
103
103
  * @param presence - the updated presence data
104
104
  * @param userId - the id of the user to update
105
105
  */
106
- updatePresence(presence, userId) {
107
- var _a;
108
- (_a = __classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.updatePresence(userId || __classPrivateFieldGet(this, _EventResponse_event, "f").sender, presence);
106
+ updatePresence(presence, userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
107
+ __classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine.updatePresence(userId, presence);
109
108
  return this;
110
109
  }
111
110
  /**
112
111
  * @desc Removes a user's presence from the channel
113
112
  * @param userId - the id of the user to remove
114
113
  */
115
- unTrackPresence(userId) {
116
- var _a;
117
- userId = userId || __classPrivateFieldGet(this, _EventResponse_event, "f").sender;
118
- (_a = __classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.removePresence(userId);
114
+ unTrackPresence(userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
115
+ __classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine.removePresence(userId);
119
116
  return this;
120
117
  }
121
118
  /**
@@ -123,8 +120,8 @@ class EventResponse extends abstractResponse_1.PondResponse {
123
120
  * @param reason - the reason for the eviction
124
121
  * @param userId - the id of the user to evict,
125
122
  */
126
- evictUser(reason, userId) {
127
- __classPrivateFieldGet(this, _EventResponse_engine, "f").kickUser(userId || __classPrivateFieldGet(this, _EventResponse_event, "f").sender, reason);
123
+ evictUser(reason, userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
124
+ __classPrivateFieldGet(this, _EventResponse_engine, "f").kickUser(userId, reason);
128
125
  }
129
126
  /**
130
127
  * @desc Closes the channel from the server side for all clients
@@ -110,7 +110,7 @@ class JoinResponse extends abstractResponse_1.PondResponse {
110
110
  * @param presence - the presence data to track
111
111
  */
112
112
  trackPresence(presence) {
113
- __classPrivateFieldGet(this, _JoinResponse_engine, "f").trackPresence(__classPrivateFieldGet(this, _JoinResponse_user, "f").clientId, presence);
113
+ __classPrivateFieldGet(this, _JoinResponse_engine, "f").presenceEngine.trackPresence(__classPrivateFieldGet(this, _JoinResponse_user, "f").clientId, presence);
114
114
  return this;
115
115
  }
116
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.70",
3
+ "version": "0.1.71",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -30,22 +30,22 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "websocket": "^1.0.34",
33
- "ws": "^8.13.0"
33
+ "ws": "^8.15.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/express": "^4.17.17",
37
- "@types/jest": "^29.5.3",
38
- "@types/node": "^20.4.4",
39
- "@types/websocket": "^1.0.5",
40
- "@types/ws": "^8.5.5",
41
- "@typescript-eslint/eslint-plugin": "^6.1.0",
42
- "eslint": "^8.45.0",
36
+ "@types/express": "^4.17.21",
37
+ "@types/jest": "^29.5.11",
38
+ "@types/node": "^20.10.4",
39
+ "@types/websocket": "^1.0.10",
40
+ "@types/ws": "^8.5.10",
41
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
42
+ "eslint": "^8.55.0",
43
43
  "eslint-plugin-file-progress": "^1.3.0",
44
- "eslint-plugin-import": "^2.27.5",
45
- "jest": "^29.6.1",
44
+ "eslint-plugin-import": "^2.29.0",
45
+ "jest": "^29.7.0",
46
46
  "superwstest": "^2.0.3",
47
47
  "ts-jest": "^29.1.1",
48
- "ts-node": "^10.9.1",
49
- "typescript": "^5.1.6"
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "^5.3.3"
50
50
  }
51
51
  }