@devanachat/sdk 0.12.0 → 0.14.0

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +104 -12
  2. package/README.md +13 -5
  3. package/build/index.cjs.js +345 -43
  4. package/build/index.cjs.js.map +1 -1
  5. package/build/index.mjs +345 -44
  6. package/build/index.mjs.map +1 -1
  7. package/build/index.umd.js +1 -1
  8. package/build/index.umd.js.map +1 -1
  9. package/build/types/AbstractChatClient.d.ts +16 -1
  10. package/build/types/Permissions.d.ts +34 -0
  11. package/build/types/WebSocketChatClient.d.ts +29 -2
  12. package/build/types/index.d.ts +4 -3
  13. package/build/types/protocol/index.d.ts +21 -2
  14. package/build/types/protocol/schemes/Call.d.ts +35 -0
  15. package/build/types/protocol/schemes/IncomingCall.d.ts +6 -0
  16. package/build/types/protocol/schemes/Message.d.ts +3 -1
  17. package/build/types/protocol/schemes/MessageCall.d.ts +9 -0
  18. package/build/types/protocol/schemes/Room.d.ts +2 -0
  19. package/build/types/protocol/schemes/RoomCall.d.ts +6 -0
  20. package/build/types/protocol/schemes/UserData.d.ts +1 -0
  21. package/build/types/protocol/schemes/UserState.d.ts +4 -0
  22. package/build/types/protocol/schemes/commands/CreateMessage.d.ts +2 -0
  23. package/build/types/protocol/schemes/commands/DeclineCall.d.ts +3 -0
  24. package/build/types/protocol/schemes/commands/GetCallMembers.d.ts +5 -0
  25. package/build/types/protocol/schemes/commands/InviteToCall.d.ts +5 -0
  26. package/build/types/protocol/schemes/commands/JoinCall.d.ts +4 -0
  27. package/build/types/protocol/schemes/commands/KickCallMember.d.ts +4 -0
  28. package/build/types/protocol/schemes/commands/MuteCallMember.d.ts +4 -0
  29. package/build/types/protocol/schemes/commands/SetPermissionOverwrites.d.ts +1 -0
  30. package/build/types/protocol/schemes/commands/SetSessionData.d.ts +1 -0
  31. package/build/types/protocol/schemes/commands/SetUserData.d.ts +1 -0
  32. package/build/types/protocol/schemes/commands/UpdateCallMember.d.ts +7 -0
  33. package/build/types/protocol/schemes/commands/UpdateRoom.d.ts +2 -0
  34. package/build/types/protocol/schemes/events/Bye.d.ts +1 -0
  35. package/build/types/protocol/schemes/events/CallJoined.d.ts +7 -0
  36. package/build/types/protocol/schemes/events/CallMemberJoined.d.ts +5 -0
  37. package/build/types/protocol/schemes/events/CallMemberLeft.d.ts +4 -0
  38. package/build/types/protocol/schemes/events/CallMemberUpdated.d.ts +6 -0
  39. package/build/types/protocol/schemes/events/CallMembers.d.ts +5 -0
  40. package/build/types/protocol/schemes/events/CallUpdated.d.ts +5 -0
  41. package/build/types/protocol/schemes/events/CallVideoLimitReached.d.ts +4 -0
  42. package/build/types/protocol/schemes/events/Error.d.ts +6 -0
  43. package/build/types/protocol/schemes/events/IncomingCallUpdated.d.ts +5 -0
  44. package/build/types/state-tracker/CallsManager.d.ts +74 -0
  45. package/build/types/state-tracker/ChatStateTracker.d.ts +5 -0
  46. package/build/types/state-tracker/StateSnapshot.d.ts +1 -1
  47. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,90 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.14.0]
