@eleven-am/pondsocket 0.1.57 → 0.1.59

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.
Files changed (71) hide show
  1. package/{dist/channel → channel}/channel.js +5 -3
  2. package/package.json +3 -3
  3. package/.eslintrc.json +0 -387
  4. package/dist/LICENSE +0 -674
  5. package/dist/README.md +0 -139
  6. package/dist/package.json +0 -51
  7. package/jest.config.js +0 -11
  8. package/src/abstracts/abstractRequest.test.ts +0 -49
  9. package/src/abstracts/abstractRequest.ts +0 -56
  10. package/src/abstracts/abstractResponse.ts +0 -26
  11. package/src/abstracts/middleware.test.ts +0 -75
  12. package/src/abstracts/middleware.ts +0 -50
  13. package/src/channel/channel.test.ts +0 -501
  14. package/src/channel/channel.ts +0 -305
  15. package/src/channel/eventRequest.test.ts +0 -37
  16. package/src/channel/eventRequest.ts +0 -27
  17. package/src/channel/eventResponse.test.ts +0 -249
  18. package/src/channel/eventResponse.ts +0 -172
  19. package/src/client/channel.test.ts +0 -799
  20. package/src/client/channel.ts +0 -342
  21. package/src/client.ts +0 -124
  22. package/src/endpoint/endpoint.test.ts +0 -825
  23. package/src/endpoint/endpoint.ts +0 -304
  24. package/src/endpoint/response.ts +0 -106
  25. package/src/enums.ts +0 -52
  26. package/src/errors/pondError.ts +0 -32
  27. package/src/express.ts +0 -58
  28. package/src/index.ts +0 -3
  29. package/src/lobby/JoinRequest.test.ts +0 -48
  30. package/src/lobby/JoinResponse.test.ts +0 -162
  31. package/src/lobby/joinRequest.ts +0 -32
  32. package/src/lobby/joinResponse.ts +0 -146
  33. package/src/lobby/lobby.ts +0 -182
  34. package/src/matcher/matcher.test.ts +0 -103
  35. package/src/matcher/matcher.ts +0 -105
  36. package/src/node.ts +0 -33
  37. package/src/presence/presence.ts +0 -127
  38. package/src/presence/presenceEngine.test.ts +0 -143
  39. package/src/server/pondSocket.ts +0 -153
  40. package/src/subjects/subject.test.ts +0 -163
  41. package/src/subjects/subject.ts +0 -137
  42. package/src/typedefs.d.ts +0 -451
  43. package/src/types.d.ts +0 -89
  44. package/tsconfig.build.json +0 -7
  45. package/tsconfig.json +0 -12
  46. /package/{dist/abstracts → abstracts}/abstractRequest.js +0 -0
  47. /package/{dist/abstracts → abstracts}/abstractResponse.js +0 -0
  48. /package/{dist/abstracts → abstracts}/middleware.js +0 -0
  49. /package/{dist/channel → channel}/eventRequest.js +0 -0
  50. /package/{dist/channel → channel}/eventResponse.js +0 -0
  51. /package/{dist/client → client}/channel.js +0 -0
  52. /package/{dist/client.d.ts → client.d.ts} +0 -0
  53. /package/{dist/client.js → client.js} +0 -0
  54. /package/{dist/endpoint → endpoint}/endpoint.js +0 -0
  55. /package/{dist/endpoint → endpoint}/response.js +0 -0
  56. /package/{dist/enums.js → enums.js} +0 -0
  57. /package/{dist/errors → errors}/pondError.js +0 -0
  58. /package/{dist/express.d.ts → express.d.ts} +0 -0
  59. /package/{dist/express.js → express.js} +0 -0
  60. /package/{dist/index.d.ts → index.d.ts} +0 -0
  61. /package/{dist/index.js → index.js} +0 -0
  62. /package/{dist/lobby → lobby}/joinRequest.js +0 -0
  63. /package/{dist/lobby → lobby}/joinResponse.js +0 -0
  64. /package/{dist/lobby → lobby}/lobby.js +0 -0
  65. /package/{dist/matcher → matcher}/matcher.js +0 -0
  66. /package/{dist/node.d.ts → node.d.ts} +0 -0
  67. /package/{dist/node.js → node.js} +0 -0
  68. /package/{dist/presence → presence}/presence.js +0 -0
  69. /package/{dist/server → server}/pondSocket.js +0 -0
  70. /package/{dist/subjects → subjects}/subject.js +0 -0
  71. /package/{dist/types.d.ts → types.d.ts} +0 -0
