Skip to content

Commit 84faabe

Browse files
authored
Merge pull request #352 from ably/chat-disposal-methods
chat: add disposal spec
2 parents df88dd3 + 32dcbe3 commit 84faabe

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

textile/chat-features.textile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ h2(#initialization). Initialization
4444
** @(CHA-IN1c)@ SDK authors must ensure that they have registered the agents used by @CHA-IN1b@ in the common repository, per "@RSC7d5@":../features#RSC7d5.
4545
** @(CHA-IN1d)@ @[Testable]@ The chat client must use the wrapper SDK proxy client created in @CHA-IN1a@ as the realtime client on which it performs all subsequent actions (for example, fetching channels or calling @#request@).
4646

47+
h2(#client). Chat Client
48+
49+
** @(CHA-CL1)@ @[Testable]@ The @ChatClient@ provides a @dispose@ method to clean up all resources and prepare the client for garbage collection.
50+
*** @(CHA-CL1a)@ @[Testable]@ When @dispose@ is called on a @ChatClient@, it must first dispose of all rooms. This will release all rooms currently in use.
51+
*** @(CHA-CL1b)@ @[Testable]@ After disposing of rooms, the @ChatClient@ must dispose of the connection instance.
52+
*** @(CHA-CL1c)@ This operation is naturally asynchronous, however many languages use synchronous destructor sequences. Therefore each language should implement whatever is most idiomatic, and the exact implementation details are left up to each individual SDK.
53+
4754
h2(#rooms). Rooms
4855

4956
h3(#rooms-general). General Information
@@ -253,6 +260,7 @@ Each chat room can be configured individually, allowing options to be passed as
253260
* @(CHA-RC1)@ Chat Rooms are singleton objects with respect to the Chat Client on which they are created.
254261
** @(CHA-RC1a)@ This specification point has been removed. It was superseded by CHA-RC1f.
255262
** @(CHA-RC1f)@ @[Testable]@ Requesting a room from the Chat Client shall return a future, that eventually resolves to an instance of a room with the provided id and (optional) options.
263+
*** @(CHA-RC1f7)@ @[Testable]@ If the @Rooms@ instance has been disposed (following a call to @dispose@), attempting to get a room must throw an error with code @40000@.
256264
*** @(CHA-RC1f1)@ @[Testable]@ If the room name exists in the room map, but the room has been requested with different options, then an @ErrorInfo@ with the @BadRequest@ error code from the "chat-specific error codes":#error-codes and a @statusCode@ of 400 shall be thrown.
257265
*** @(CHA-RC1f2)@ @[Testable]@ If the room name exists in the room map, and it is requested with the same options, then the same instance of the room must be reused.
258266
*** @(CHA-RC1f3)@ @[Testable]@ If no @CHA-RC1g@ release operation is in progress, a new room instance shall be created, added to the room map and returned as the future value.
@@ -270,6 +278,7 @@ Each chat room can be configured individually, allowing options to be passed as
270278
*** @(CHA-RC1g3)@ @[Testable]@ If the room does not exist in the room map, and a release operation is already in progress, then the associated future will be returned.
271279
*** @(CHA-RC1g4)@ @[Testable]@ If a release operation is already in progress, any pending @CHA-RC1f@ future shall be rejected / throw an error. The error must use the @RoomReleasedBeforeOperationCompleted@ error code from the "chat-specific error codes":#error-codes and a @statusCode@ of 400. The room shall be removed from the room map and the operation must return the future associated with the previous operation.
272280
*** @(CHA-RC1g5)@ @[Testable]@ The room is removed from the room map and a @CHA-RL3@ release operation is initiated for the room object. A future is returned which resolves when the release operation completes.
281+
*** @(CHA-RC1g6)@ @[Testable]@ Once the @CHA-RL3@ release operation completes, each individual feature must be cleaned up for garbage collection via its individual @dispose@ method.
273282
* @(CHA-RC5)@ @[Testable]@ All chat feature properties (e.g. @room.messages@) are enabled by default. The specific behaviour of each feature is controlled by its respective room options @CHA-RC2@.
274283
* @(CHA-RC2)@ Chat rooms are configurable, so as to enable or disable certain functionality. When requesting a room, options as to what functionality should be enabled/disabled, can be provided (@RoomOptions@).
275284
** @(CHA-RC2a)@ @[Testable]@ If a room is requested with invalid configuration, for example: a negative typing timeout, an @ErrorInfo@ with code @40001@ must be thrown.
@@ -289,6 +298,16 @@ Each chat room can be configured individually, allowing options to be passed as
289298
** @(CHA-RC4a)@ @[Testable]@ Where room options have not been provided, the client shall provide defaults.
290299
** @(CHA-RC4b)@ @[Testable]@ Where a partial room options have been provided, the client shall deep-merge the provided values with the defaults.
291300

301+
h2(#roos-disposal). Rooms Disposal
302+
303+
Rooms in the Chat SDK are a complex type that register many different listeners and consume many different events. Therefore, there must be methods available to clean up any listeners to allow for garbage collection.
304+
305+
** @(CHA-RD1)@ @[Testable]@ The @Rooms@ map / manager must offer an internal API for disposal, that must prepare the rooms manager for garbage collection and release all managed rooms.
306+
*** @(CHA-RD1a)@ @[Testable]@ When disposal is called, it must mark the instance as disposed to prevent future room operations.
307+
*** @(CHA-RD1b)@ @[Testable]@ If no rooms exist when @dispose@ is called, the method must complete successfully without error.
308+
*** @(CHA-RD1c)@ @[Testable]@ If rooms exist in the map, the procedure must release all rooms currently in the rooms map concurrently.
309+
*** @(CHA-RD1d)@ @[Testable]@ The procedure must wait for all room release operations to complete before resolving.
310+
292311
h2(#messages). Messages
293312

294313
Messages are the quintessential component of a chat room - the purpose of chat is for users to talk to each other!
@@ -381,6 +400,7 @@ Broadly speaking, messages are published via REST calls to the Chat HTTP API and
381400
** @(CHA-M11e)@ @[Testable]@ For @MessageReactionSummaryEvent@, the method must verify that the @summary.messageSerial@ in the event matches the message's own serial. If they don't match, an error with code @40000@ and status code @400@ must be thrown.
382401
** @(CHA-M11f)@ @[Testable]@ For @MessageReactionSummaryEvent@, the method must return a new @Message@ instance (deep copy) with the updated reactions, preserving all other properties of the original message.
383402
** @(CHA-M11g)@ @[Testable]@ For @MessageReactionSummaryEvent@, the method must deep-copy the reactions from the event before applying them to the returned message instance.
403+
* @(CHA-M12)@ @[Testable]@ The @Messages@ instance must provide an internal disposal mechanism, that removes all user-provided listeners, and un-registers any internal listeners that have been associated with the Realtime channel.
384404

385405
h2(#messageReactions). Message Reactions
386406

@@ -440,6 +460,8 @@ Users can add reactions to messages, such as thumbs-up or heart emojis. Summarie
440460

441461
* @(CHA-MR10)@ This specification point has been replaced by @CHA-RC3d@.
442462

463+
* @(CHA-MR12)@ @[Testable]@ The @MessageReactions@ instance must provide an internal disposal mechanism, that removes all user-provided listeners, and un-registers any internal listeners that have been associated with the Realtime channel.
464+
443465
h2(#reactions). Ephemeral Room Reactions
444466

445467
Ephemeral room reactions are one-time events that are sent to the room, such as thumbs-up or heart emojis. They are supposed to capture the current emotions in the room (e.g. everyone spamming the :tada: emoji when a team scores the winning goal).
@@ -469,6 +491,7 @@ All ephemeral room reactions are handled over the Realtime connection.
469491
*** @(CHA-ER4e3)@ @[Testable]@ The clientId field shall be an empty string.
470492
*** @(CHA-ER4e4)@ @[Testable]@ Timestamp fields shall be the current timestamp.
471493
* @(CHA-ER5)@ This specification point has been removed. It was valid up until the single-channel migration.
494+
* @(CHA-ER6)@ @[Testable]@ The @RoomReactions@ instance must provide an internal disposal mechanism, that removes all user-provided listeners, and un-registers any internal listeners that have been associated with the Realtime channel.
472495

473496
h2(#presence). Online Status (Presence)
474497

@@ -527,6 +550,7 @@ Presence allows chat room users to indicate to others that they're online, as we
527550
** @(CHA-PR9c)@ The option @presence.enableEvents@ controls whether or not the client should receive presence events from the server. @CHA-RC3d1@ describes how to implement this.
528551
*** @(CHA-PR9c1)@ @[Testable]@ This option defaults to @true@.
529552
*** @(CHA-PR9c2)@ This specification point has been replaced by @CHA-RC3d1@.
553+
* @(CHA-PR11)@ @[Testable]@ The @Presence@ instance must provide an internal disposal mechanism, that removes all user-provided listeners, and un-registers any internal listeners that have been associated with the Realtime channel.
530554

531555
h2(#typing). Typing Indicators
532556

@@ -588,6 +612,7 @@ For the purpose of this section, an @ephemeral message@ is understood to mean a
588612
** @(CHA-T14b)@ @[Testable]@ Once the lock is acquired, if another call is made to either function, the second call shall be queued and wait until it can acquire the lock before executing.
589613
*** @(CHA-T14b1)@ @[Testable]@ During this time, each new subsequent call to either function shall abort the previously queued call, this should be registered as a successful no-op to the caller. In doing so, there shall only ever be one pending call while the mutex is held, thus the most recent call shall "win" and execute once the mutex is released.
590614
*** @(CHA-T14b2)@ @[Testable]@ If an error occurs while the lock is held, the mutex shall be released and the error shall be thrown to the caller.
615+
* @(CHA-T17)@ @[Testable]@ The @Messages@ instance must provide an internal disposal mechanism, that removes all user-provided listeners, and un-registers any internal listeners that have been associated with the Realtime channel. Any timeouts or timers associated with typing heartbeats must also be cancelled.
591616

592617
h2(#occupancy). Occupancy
593618

@@ -616,6 +641,7 @@ the overhead of having everyone in presence.
616641
** @(CHA-O7a)@ @[Testable]@ The @current@ method should return the latest occupancy numbers received over the realtime connection in a @[meta]occupancy@ event.
617642
** @(CHA-O7b)@ @[Testable]@ If no realtime events have been received yet, @current()@ returns undefined/null.
618643
** @(CHA-O7c)@ @[Testable]@ If occupancy events are not enabled via @RoomOptions.occupancy.enableEvents@, @current()@ throws an error with code 40000.
644+
* @(CHA-O8)@ @[Testable]@ The @Occupancy@ instance must provide an internal disposal mechanism, that removes all user-provided listeners, and un-registers any internal listeners that have been associated with the Realtime channel.
619645

620646
h2(#rest-api). Chat HTTP REST API
621647

0 commit comments

Comments
 (0)