polfan-server-js-client 0.2.64 → 0.2.66

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.
@@ -5,6 +5,7 @@
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
7
  <list default="true" id="831dae43-0da1-47fd-a5f7-33dd5eec2992" name="Changes" comment="Align to custom colors and nicks protocol changes">
8
+ <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
8
9
  <change beforePath="$PROJECT_DIR$/build/index.cjs.js" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.cjs.js" afterDir="false" />
9
10
  <change beforePath="$PROJECT_DIR$/build/index.cjs.js.map" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.cjs.js.map" afterDir="false" />
10
11
  <change beforePath="$PROJECT_DIR$/build/index.umd.js" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.umd.js" afterDir="false" />
@@ -12,6 +13,8 @@
12
13
  <change beforePath="$PROJECT_DIR$/build/types/WebSocketChatClient.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/build/types/WebSocketChatClient.d.ts" afterDir="false" />
13
14
  <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
14
15
  <change beforePath="$PROJECT_DIR$/src/WebSocketChatClient.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/WebSocketChatClient.ts" afterDir="false" />
16
+ <change beforePath="$PROJECT_DIR$/src/state-tracker/MessagesManager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/state-tracker/MessagesManager.ts" afterDir="false" />
17
+ <change beforePath="$PROJECT_DIR$/src/state-tracker/TopicHistoryWindow.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/state-tracker/TopicHistoryWindow.ts" afterDir="false" />
15
18
  </list>
16
19
  <option name="SHOW_DIALOG" value="false" />
17
20
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -163,7 +166,7 @@
163
166
  <workItem from="1764758258935" duration="1127000" />
164
167
  <workItem from="1764792690210" duration="1002000" />
165
168
  <workItem from="1764794428269" duration="595000" />
166
- <workItem from="1764847260499" duration="3270000" />
169
+ <workItem from="1764847260499" duration="12786000" />
167
170
  </task>
168
171
  <task id="LOCAL-00017" summary="New scheme of Bye event">
169
172
  <option name="closed" value="true" />
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # pserv-js-client-library
2
- TypeScript client library to handle connection with Polfan chat service.
2
+ TypeScript client library to handle connection with Devana (new Polfan) chat service.
3
3
 
4
4
  ## How to use?
5
5
 
@@ -22,4 +22,24 @@ TypeScript client library to handle connection with Polfan chat service.
22
22
  console.log("The spaces you are in:", session.spaces);
23
23
  console.log("The version of server you connected to:", session.serverVersion);
24
24
  })();
25
- ```
25
+ ```
26
+
27
+ ## State management
28
+
29
+ The library provides built-in state management for WebSocket client. To enable it, just pass `stateTracking`
30
+ option to the `WebSocketChatClient` constructor:
31
+
32
+ ```js
33
+ const wsClient = new PServ.WebSocketChatClient({
34
+ token: 'your-access-token',
35
+ url: 'wss://pserv-websocket-address',
36
+ stateTracking: true, // Enable state tracking
37
+ });
38
+ ```
39
+
40
+ With state tracking enabled, the client will automatically maintain the current state of rooms, users, and messages,
41
+ by handling incoming events from the server. Reactive data structures are available via `ObservableIndexedObjectCollection`
42
+ objects, which allows you to subscribe to changes.
43
+
44
+ **Important note:** you can cache these objects for the connection lifetime, but you should refetch them after reconnecting,
45
+ because some structures are rebuild from scratch on `Session` event.
@@ -968,9 +968,6 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
968
968
  _this2.tracker = tracker;
969
969
  _this2.internalState.traverseLock = false;
970
970
  if (bindEvents) {
971
- _this2.tracker.client.on('Session', function (ev) {
972
- return _this2.handleSession(ev);
973
- });
974
971
  _this2.tracker.client.on('NewMessage', function (ev) {
975
972
  return _this2.handleNewMessage(ev);
976
973
  });
@@ -1117,19 +1114,6 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
1117
1114
  }
1118
1115
  return handleNewMessage;
1119
1116
  }()