10
+
11
+ ### Added
12
+
13
+ - Voice and video calls in rooms. The protocol: commands `JoinCall` (answered with `CallJoined`: the media server URL,
14
+ token and quality), `DeclineCall`, `InviteToCall`, `MuteCallMember` and `KickCallMember`; events
15
+ `CallUpdated` (a call started, changed or ended), `CallMemberJoined`, `CallMemberUpdated` and `CallMemberLeft`
16
+ (a change of a single member), `IncomingCallUpdated` (an `IncomingCall` - the call and its caller - started or
17
+ stopped ringing at you) and `CallVideoLimitReached` (the server took your camera or screen share away because of
18
+ the video limit of the call); `Session.state.calls` with the ongoing calls, each with its `location`, and
19
+ `Session.state.incomingCalls` with the calls ringing at you; the `Call` message type
20
+ with `Message.call` (status, the `mode` the call had, duration, `memberCount` and some of the members in
21
+ `partialMembers`) and the
22
+ `CallJoin` / `CallLeave` messages in the call's topic; the `GetCallMembers` command answered with `CallMembers`
23
+ (`CallsManager.getMembers(messageId, {limit, offset})`) for all the members of the call of a message;
24
+ `SessionPush.voipToken` for the iOS PushKit token; error codes `CallsUnavailable`, `CallFull`, `CallNotFound` and
25
+ `TooManyCallInvitees`. The SDK does the signalling only - connect to the media server with the access yourself.
26
+ - `ChatStateTracker.calls` (`CallsManager`): `get()` - the ongoing calls in your rooms keyed by room id, `getRinging()`
27
+ - the calls ringing at you, and `join`, `decline`, `invite`, `muteMember` and `kickMember`. The member events
28
+ replace the tracked call with a new object, and a `getRinging()` entry is replaced with a new object when its call
29
+ changes. `CallUpdated` of a room you are not in is ignored. Calls are not part of the state snapshot.
30
+ - Call modes, set per room in `Room.call` / `UpdateRoom.call` (`RoomCall`: `mode`, `userLimit`, `turnSeconds`):
31
+ `Conversation` (everyone speaks), `Stage` (moderators bring listeners who raised a hand on the stage) and `Queue`
32
+ (members raise a hand to take turns). `Call.mode`, `Call.turn` (who speaks until when, and by when they have to turn
33
+ the microphone on, or the turn ends - null once they did), `CallMember.handRaisedAt` (`CallsManager.getQueue(call)`
34
+ orders the raised hands), `CallMemberFlag` (`Camera`, `ScreenShare`, `Speaker`, `RaiseBlocked`), the optional title of a call
35
+ started with `JoinCall`, the `UpdateCallMember` command (`CallsManager.updateMember`: raising and lowering a hand,
36
+ moving on and off the stage, which also ends or skips a turn) and the `CallMode` error code for an operation the
37
+ mode of the call does not allow.
38
+ - `UserData.acceptCalls` (true by default) and `SetUserData.acceptCalls` (null or left out keeps it): with it off,
39
+ `JoinCall` starting a call in a one-to-one private room with you fails with the new `CallsNotAccepted` error code.
40
+ - `Call.autoEndAt`: when the server ends the call because nobody is left to talk with (null while it is not going to).
41
+ - Permissions `JoinCalls` (2^30), `ShareVideo` (2^31), `InviteToCall` (2^32) and `ManageCalls` (2^33). The last
42
+ three lie beyond the 31 bits JavaScript bitwise operators handle, so check and build permission masks with the
43
+ new `Permissions.has(mask, name)`, `Permissions.union(...masks)` and `Permissions.subtract(mask, removed)` instead
44
+ of `&`, `|` and `~`.
45
+ - `SetPermissionOverwrites.knownPermissions`: the mask of the permissions the client knows. The server changes only
46
+ these bits of the overwrites; without it, it keeps the bits from 2^30 up, so an older client does not clear the call
47
+ permissions it cannot show. `Permissions.getKnownMask()` gives the mask of all the permissions of the SDK for it.
48
+
49
+ ### Changed
50
+
51
+ - `Room.call` is required, as are `UserState.calls` and `UserState.incomingCalls` - the server always sends them.
52
+ `MessageType` has the new `Call`, `CallJoin` and `CallLeave` values, so a `switch` over it may need new cases.
53
+ - State snapshots: version 4 (rooms with `call`); older snapshots are rejected.
54
+
55
+ ### Fixed
56
+
57
+ - `PermissionsManager` computes permissions beyond the 31st bit correctly.
58
+
59
+ ## [0.13.0]
60
+
61
+ ### Added
62
+
63
+ - `CreateMessage.allowedMentions` (`MessageMentions`): limits the users and roles the message mentions - empty lists
64
+ mention no one.
65
+
66
+ ### Changed
67
+
68
+ - Reconnecting spreads the clients dropped together: a retry waits a random time between 0 and the backoff delay
69
+ (it used to be 50-100% of it). After a closure by the server (close code 1001, 1012 or 1013, or after a `Bye`) the backoff
70
+ starts at `reconnect.serverCloseMinDelayMs` (5 s by default) instead of `reconnect.minDelayMs` (1 s). The backoff
71
+ starts over once a connection has stayed authenticated for `reconnect.stableConnectionMs` (30 s by default),
72
+ not as soon as it authenticates.
73
+ - `connectingTimeoutMs` (10 s) limits only the time until the socket opens. An open socket waits for `Session` up to
74
+ the new `sessionTimeoutMs` (60 s by default), so a client the server holds in its queue during a reconnect storm is
75
+ no longer dropped and sent back to the end of it.
76
+
77
+ ### Fixed
78
+
79
+ - A `Bye` with the `Service` reason (the server shutting down) is followed by a reconnect even when the server closes
80
+ the connection with code 1000; the client used to stop. `Bye` is emitted first, then `disconnect` with `true`; a
81
+ `connect()` still waiting for `Session` stays pending for the retry. Other `Bye` reasons behave as before.
82
+ - `Bye.retryAfterMs`: when the server sends it, the next reconnect waits that long instead of the backoff delay, without
83
+ further jitter; values that are not positive finite numbers are ignored and longer ones are capped at 60 s.
84
+ - A `Bye` with the `ServiceUnavailableException` error (the server too busy to take the connection) is followed by a
85
+ reconnect, like a `Service` one, instead of being treated as a rejected token: no `error` event, a pending
86
+ `connect()` stays pending for the retry. `AuthenticationException` still stops reconnecting.
87
+ - `disconnect()` called by a listener of the message being received (e.g. of `Session`, to refuse the protocol
88
+ version, or of `Bye`) is final: the client no longer authenticates the closed connection, emits `connect` or
89
+ schedules a retry afterwards, and emits `disconnect` once.
90
+
91
+ ## [0.12.0]
92
+
9
93
  ### Added
