@eleven-am/pondsocket 0.1.138 → 0.1.141

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.
@@ -104,8 +104,9 @@ class ChannelEngine {
104
104
  /**
105
105
  * @desc Removes a user from the channel
106
106
  * @param userId - The id of the user to remove
107
+ * @param isGraceful - Whether the user is being removed gracefully
107
108
  */
108
- removeUser(userId) {
109
+ removeUser(userId, isGraceful) {
109
110
  var _a;
110
111
  const user = __classPrivateFieldGet(this, _ChannelEngine_users, "f").get(userId);
111
112
  if (user) {
@@ -126,7 +127,7 @@ class ChannelEngine {
126
127
  __classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").destroyChannel();
127
128
  }
128
129
  }
129
- else {
130
+ else if (!isGraceful) {
130
131
  throw new pondError_1.ChannelError(`ChannelEngine: User with id ${userId} does not exist in channel ${this.name}`, 404, this.name);
131
132
  }
132
133
  }
@@ -140,7 +141,7 @@ class ChannelEngine {
140
141
  message: reason,
141
142
  code: 403,
142
143
  });
143
- this.removeUser(userId);
144
+ this.removeUser(userId, false);
144
145
  this.sendMessage((0, pondsocket_common_1.uuid)(), pondsocket_common_1.SystemSender.CHANNEL, pondsocket_common_1.ChannelReceiver.ALL_USERS, pondsocket_common_1.ServerActions.SYSTEM, 'kicked', {
145
146
  userId,
146
147
  reason,
@@ -155,7 +156,7 @@ class ChannelEngine {
155
156
  message: reason !== null && reason !== void 0 ? reason : 'Channel has been destroyed',
156
157
  });
157
158
  __classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").destroyChannel();
158
- __classPrivateFieldGet(this, _ChannelEngine_users, "f").forEach((_, userId) => this.removeUser(userId));
159
+ __classPrivateFieldGet(this, _ChannelEngine_users, "f").forEach((_, userId) => this.removeUser(userId, true));
159
160
  }
160
161
  /**
161
162
  * @desc Updates a user's assigns
@@ -48,7 +48,7 @@ describe('ChannelEngine', () => {
48
48
  const parentEngine = (0, exports.createParentEngine)();
49
49
  const channelEngine = new channel_1.ChannelEngine('testChannel', parentEngine);
50
50
  expect(() => {
51
- channelEngine.removeUser('test');
51
+ channelEngine.removeUser('test', false);
52
52
  }).toThrow('ChannelEngine: User with id test does not exist in channel testChannel');
53
53
  });
54
54
  it('should update a users assigns', () => {
@@ -163,7 +163,7 @@ describe('ChannelEngine', () => {
163
163
  channelEngine.addUser('test', { test: 1 }, onMessage);
164
164
  expect(channelEngine.size).toEqual(1);
165
165
  expect(channelEngine.getUserData('test')).toBeDefined();
166
- channelEngine.removeUser('test');
166
+ channelEngine.removeUser('test', true);
167
167
  expect(channelEngine.size).toEqual(0);
168
168
  expect(channelEngine.getUserData('test')).not.toBeDefined();
169
169
  });
@@ -181,7 +181,7 @@ describe('ChannelEngine', () => {
181
181
  test2: { test: 2 },
182
182
  });
183
183
  onMessage.mockClear();
184
- channelEngine.removeUser('test');
184
+ channelEngine.removeUser('test', true);
185
185
  expect((_b = channelEngine.presenceEngine) === null || _b === void 0 ? void 0 : _b.getPresence()).toEqual({
186
186
  test2: { test: 2 },
187
187
  });
@@ -216,7 +216,7 @@ _Endpoint_middleware = new WeakMap(), _Endpoint_channels = new WeakMap(), _Endpo
216
216
  break;
217
217
  case pondsocket_common_1.ClientActions.LEAVE_CHANNEL:
218
218
  __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_execute).call(this, message.channelName, (channel) => {
219
- channel.removeUser(cache.clientId);
219
+ channel.removeUser(cache.clientId, true);
220
220
  });
221
221
  break;
222
222
  case pondsocket_common_1.ClientActions.BROADCAST:
package/lobby/lobby.js CHANGED
@@ -82,7 +82,7 @@ class LobbyEngine {
82
82
  */
83
83
  removeUser(clientId) {
84
84
  __classPrivateFieldGet(this, _LobbyEngine_channels, "f").forEach((channel) => {
85
- channel.removeUser(clientId);
85
+ channel.removeUser(clientId, true);
86
86
  });
87
87
  }
88
88
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.138",
3
+ "version": "0.1.141",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
package/types.d.ts CHANGED
@@ -14,14 +14,14 @@ import { WebSocketServer } from 'ws';
14
14
 
15
15
  export * from '@eleven-am/pondsocket-common';
16
16
 
17
- interface LeaveEvent<EventTypes extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
17
+ export interface LeaveEvent<EventTypes extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
18
18
  user: UserData<PresenceType, AssignType>;
19
19
  channel: Channel<EventTypes, PresenceType, AssignType>;
20
20
  }
21
21
 
22
- type LeaveCallback<EventTypes extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> = (event: LeaveEvent<EventTypes, PresenceType, AssignType>) => void;
22
+ export type LeaveCallback<EventTypes extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> = (event: LeaveEvent<EventTypes, PresenceType, AssignType>) => void;
23
23
 
24
- declare class AbstractRequest<Path extends string, PresenceType extends PondPresence, AssignType extends PondAssigns> {
24
+ export declare class AbstractRequest<Path extends string, PresenceType extends PondPresence, AssignType extends PondAssigns> {
25
25
  event: PondEvent<Path>;
26
26
 
27
27
  channelName: string;
@@ -31,13 +31,13 @@ declare class AbstractRequest<Path extends string, PresenceType extends PondPres
31
31
  presence: Record<string, PresenceType>;
32
32
  }
33
33
 
34
- declare class EventRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> extends AbstractRequest<Path, PresenceType, AssignType> {
34
+ export declare class EventRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> extends AbstractRequest<Path, PresenceType, AssignType> {
35
35
  user: UserData<PresenceType, AssignType>;
36
36
 
37
37
  channel: Channel;
38
38
  }
39
39
 
40
- declare class EventResponse<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
40
+ export declare class EventResponse<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
41
41
  /**
42
42
  * @desc Whether the server has responded to the request
43
43
  */
@@ -129,7 +129,7 @@ declare class EventResponse<EventType extends PondEventMap = PondEventMap, Prese
129
129
  closeChannel (reason: string): void;
130
130
  }
131
131
 
132
- declare class Endpoint {
132
+ export declare class Endpoint {
133
133
  /**
134
134
  * @desc Adds a new PondChannel to this path on this endpoint
135
135
  * @param path - The path to add the channel to
@@ -241,7 +241,7 @@ export declare class Channel<EventType extends PondEventMap = PondEventMap, Pres
241
241
  updatePresence (userId: string, presence: PresenceType): void;
242
242
  }
243
243
 
244
- declare class JoinRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> extends AbstractRequest<Path, PresenceType, AssignType> {
244
+ export declare class JoinRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> extends AbstractRequest<Path, PresenceType, AssignType> {
245
245
  joinParams: JoinParams;
246
246
 
247
247
  user: UserData<PresenceType, AssignType>;
@@ -249,7 +249,7 @@ declare class JoinRequest<Path extends string, PresenceType extends PondPresence
249
249
  channel: Channel;
250
250
  }
251
251
 
252
- declare class JoinResponse<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
252
+ export declare class JoinResponse<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
253
253
  /**
254
254
  * @desc Whether the server has responded to the request
255
255
  */
@@ -305,7 +305,7 @@ declare class JoinResponse<EventType extends PondEventMap = PondEventMap, Presen
305
305
  trackPresence (presence: PresenceType): JoinResponse;
306
306
  }
307
307
 
308
- declare class ConnectionResponse {
308
+ export declare class ConnectionResponse {
309
309
  /**
310
310
  * @desc Whether the server has responded to the request
311
311
  */