1120
- }, {
1121
- key: "handleSession",
1122
- value: function handleSession(ev) {
1123
- var _this3 = this;
1124
- var rooms = ev.state.rooms;
1125
- if (rooms.find(function (room) {
1126
- return room.id === _this3.roomId;
1127
- })) {
1128
- void this.resetToLatest();
1129
- } else {
1130
- this.deleteAll();
1131
- }
1132
- }
1133
1117
  }, {
1134
1118
  key: "fetchItemsAfter",
1135
1119
  value: function () {
@@ -4314,7 +4298,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4314
4298
  return WebSocketChatClient_regenerator().w(function (_context) {
4315
4299
  while (1) switch (_context.n) {
4316
4300
  case 0:
4317
- if (!(this.isReadyToSendWsState() || this.isPendingReadyWsState())) {
4301
+ if (!(this.isOpenWsState() || this.isConnectingWsState())) {
4318
4302
  _context.n = 1;
4319
4303
  break;
4320
4304
  }
@@ -4365,7 +4349,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4365
4349
  case 0:
4366
4350
  envelope = this.createEnvelope(commandType, commandData);
4367
4351
  promise = this.createPromiseFromCommandEnvelope(envelope);
4368
- if (!this.isPendingReadyWsState()) {
4352
+ if (!(this.isConnectingWsState() || !this.authenticated && this.isOpenWsState())) {
4369
4353
  _context2.n = 1;
4370
4354
  break;
4371
4355
  }
@@ -4385,17 +4369,17 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4385
4369
  }, {
4386
4370
  key: "isReady",
4387
4371
  get: function get() {
4388
- return this.isReadyToSendWsState();
4372
+ return this.isOpenWsState() && this.authenticated;
4389
4373
  }
4390
4374
  }, {
4391
4375
  key: "sendEnvelope",
4392
4376
  value: function sendEnvelope(envelope) {
4393
4377
  var _this$ws$readyState, _this$ws2;
4394
- if (this.isReadyToSendWsState()) {
4378
+ if (this.isReady) {
4395
4379
  this.ws.send(JSON.stringify(envelope));
4396
4380
  return;
4397
4381
  }
4398
- this.handleEnvelopeSendError(envelope, new Error("Cannot send; invalid websocket state=".concat((_this$ws$readyState = (_this$ws2 = this.ws) === null || _this$ws2 === void 0 ? void 0 : _this$ws2.readyState) !== null && _this$ws$readyState !== void 0 ? _this$ws$readyState : '[no connection]')));
4382
+ this.handleEnvelopeSendError(envelope, new Error("Cannot send - client is not ready (state=".concat((_this$ws$readyState = (_this$ws2 = this.ws) === null || _this$ws2 === void 0 ? void 0 : _this$ws2.readyState) !== null && _this$ws$readyState !== void 0 ? _this$ws$readyState : '[no connection]', "; authenticated=").concat(this.authenticated, ")")));
4399
4383
  }
4400
4384
  }, {
4401
4385
  key: "onMessage",
@@ -4455,14 +4439,14 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4455
4439
  this.emit(this.Event.error, new Error('Connection timeout'));
4456
4440
  }
4457
4441
  }, {
4458
- key: "isPendingReadyWsState",
4459
- value: function isPendingReadyWsState() {
4460
- return this.ws && this.ws.readyState === this.ws.CONNECTING || !this.authenticated;
4442
+ key: "isConnectingWsState",
4443
+ value: function isConnectingWsState() {
4444
+ return this.ws && this.ws.readyState === this.ws.CONNECTING;
4461
4445
  }
4462
4446
  }, {
4463
- key: "isReadyToSendWsState",
4464
- value: function isReadyToSendWsState() {
4465
- return this.ws && this.ws.readyState === this.ws.OPEN && this.authenticated;
4447
+ key: "isOpenWsState",
4448
+ value: function isOpenWsState() {
4449
+ return this.ws && this.ws.readyState === this.ws.OPEN;
4466
4450
  }
4467
4451
  }]);
4468
4452
  }(AbstractChatClient);