@eleven-am/pondsocket 0.1.139 → 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.139",
3
+ "version": "0.1.141",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",