@eleven-am/pondsocket 0.1.70 → 0.1.72
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 +4 -4
- package/channel/channel.js +9 -20
- package/channel/eventResponse.js +14 -11
- package/endpoint/response.js +6 -0
- package/lobby/joinResponse.js +7 -1
- package/package.json +13 -13
- package/types.d.ts +20 -0
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
|
|
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
|
-
- `
|
|
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
|
-
- `
|
|
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):
|
|
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
|
|
package/channel/channel.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
package/channel/eventResponse.js
CHANGED
|
@@ -27,6 +27,12 @@ class EventResponse extends abstractResponse_1.PondResponse {
|
|
|
27
27
|
__classPrivateFieldSet(this, _EventResponse_engine, engine, "f");
|
|
28
28
|
__classPrivateFieldSet(this, _EventResponse_executed, false, "f");
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* @desc Whether the server has responded to the request
|
|
32
|
+
*/
|
|
33
|
+
get hasResponded() {
|
|
34
|
+
return __classPrivateFieldGet(this, _EventResponse_executed, "f");
|
|
35
|
+
}
|
|
30
36
|
/**
|
|
31
37
|
* @desc Accepts the request and optionally assigns data to the client
|
|
32
38
|
* @param assigns - the data to assign to the client
|
|
@@ -94,8 +100,8 @@ class EventResponse extends abstractResponse_1.PondResponse {
|
|
|
94
100
|
* @param presence - the initial presence data
|
|
95
101
|
* @param userId - the id of the user to track
|
|
96
102
|
*/
|
|
97
|
-
trackPresence(presence, userId) {
|
|
98
|
-
__classPrivateFieldGet(this, _EventResponse_engine, "f").trackPresence(userId
|
|
103
|
+
trackPresence(presence, userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
|
|
104
|
+
__classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine.trackPresence(userId, presence);
|
|
99
105
|
return this;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
@@ -103,19 +109,16 @@ class EventResponse extends abstractResponse_1.PondResponse {
|
|
|
103
109
|
* @param presence - the updated presence data
|
|
104
110
|
* @param userId - the id of the user to update
|
|
105
111
|
*/
|
|
106
|
-
updatePresence(presence, userId) {
|
|
107
|
-
|
|
108
|
-
(_a = __classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.updatePresence(userId || __classPrivateFieldGet(this, _EventResponse_event, "f").sender, presence);
|
|
112
|
+
updatePresence(presence, userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
|
|
113
|
+
__classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine.updatePresence(userId, presence);
|
|
109
114
|
return this;
|
|
110
115
|
}
|
|
111
116
|
/**
|
|
112
117
|
* @desc Removes a user's presence from the channel
|
|
113
118
|
* @param userId - the id of the user to remove
|
|
114
119
|
*/
|
|
115
|
-
unTrackPresence(userId) {
|
|
116
|
-
|
|
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);
|
|
120
|
+
unTrackPresence(userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
|
|
121
|
+
__classPrivateFieldGet(this, _EventResponse_engine, "f").presenceEngine.removePresence(userId);
|
|
119
122
|
return this;
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
@@ -123,8 +126,8 @@ class EventResponse extends abstractResponse_1.PondResponse {
|
|
|
123
126
|
* @param reason - the reason for the eviction
|
|
124
127
|
* @param userId - the id of the user to evict,
|
|
125
128
|
*/
|
|
126
|
-
evictUser(reason, userId) {
|
|
127
|
-
__classPrivateFieldGet(this, _EventResponse_engine, "f").kickUser(userId
|
|
129
|
+
evictUser(reason, userId = __classPrivateFieldGet(this, _EventResponse_event, "f").sender) {
|
|
130
|
+
__classPrivateFieldGet(this, _EventResponse_engine, "f").kickUser(userId, reason);
|
|
128
131
|
}
|
|
129
132
|
/**
|
|
130
133
|
* @desc Closes the channel from the server side for all clients
|
package/endpoint/response.js
CHANGED
|
@@ -29,6 +29,12 @@ class ConnectionResponse extends abstractResponse_1.PondResponse {
|
|
|
29
29
|
__classPrivateFieldSet(this, _ConnectionResponse_clientId, clientId, "f");
|
|
30
30
|
__classPrivateFieldSet(this, _ConnectionResponse_executed, false, "f");
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* @desc Whether the server has responded to the request
|
|
34
|
+
*/
|
|
35
|
+
get hasResponded() {
|
|
36
|
+
return __classPrivateFieldGet(this, _ConnectionResponse_executed, "f");
|
|
37
|
+
}
|
|
32
38
|
/**
|
|
33
39
|
* @desc Accepts the request and optionally assigns data to the client
|
|
34
40
|
* @param assigns - the data to assign to the client
|
package/lobby/joinResponse.js
CHANGED
|
@@ -27,6 +27,12 @@ class JoinResponse extends abstractResponse_1.PondResponse {
|
|
|
27
27
|
__classPrivateFieldSet(this, _JoinResponse_engine, engine, "f");
|
|
28
28
|
__classPrivateFieldSet(this, _JoinResponse_executed, false, "f");
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* @desc Whether the server has responded to the request
|
|
32
|
+
*/
|
|
33
|
+
get hasResponded() {
|
|
34
|
+
return __classPrivateFieldGet(this, _JoinResponse_executed, "f");
|
|
35
|
+
}
|
|
30
36
|
/**
|
|
31
37
|
* @desc Accepts the request and optionally assigns data to the client
|
|
32
38
|
* @param assigns - the data to assign to the client
|
|
@@ -110,7 +116,7 @@ class JoinResponse extends abstractResponse_1.PondResponse {
|
|
|
110
116
|
* @param presence - the presence data to track
|
|
111
117
|
*/
|
|
112
118
|
trackPresence(presence) {
|
|
113
|
-
__classPrivateFieldGet(this, _JoinResponse_engine, "f").trackPresence(__classPrivateFieldGet(this, _JoinResponse_user, "f").clientId, presence);
|
|
119
|
+
__classPrivateFieldGet(this, _JoinResponse_engine, "f").presenceEngine.trackPresence(__classPrivateFieldGet(this, _JoinResponse_user, "f").clientId, presence);
|
|
114
120
|
return this;
|
|
115
121
|
}
|
|
116
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.72",
|
|
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.
|
|
33
|
+
"ws": "^8.15.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/express": "^4.17.
|
|
37
|
-
"@types/jest": "^29.5.
|
|
38
|
-
"@types/node": "^20.
|
|
39
|
-
"@types/websocket": "^1.0.
|
|
40
|
-
"@types/ws": "^8.5.
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
42
|
-
"eslint": "^8.
|
|
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.
|
|
45
|
-
"jest": "^29.
|
|
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.
|
|
49
|
-
"typescript": "^5.
|
|
48
|
+
"ts-node": "^10.9.2",
|
|
49
|
+
"typescript": "^5.3.3"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/types.d.ts
CHANGED
|
@@ -85,6 +85,11 @@ declare class AbstractRequest<Path extends string> {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
declare abstract class PondResponse {
|
|
88
|
+
/**
|
|
89
|
+
* @desc Whether the server has responded to the request
|
|
90
|
+
*/
|
|
91
|
+
public abstract hasResponded: boolean;
|
|
92
|
+
|
|
88
93
|
/**
|
|
89
94
|
* @desc Rejects the request with the given error message
|
|
90
95
|
* @param message - the error message
|
|
@@ -115,6 +120,11 @@ declare class EventRequest<Path extends string> extends AbstractRequest<Path> {
|
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
declare class EventResponse extends PondResponse {
|
|
123
|
+
/**
|
|
124
|
+
* @desc Whether the server has responded to the request
|
|
125
|
+
*/
|
|
126
|
+
hasResponded: boolean;
|
|
127
|
+
|
|
118
128
|
/**
|
|
119
129
|
* @desc Accepts the request and optionally assigns data to the client
|
|
120
130
|
* @param assigns - the data to assign to the client
|
|
@@ -396,6 +406,11 @@ declare class JoinRequest<Path extends string> extends AbstractRequest<Path> {
|
|
|
396
406
|
}
|
|
397
407
|
|
|
398
408
|
declare class JoinResponse extends PondResponse {
|
|
409
|
+
/**
|
|
410
|
+
* @desc Whether the server has responded to the request
|
|
411
|
+
*/
|
|
412
|
+
hasResponded: boolean;
|
|
413
|
+
|
|
399
414
|
/**
|
|
400
415
|
* @desc Accepts the request and optionally assigns data to the client
|
|
401
416
|
* @param assigns - the data to assign to the client
|
|
@@ -447,6 +462,11 @@ declare class JoinResponse extends PondResponse {
|
|
|
447
462
|
}
|
|
448
463
|
|
|
449
464
|
declare class ConnectionResponse extends PondResponse {
|
|
465
|
+
/**
|
|
466
|
+
* @desc Whether the server has responded to the request
|
|
467
|
+
*/
|
|
468
|
+
hasResponded: boolean;
|
|
469
|
+
|
|
450
470
|
/**
|
|
451
471
|
* @desc Accepts the request and optionally assigns data to the client
|
|
452
472
|
* @param assigns - the data to assign to the client
|