@eleven-am/pondsocket 0.1.59 → 0.1.61

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.
@@ -35,7 +35,7 @@ class AbstractRequest {
35
35
  payload: __classPrivateFieldGet(this, _AbstractRequest_payload, "f"),
36
36
  };
37
37
  }
38
- get channelNme() {
38
+ get channelName() {
39
39
  return this._engine.name;
40
40
  }
41
41
  get assigns() {
@@ -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");
@@ -251,3 +251,37 @@ _ChannelEngine_receiver = new WeakMap(), _ChannelEngine_presenceEngine = new Wea
251
251
  }
252
252
  return users;
253
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();
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventRequest = void 0;
4
+ const channel_1 = require("./channel");
4
5
  const abstractRequest_1 = require("../abstracts/abstractRequest");
5
6
  const pondError_1 = require("../errors/pondError");
6
7
  class EventRequest extends abstractRequest_1.AbstractRequest {
@@ -17,5 +18,8 @@ class EventRequest extends abstractRequest_1.AbstractRequest {
17
18
  }
18
19
  return assigns;
19
20
  }
21
+ get client() {
22
+ return new channel_1.Client(this._engine);
23
+ }
20
24
  }
21
25
  exports.EventRequest = EventRequest;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.59",
3
+ "version": "0.1.61",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
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
- channelNme: string;
76
+ channelName: string;
77
77
 
78
78
  assigns: UserAssigns;
79
79
 
@@ -106,6 +106,8 @@ declare abstract class PondResponse {
106
106
 
107
107
  declare class EventRequest<Path extends string> extends AbstractRequest<Path> {
108
108
  user: UserData;
109
+
110
+ client: Client;
109
111
  }
110
112
 
111
113
  declare class EventResponse extends PondResponse {
@@ -313,10 +315,67 @@ declare class Endpoint {
313
315
  closeConnection (clientIds: string | string[]): void;
314
316
  }
315
317
 
318
+ export declare class Client {
319
+ /**
320
+ * @desc Gets the current assign data for the channel.
321
+ */
322
+ get getAssigns (): UserAssigns;
323
+
324
+ /**
325
+ * @desc Gets the assign date for a specific user.
326
+ * @param userId - The id of the user to get the assign data for.
327
+ */
328
+ getUserData (userId: string): UserData;
329
+
330
+ /**
331
+ * @desc Broadcasts a message to every client in the channel,
332
+ * @param event - The event to send.
333
+ * @param payload - The message to send.
334
+ */
335
+ broadcastMessage (event: string, payload: PondMessage): void;
336
+
337
+ /**
338
+ * @desc Sends a message to a specific client in the channel.
339
+ * @param userId - The id of the user to send the message to.
340
+ * @param event - The event to send.
341
+ * @param payload - The message to send.
342
+ */
343
+ sendToUser (userId: string, event: string, payload: PondMessage): void;
344
+
345
+ /**
346
+ * @desc Bans a user from the channel.
347
+ * @param userId - The id of the user to ban.
348
+ * @param reason - The reason for the ban.
349
+ */
350
+ banUser (userId: string, reason?: string): void;
351
+
352
+ /**
353
+ * @desc tracks a user's presence in the channel
354
+ * @param userId - the id of the user to track
355
+ * @param presence - the presence of the user
356
+ */
357
+ trackPresence (userId: string, presence: PondPresence): void;
358
+
359
+ /**
360
+ * @desc removes a user's presence from the channel
361
+ * @param userId - the id of the user to remove
362
+ */
363
+ removePresence (userId: string): void;
364
+
365
+ /**
366
+ * @desc updates a user's presence in the channel
367
+ * @param userId - the id of the user to update
368
+ * @param presence - the new presence of the user
369
+ */
370
+ updatePresence (userId: string, presence: PondPresence): void;
371
+ }
372
+
316
373
  declare class JoinRequest<Path extends string> extends AbstractRequest<Path> {
317
374
  joinParams: JoinParams;
318
375
 
319
376
  user: UserData;
377
+
378
+ client: Client;
320
379
  }
321
380
 
322
381
  declare class JoinResponse extends PondResponse {