polfan-server-js-client 0.2.65 → 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="4990000" />
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 () {