@eleven-am/pondsocket-client 0.0.20 → 0.0.22

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/browser/client.js CHANGED
@@ -34,7 +34,7 @@ class PondClient {
34
34
  address.protocol = protocol;
35
35
  }
36
36
  this._address = address;
37
- __classPrivateFieldSet(this, _PondClient_channels, {}, "f");
37
+ __classPrivateFieldSet(this, _PondClient_channels, new Map(), "f");
38
38
  this._broadcaster = new pondsocket_common_1.Subject();
39
39
  this._connectionState = new pondsocket_common_1.BehaviorSubject(false);
40
40
  __classPrivateFieldGet(this, _PondClient_instances, "m", _PondClient_init).call(this);
@@ -73,11 +73,10 @@ class PondClient {
73
73
  */
74
74
  disconnect() {
75
75
  var _a;
76
- Object.values(__classPrivateFieldGet(this, _PondClient_channels, "f")).forEach((channel) => channel.leave());
77
76
  this._connectionState.publish(false);
78
77
  this._disconnecting = true;
79
78
  (_a = this._socket) === null || _a === void 0 ? void 0 : _a.close();
80
- __classPrivateFieldSet(this, _PondClient_channels, {}, "f");
79
+ __classPrivateFieldGet(this, _PondClient_channels, "f").clear();
81
80
  }
82
81
  /**
83
82
  * @desc Creates a channel with the given name and params.
@@ -85,13 +84,14 @@ class PondClient {
85
84
  * @param params - The params to send to the server.
86
85
  */
87
86
  createChannel(name, params) {
88
- if (__classPrivateFieldGet(this, _PondClient_channels, "f")[name] && __classPrivateFieldGet(this, _PondClient_channels, "f")[name].channelState !== pondsocket_common_1.ChannelState.CLOSED) {
89
- return __classPrivateFieldGet(this, _PondClient_channels, "f")[name];
87
+ const channel = __classPrivateFieldGet(this, _PondClient_channels, "f").get(name);
88
+ if (channel && channel.channelState !== pondsocket_common_1.ChannelState.CLOSED) {
89
+ return channel;
90
90
  }
91
91
  const publisher = __classPrivateFieldGet(this, _PondClient_instances, "m", _PondClient_createPublisher).call(this);
92
- const channel = new channel_1.Channel(publisher, this._connectionState, name, params || {});
93
- __classPrivateFieldGet(this, _PondClient_channels, "f")[name] = channel;
94
- return channel;
92
+ const newChannel = new channel_1.Channel(publisher, this._connectionState, name, params || {});
93
+ __classPrivateFieldGet(this, _PondClient_channels, "f").set(name, newChannel);
94
+ return newChannel;
95
95
  }
96
96
  /**
97
97
  * @desc Subscribes to the connection state.
@@ -109,8 +109,8 @@ _PondClient_channels = new WeakMap(), _PondClient_instances = new WeakSet(), _Po
109
109
  };
110
110
  }, _PondClient_handleAcknowledge = function _PondClient_handleAcknowledge(message) {
111
111
  var _a;
112
- const channel = (_a = __classPrivateFieldGet(this, _PondClient_channels, "f")[message.channelName]) !== null && _a !== void 0 ? _a : new channel_1.Channel(__classPrivateFieldGet(this, _PondClient_instances, "m", _PondClient_createPublisher).call(this), this._connectionState, message.channelName, {});
113
- __classPrivateFieldGet(this, _PondClient_channels, "f")[message.channelName] = channel;
112
+ const channel = (_a = __classPrivateFieldGet(this, _PondClient_channels, "f").get(message.channelName)) !== null && _a !== void 0 ? _a : new channel_1.Channel(__classPrivateFieldGet(this, _PondClient_instances, "m", _PondClient_createPublisher).call(this), this._connectionState, message.channelName, {});
113
+ __classPrivateFieldGet(this, _PondClient_channels, "f").set(message.channelName, channel);
114
114
  channel.acknowledge(this._broadcaster);
115
115
  }, _PondClient_init = function _PondClient_init() {
116
116
  this._broadcaster.subscribe((message) => {
@@ -87,28 +87,6 @@ describe('PondClient', () => {
87
87
  mockWebSocket.onmessage({ data: JSON.stringify(acknowledgeEvent) });
88
88
  expect(mockCallback).toHaveBeenCalledWith(true);
89
89
  });
90
- test('disconnect method should close the socket and leave all channels', () => {
91
- const mockCallback = jest.fn();
92
- pondClient.onConnectionChange(mockCallback);
93
- pondClient.connect();
94
- const mockWebSocket = pondClient['_socket'];
95
- const acknowledgeEvent = {
96
- event: pondsocket_common_1.Events.CONNECTION,
97
- action: pondsocket_common_1.ServerActions.CONNECT,
98
- channelName: 'exampleChannel',
99
- requestId: '123',
100
- payload: {},
101
- };
102
- mockWebSocket.onmessage({ data: JSON.stringify(acknowledgeEvent) });
103
- expect(mockCallback).toHaveBeenCalledWith(true);
104
- const channel = pondClient.createChannel('exampleChannel');
105
- const spyOnLeave = jest.spyOn(channel, 'leave');
106
- mockCallback.mockClear();
107
- pondClient.disconnect();
108
- expect(mockCallback).toHaveBeenCalledWith(false);
109
- expect(mockWebSocket.close).toHaveBeenCalled();
110
- expect(spyOnLeave).toHaveBeenCalled();
111
- });
112
90
  test('createChannel method should create a new channel or return an existing one', () => {
113
91
  const mockChannel = pondClient.createChannel('exampleChannel');
114
92
  const mockExistingChannel = pondClient.createChannel('exampleChannel');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket-client",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -29,22 +29,22 @@
29
29
  "pipeline": "npm run test && npm run build && npm run push"
30
30
  },
31
31
  "dependencies": {
32
- "@eleven-am/pondsocket-common": "^0.0.20",
33
- "websocket": "^1.0.34"
32
+ "@eleven-am/pondsocket-common": "^0.0.25",
33
+ "websocket": "^1.0.35"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/jest": "^29.5.12",
36
+ "@types/jest": "^29.5.13",
37
37
  "@types/websocket": "^1.0.10",
38
- "@typescript-eslint/eslint-plugin": "^7.1.0",
39
- "eslint-plugin-file-progress": "^1.3.0",
40
- "eslint-plugin-import": "^2.29.1",
38
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
39
+ "eslint-plugin-file-progress": "^1.5.0",
40
+ "eslint-plugin-import": "^2.30.0",
41
41
  "jest": "^29.7.0",
42
- "prettier": "^3.2.5",
43
- "supertest": "^6.3.4",
44
- "ts-jest": "^29.1.2",
42
+ "prettier": "^3.3.3",
43
+ "supertest": "^7.0.0",
44
+ "ts-jest": "^29.2.5",
45
45
  "ts-loader": "^9.5.1",
46
46
  "ts-node": "^10.9.2",
47
- "typescript": "^5.3.3"
47
+ "typescript": "^5.6.2"
48
48
  },
49
49
  "jest": {
50
50
  "moduleFileExtensions": [