@@ -1,172 +0,0 @@
1
- import { ChannelEngine, BroadcastEvent } from './channel';
2
- import { PondResponse } from '../abstracts/abstractResponse';
3
- import { SystemSender, ServerActions, ErrorTypes, ChannelReceiver } from '../enums';
4
- import { ChannelError } from '../errors/pondError';
5
- // eslint-disable-next-line import/no-unresolved
6
- import { PondAssigns, PondMessage, PondPresence } from '../types';
7
-
8
- export class EventResponse extends PondResponse {
9
- readonly #event: BroadcastEvent;
10
-
11
- readonly #engine: ChannelEngine;
12
-
13
- #executed: boolean;
14
-
15
- constructor (event: BroadcastEvent, engine: ChannelEngine) {
16
- super();
17
- this.#event = event;
18
- this.#engine = engine;
19
- this.#executed = false;
20
- }
21
-
22
- /**
23
- * @desc Accepts the request and optionally assigns data to the client
24
- * @param assigns - the data to assign to the client
25
- */
26
- public accept (assigns?: PondAssigns): EventResponse {
27
- this.#manageAssigns(assigns);
28
- this.#engine.sendMessage(this.#event.sender, this.#event.recipients, this.#event.action, this.#event.event, this.#event.payload);
29
-
30
- return this;
31
- }
32
-
33
- /**
34
- * @desc Rejects the request and optionally assigns data to the client
35
- * @param message - the error message
36
- * @param errorCode - the error code
37
- * @param assigns - the data to assign to the client
38
- */
39
- public reject (message?: string, errorCode?: number, assigns?: PondAssigns): EventResponse {
40
- this.#manageAssigns(assigns);
41
- const text = message || 'Unauthorized request';
42
-
43
- this.#engine.sendMessage(SystemSender.CHANNEL, [this.#event.sender], ServerActions.ERROR, ErrorTypes.UNAUTHORIZED_BROADCAST, {
44
- message: text,
45
- code: errorCode || 403,
46
- });
47
-
48
- return this;
49
- }
50
-
51
- /**
52
- * @desc Emits a direct message to the client
53
- * @param event - the event name
54
- * @param payload - the payload to send
55
- * @param assigns - the data to assign to the client
56
- */
57
- public send (event: string, payload: PondMessage, assigns?: PondAssigns) {
58
- this.accept(assigns);
59
- this.#engine.sendMessage(SystemSender.CHANNEL, [this.#event.sender], ServerActions.SYSTEM, event, payload);
60
- }
61
-
62
- /**
63
- * @desc Sends a message to all clients in the channel
64
- * @param event - the event to send
65
- * @param payload - the payload to send
66
- */
67
- public broadcast (event: string, payload: PondMessage): EventResponse {
68
- this.#engine.sendMessage(this.#event.sender, ChannelReceiver.ALL_USERS, ServerActions.BROADCAST, event, payload);
69
-
70
- return this;
71
- }
72
-
73
- /**
74
- * @desc Sends a message to all clients in the channel except the client making the request
75
- * @param event - the event to send
76
- * @param payload - the payload to send
77
- */
78
- public broadcastFromUser (event: string, payload: PondMessage): EventResponse {
79
- this.#engine.sendMessage(this.#event.sender, ChannelReceiver.ALL_EXCEPT_SENDER, ServerActions.BROADCAST, event, payload);
80
-
81
- return this;
82
- }
83
-
84
- /**
85
- * @desc Sends a message to a set of clients in the channel
86
- * @param event - the event to send
87
- * @param payload - the payload to send
88
- * @param userIds - the ids of the clients to send the message to
89
- */
90
- public sendToUsers (event: string, payload: PondMessage, userIds: string[]): EventResponse {
91
- this.#engine.sendMessage(this.#event.sender, userIds, ServerActions.BROADCAST, event, payload);
92
-
93
- return this;
94
- }
95
-
96
- /**
97
- * @desc Tracks a user's presence in the channel
98
- * @param presence - the initial presence data
99
- * @param userId - the id of the user to track
100
- */
101
- public trackPresence (presence: PondPresence, userId?: string): EventResponse {
102
- this.#engine.trackPresence(userId || this.#event.sender, presence);
103
-
104
- return this;
105
- }
106
-
107
- /**
108
- * @desc Updates a user's presence in the channel
109
- * @param presence - the updated presence data
110
- * @param userId - the id of the user to update
111
- */
112
- public updatePresence (presence: PondPresence, userId?: string): EventResponse {
113
- this.#engine.presenceEngine?.updatePresence(userId || this.#event.sender, presence);
114
-
115
- return this;
116
- }
117
-
118
- /**
119
- * @desc Removes a user's presence from the channel
120
- * @param userId - the id of the user to remove
121
- */
122
- public unTrackPresence (userId?: string): EventResponse {
123
- userId = userId || this.#event.sender;
124
- this.#engine.presenceEngine?.removePresence(userId);
125
-
126
- return this;
127
- }
128
-
129
- /**
130
- * @desc Evicts a user from the channel
131
- * @param reason - the reason for the eviction
132
- * @param userId - the id of the user to evict,
133
- */
134
- public evictUser (reason: string, userId?: string): void {
135
- this.#engine.kickUser(userId || this.#event.sender, reason);
136
- }
137
-
138
- /**
139
- * @desc Closes the channel from the server side for all clients
140
- * @param reason - the reason for closing the channel
141
- */
142
- public closeChannel (reason: string): void {
143
- this.#engine.destroy(reason);
144
- }
145
-
146
- /**
147
- * @desc Gets the event that triggered the response
148
- * @param assigns - the data to assign to the client
149
- * @private
150
- */
151
- #manageAssigns (assigns?: PondAssigns): void {
152
- this.#performChecks();
153
- if (assigns) {
154
- this.#engine.updateAssigns(this.#event.sender, assigns);
155
- }
156
- }
157
-
158
- /**
159
- * @desc Performs checks to ensure the response has not been executed
160
- * @private
161
- */
162
- #performChecks (): void {
163
- if (this.#executed) {
164
- const message = 'Event response has already been executed';
165
- const code = 403;
166
-
167
- throw new ChannelError(message, code, this.#engine.name);
168
- }
169
-
170
- this.#executed = true;
171
- }
172
- }