@eleven-am/pondsocket 0.1.58 → 0.1.60
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/abstracts/abstractRequest.js +1 -1
- package/channel/channel.js +41 -5
- package/lobby/joinRequest.js +4 -0
- package/package.json +1 -1
- package/types.d.ts +58 -1
package/channel/channel.js
CHANGED
|
@@ -21,9 +21,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
}
|
|
22
22
|
return t;
|
|
23
23
|
};
|
|
24
|
-
var _ChannelEngine_instances, _ChannelEngine_receiver, _ChannelEngine_presenceEngine, _ChannelEngine_users, _ChannelEngine_parentEngine, _ChannelEngine_subscribe, _ChannelEngine_getUsersFromRecipients;
|
|
24
|
+
var _ChannelEngine_instances, _ChannelEngine_receiver, _ChannelEngine_presenceEngine, _ChannelEngine_users, _ChannelEngine_parentEngine, _ChannelEngine_subscribe, _ChannelEngine_getUsersFromRecipients, _Client_engine;
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ChannelEngine = void 0;
|
|
26
|
+
exports.Client = exports.ChannelEngine = void 0;
|
|
27
27
|
const eventRequest_1 = require("./eventRequest");
|
|
28
28
|
const eventResponse_1 = require("./eventResponse");
|
|
29
29
|
const enums_1 = require("../enums");
|
|
@@ -240,12 +240,48 @@ _ChannelEngine_receiver = new WeakMap(), _ChannelEngine_presenceEngine = new Wea
|
|
|
240
240
|
users = allUsers.filter((user) => user !== sender);
|
|
241
241
|
break;
|
|
242
242
|
default:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
if (!Array.isArray(recipients) || !recipients.every((recipient) => typeof recipient === 'string')) {
|
|
244
|
+
throw new pondError_1.ChannelError(`ChannelEngine: Invalid recipients ${recipients}`, 500, this.name);
|
|
245
|
+
}
|
|
246
|
+
if (recipients.some((user) => !allUsers.includes(user))) {
|
|
247
|
+
throw new pondError_1.ChannelError(`ChannelEngine: Invalid recipients ${recipients} some users do not exist in channel ${this.name}`, 500, this.name);
|
|
246
248
|
}
|
|
247
249
|
users = recipients;
|
|
248
250
|
break;
|
|
249
251
|
}
|
|
250
252
|
return users;
|
|
251
253
|
};
|
|
254
|
+
class Client {
|
|
255
|
+
constructor(engine) {
|
|
256
|
+
_Client_engine.set(this, void 0);
|
|
257
|
+
__classPrivateFieldSet(this, _Client_engine, engine, "f");
|
|
258
|
+
}
|
|
259
|
+
getAssigns() {
|
|
260
|
+
return __classPrivateFieldGet(this, _Client_engine, "f").getAssigns();
|
|
261
|
+
}
|
|
262
|
+
getUserData(userId) {
|
|
263
|
+
return __classPrivateFieldGet(this, _Client_engine, "f").getUserData(userId);
|
|
264
|
+
}
|
|
265
|
+
broadcastMessage(event, payload) {
|
|
266
|
+
__classPrivateFieldGet(this, _Client_engine, "f").sendMessage(enums_1.SystemSender.CHANNEL, enums_1.ChannelReceiver.ALL_USERS, enums_1.ServerActions.BROADCAST, event, payload);
|
|
267
|
+
}
|
|
268
|
+
sendToUser(userId, event, payload) {
|
|
269
|
+
__classPrivateFieldGet(this, _Client_engine, "f").sendMessage(enums_1.SystemSender.CHANNEL, [userId], enums_1.ServerActions.BROADCAST, event, payload);
|
|
270
|
+
}
|
|
271
|
+
banUser(userId, reason) {
|
|
272
|
+
__classPrivateFieldGet(this, _Client_engine, "f").kickUser(userId, reason !== null && reason !== void 0 ? reason : 'You have been banned from the channel');
|
|
273
|
+
}
|
|
274
|
+
trackPresence(userId, presence) {
|
|
275
|
+
__classPrivateFieldGet(this, _Client_engine, "f").trackPresence(userId, presence);
|
|
276
|
+
}
|
|
277
|
+
removePresence(userId) {
|
|
278
|
+
var _a;
|
|
279
|
+
(_a = __classPrivateFieldGet(this, _Client_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.removePresence(userId);
|
|
280
|
+
}
|
|
281
|
+
updatePresence(userId, presence) {
|
|
282
|
+
var _a;
|
|
283
|
+
(_a = __classPrivateFieldGet(this, _Client_engine, "f").presenceEngine) === null || _a === void 0 ? void 0 : _a.updatePresence(userId, presence);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.Client = Client;
|
|
287
|
+
_Client_engine = new WeakMap();
|
package/lobby/joinRequest.js
CHANGED
|
@@ -14,6 +14,7 @@ var _JoinRequest_params, _JoinRequest_clientId, _JoinRequest_assigns;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.JoinRequest = void 0;
|
|
16
16
|
const abstractRequest_1 = require("../abstracts/abstractRequest");
|
|
17
|
+
const channel_1 = require("../channel/channel");
|
|
17
18
|
class JoinRequest extends abstractRequest_1.AbstractRequest {
|
|
18
19
|
constructor(event, params, engine) {
|
|
19
20
|
super(engine.name, engine, params);
|
|
@@ -34,6 +35,9 @@ class JoinRequest extends abstractRequest_1.AbstractRequest {
|
|
|
34
35
|
presence: {},
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
get client() {
|
|
39
|
+
return new channel_1.Client(this._engine);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
exports.JoinRequest = JoinRequest;
|
|
39
43
|
_JoinRequest_params = new WeakMap(), _JoinRequest_clientId = new WeakMap(), _JoinRequest_assigns = new WeakMap();
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export enum ChannelState {
|
|
|
73
73
|
declare class AbstractRequest<Path extends string> {
|
|
74
74
|
event: PondEvent<Path>;
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
channelName: string;
|
|
77
77
|
|
|
78
78
|
assigns: UserAssigns;
|
|
79
79
|
|
|
@@ -313,10 +313,67 @@ declare class Endpoint {
|
|
|
313
313
|
closeConnection (clientIds: string | string[]): void;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
export declare class Client {
|
|
317
|
+
/**
|
|
318
|
+
* @desc Gets the current assign data for the channel.
|
|
319
|
+
*/
|
|
320
|
+
get getAssigns (): UserAssigns;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @desc Gets the assign date for a specific user.
|
|
324
|
+
* @param userId - The id of the user to get the assign data for.
|
|
325
|
+
*/
|
|
326
|
+
getUserData (userId: string): UserData;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* @desc Broadcasts a message to every client in the channel,
|
|
330
|
+
* @param event - The event to send.
|
|
331
|
+
* @param payload - The message to send.
|
|
332
|
+
*/
|
|
333
|
+
broadcastMessage (event: string, payload: PondMessage): void;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @desc Sends a message to a specific client in the channel.
|
|
337
|
+
* @param userId - The id of the user to send the message to.
|
|
338
|
+
* @param event - The event to send.
|
|
339
|
+
* @param payload - The message to send.
|
|
340
|
+
*/
|
|
341
|
+
sendToUser (userId: string, event: string, payload: PondMessage): void;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @desc Bans a user from the channel.
|
|
345
|
+
* @param userId - The id of the user to ban.
|
|
346
|
+
* @param reason - The reason for the ban.
|
|
347
|
+
*/
|
|
348
|
+
banUser (userId: string, reason?: string): void;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @desc tracks a user's presence in the channel
|
|
352
|
+
* @param userId - the id of the user to track
|
|
353
|
+
* @param presence - the presence of the user
|
|
354
|
+
*/
|
|
355
|
+
trackPresence (userId: string, presence: PondPresence): void;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* @desc removes a user's presence from the channel
|
|
359
|
+
* @param userId - the id of the user to remove
|
|
360
|
+
*/
|
|
361
|
+
removePresence (userId: string): void;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* @desc updates a user's presence in the channel
|
|
365
|
+
* @param userId - the id of the user to update
|
|
366
|
+
* @param presence - the new presence of the user
|
|
367
|
+
*/
|
|
368
|
+
updatePresence (userId: string, presence: PondPresence): void;
|
|
369
|
+
}
|
|
370
|
+
|
|
316
371
|
declare class JoinRequest<Path extends string> extends AbstractRequest<Path> {
|
|
317
372
|
joinParams: JoinParams;
|
|
318
373
|
|
|
319
374
|
user: UserData;
|
|
375
|
+
|
|
376
|
+
client: Client;
|
|
320
377
|
}
|
|
321
378
|
|
|
322
379
|
declare class JoinResponse extends PondResponse {
|