10
94
 
11
95
  - Editing messages: the `UpdateMessage` command (`{messageId, content?, embed?}` - a field left out stays, `embed: null`
@@ -39,6 +123,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
39
123
  `FoundGif` with its post `url`, size, poster and MP4/WebM sources; pass `next` as `position` for the following page),
40
124
  and the `GetGifCategories` command (`{locale?}`) resolving with `GifCategories` (`{categories}`, each `GifCategory`
41
125
  with the search `term`, its English `name` and an `imageUrl`). Available when the server runs GIF search.
126
+ - Reactions of sticky messages: `RoomsManager.getStickyMyReactions(location, messageId)` returns the reactions of the
127
+ connected user on sticky messages (`MessageUserReactions`, keyed by message id) - fetched once per message with `GetMessages` (`around`,
128
+ `limit: 1`, `includeMyReactions`), as a sticky message comes with its topic, then kept up to date with `Reacted`.
129
+ The topics tracked by `RoomsManager` follow the reaction counters of their sticky message with `ReactionUpdated`.
130
+
131
+ ### Changed
132
+
133
+ - **Breaking:** `Messages.myReactions` is a list of `MessageUserReactions` (`{messageId, reactions}`) instead of a map
134
+ keyed by message id, so this version needs a server sending the list; `TopicHistoryWindow.myReactions` keeps the map.
135
+ - **Breaking:** the `RedactMessages` permission is `ManageMessages` (the same bit, `1 << 19`; the `RedactMessages`
136
+ command keeps its name). Besides deleting messages it lets `UpdateMessage` with `embed: null` hide a preview
137
+ generated by the server in any message.
138
+ - State snapshots: version 3 (with the replied messages of the saved histories); older snapshots are rejected.
139
+ - `React` with a reaction the user already has fails with `ReactionExistsAlreadyException`; `Unreact` of a reaction the
140
+ user does not have resolves with `Ok`. Both used to get no answer.
141
+
142
+ ## [0.11.0]
143
+
144
+ ### Added
145
+
42
146
  - Typing notifications: the `Type` command and the `Typing` event (`{location, userId}`), for rooms other than
43
147
  `ClassicText`. `RoomsManager.typing.get(roomId, topicId)` returns the ids of the users typing in a topic, tracked from
44
148
  the first call, each leaving `TYPING_TIMEOUT_MS` after their last notification or with their message.
@@ -46,10 +150,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
46
150
  - Sticky messages: `Topic.stickyMessage`, `CreateMessage.sticky`, `NewMessage.sticky`, `UpdateTopic.stickyMessageId`
47
151
  (a message id sticks it, `null` unsticks it) and the `ManagePins` permission. The topics tracked by `RoomsManager`
48
152
  take a new sticky message from `NewMessage` and drop it when it is redacted.
49
- - Reactions of sticky messages: `RoomsManager.getStickyMyReactions(location, messageId)` returns the reactions of the
50
- connected user on sticky messages (`MessageUserReactions`, keyed by message id) - fetched once per message with `GetMessages` (`around`,
51
- `limit: 1`, `includeMyReactions`), as a sticky message comes with its topic, then kept up to date with `Reacted`.
52
- The topics tracked by `RoomsManager` follow the reaction counters of their sticky message with `ReactionUpdated`.
53
153
  - Role icons: `Role.icon` (`RoleIcon` - an emoji or an emoticon of the space, `{type, value}` like a reaction) and
54
154
  `UpdateRole.icon` (an icon sets it, `null` removes it).
55
155
  - Guests: `Space.guestRole` and `UpdateSpace.guestRole` (a role of the space given to temporary accounts when they
@@ -61,14 +161,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
61
161
 
62
162
  ### Changed
63
163
 
64
- - **Breaking:** `Messages.myReactions` is a list of `MessageUserReactions` (`{messageId, reactions}`) instead of a map
65
- keyed by message id, so this version needs a server sending the list; `TopicHistoryWindow.myReactions` keeps the map.
66
- - **Breaking:** the `RedactMessages` permission is `ManageMessages` (the same bit, `1 << 19`; the `RedactMessages`
67
- command keeps its name). Besides deleting messages it lets `UpdateMessage` with `embed: null` hide a preview
68
- generated by the server in any message.
69
- - State snapshots: version 3 (with the replied messages of the saved histories); older snapshots are rejected.
70
- - `React` with a reaction the user already has fails with `ReactionExistsAlreadyException`; `Unreact` of a reaction the
71
- user does not have resolves with `Ok`. Both used to get no answer.
72
164
  - `PermissionsManager.calculatePermissions` follows the server: on every layer the space default role (everyone) is
73
165
  applied before the other roles, so a deny of another role overrides what everyone allows. An allow of any role still
74
166
  wins over a deny of another one.
package/README.md CHANGED
@@ -161,19 +161,27 @@ client.on('NewMessage', async ({message}) => {
161
161
  ## Connection maintenance
162
162
 
163
163
  `WebSocketChatClient` keeps the connection alive: after any loss (error, connecting timeout, missing pong, closure with
164
- a code other than 1000) it reconnects indefinitely, with an exponential backoff between attempts. The `disconnect` event
164
+ a code other than 1000) it reconnects indefinitely, waiting a random time up to an exponentially growing delay between
165
+ attempts. The backoff starts higher when the server closed the connection than after a network drop, and starts over
166
+ once a connection has been stable for a while. The `disconnect` event
165
167
  tells whether a retry follows. A pending `connect()` promise resolves once an attempt authenticates, and is rejected by
166
168
  `disconnect()`, which also stops reconnecting. An invalid token (`Bye` with `AuthenticationException`) rejects `connect()`
167
- with the `Bye` data, emits an `error` event and stops reconnecting as well.
169
+ with the `Bye` data, emits an `error` event and stops reconnecting as well. A `Bye` with the `Service` reason (the server
170
+ going down) or with `ServiceUnavailableException` (the server overloaded) is always followed by a retry, emitted as
171
+ `Bye` and then `disconnect` with `true`, whatever the close code.
172
+ When a `Bye` carries `retryAfterMs`, the next retry waits that long (at most 60 s) instead of the backoff delay.
168
173
 
169
174
  ```ts
170
175
  const client = new WebSocketChatClient({
171
176
  url: 'wss://s1.devana.pl:1600/ws',
172
177
  token: 'your-access-token',
173
- connectingTimeoutMs: 10000, // Per attempt (default)
178
+ connectingTimeoutMs: 10000, // Until the socket opens (default)
179
+ sessionTimeoutMs: 60000, // Until Session arrives on an open socket; the server may queue connections (default)
174
180
  reconnect: {
175
- minDelayMs: 1000, // Delay before the first retry, doubled on every next one (default)
176
- maxDelayMs: 30000, // Maximum delay between retries (default)
181
+ minDelayMs: 1000, // Limit of the first delay after a lost connection, doubled on every next one (default)
182
+ serverCloseMinDelayMs: 5000, // The same after a closure by the server: 1001, 1012, 1013 or a Bye (default)
183
+ maxDelayMs: 30000, // Maximum delay between retries; a higher minimum delay wins over it (default)
184
+ stableConnectionMs: 30000, // A connection lasting this long starts the backoff over (default)
177
185
  },
178
186
  ping: {
179
187
  noActivityTimeoutMs: 15000, // Send a ping after this much silence (default)