From bbfe712c68c8fe7f4d90ba0433da2050c08fd96c Mon Sep 17 00:00:00 2001 From: Umair Date: Fri, 22 Nov 2024 14:23:24 +0000 Subject: [PATCH 01/10] Updates the Chat setup page to include setup instructions for chat-swift --- content/chat/setup.textile | 106 +++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 27 deletions(-) diff --git a/content/chat/setup.textile b/content/chat/setup.textile index 27cf84318e..d847254bcd 100644 --- a/content/chat/setup.textile +++ b/content/chat/setup.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- Use these instructions to install, authenticate and instantiate the Chat SDK. @@ -43,28 +44,29 @@ h2(#install). Install The Chat SDK is built on top of the Ably Pub/Sub SDK and uses that to establish a connection with Ably. -Both SDKs are available as NPM modules and via CDN. - -h3(#npm). NPM - -Install the Pub/Sub SDK and the Chat SDK: - -```[sh] -npm install @ably/chat -``` - -Import the SDKs into your project: - -```[javascript] -import * as Ably from 'ably'; -import { ChatClient } from '@ably/chat'; -``` +blang[javascript,react]. + h3(#npm). NPM + + Install the Pub/Sub SDK and the Chat SDK: + + ```[sh] + npm install @ably/chat + ``` + + Import the SDKs into your project: + + ```[javascript] + import * as Ably from 'ably'; + import ChatClient from '@ably/chat'; + ``` + + ```[react] + import * as Ably from 'ably'; + import ChatClient from '@ably/chat'; + import { ChatClientProvider } from '@ably/chat/react'; + ``` -```[react] -import * as Ably from 'ably'; -import { ChatClient } from '@ably/chat'; -import { ChatClientProvider } from '@ably/chat/react'; -``` +blang[swift]. blang[javascript]. h3(#cdn). CDN @@ -81,7 +83,30 @@ blang[javascript]. ``` -blang[react]. +blang[react,swift]. + +blang[swift]. + h3(#spm). Swift Package Manager + + The SDK is distributed as a Swift Package and can be installed using Xcode or by adding it as a dependency in your package’s @Package.swift@. + + To install the @ably-chat-swift@ package in your Xcode Project: + * Paste @https://github.com/ably/ably-chat-swift@ in the Swift Packages search box (Xcode project → Swift Packages.. . → @+@ button). + * Select the Ably Chat SDK for your target. + + To install the @ably-chat-swift@ package in another Swift Package, add the following to your @Package.swift@: + + ```[swift] + .package(url: "https://github.com/ably/ably-chat-swift", from: "0.1.0"), + ``` + + Import the SDK: + + ```[swift] + import AblyChat + ``` + +blang[javascript,react]. h2(#instantiate). Instantiate a client @@ -90,7 +115,7 @@ Instantiate a realtime client using the Pub/Sub SDK and pass the generated clien blang[react]. Pass the @ChatClient@ into the "@ChatClientProvider@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat_react.ChatClientProvider.html. The @ChatClient@ instance will be available to all child components in your React component tree. -blang[javascript]. +blang[javascript,swift]. ```[javascript] @@ -111,13 +136,27 @@ const App = () => { }; ``` +```[swift] +let realtimeOptions = ARTClientOptions() +realtimeOptions.key = "" +realtimeOptions.clientId = "" +let realtime = ARTRealtime(options: realtimeOptions) +let chatClient = DefaultChatClient(realtime: realtime, clientOptions: nil) +``` + A "@ClientOptions@":/api/realtime-sdk#client-options object may be passed to the Pub/Sub SDK instance to further customize the connection, however at a minimum you must set an API key and provide a @clientId@ to ensure that the client is "identified":/auth/identified-clients. Additional options can also be passed to the Chat client to customize the following properties: -|_. Property |_. Description | -| logHandler | The function to call for each line of "log output":#logging. The default is @console.log@. | -| logLevel | The verbosity of the "log output":#logging. Options are; @trace@, @debug@, @info@, @warn@, @error@ or @silent@. The default is @error@. | +blang[javascript,react]. + |_. Property |_. Description | + | logHandler | The function to call for each line of "log output":#logging. The default is @console.log@. | + | logLevel | The verbosity of the "log output":#logging. Options are; @trace@, @debug@, @info@, @warn@, @error@ or @silent@. The default is @error@. | + +blang[swift]. + |_. Property |_. Description | + | logHandler | This is your own custom log handler conforming to the @LogHandler@ protocol. A single @log@ function is called for each line of "log output":#logging. The default implementation uses Swift's @Logger@. | + | logLevel | The verbosity of the "log output":#logging. Options are; @.trace@, @.debug@, @.info@, @.warn@, @.error@ or @.silent@. The default is @.error@. | h2(#logging). Logging @@ -145,7 +184,20 @@ const App = => { }; ``` -The @logHandler@ property is your own function that will be called for each line of log output generated by the Chat SDK. +```[swift] +let realtimeOptions = ARTClientOptions() +realtimeOptions.key = "" +realtimeOptions.clientId = "" +let realtime = ARTRealtime(options: realtimeOptions) +let clientOptions = ClientOptions(logHandler: SomeLogHandler(), logLevel: .debug) +return DefaultChatClient(realtime: realtime, clientOptions: clientOptions) +``` + +blang[javascript,react]. + The @logHandler@ property is your own function that will be called for each line of log output generated by the Chat SDK. + +blang[swift]. + The @logHandler@ property is your custom @LogHandler@ implementation that will be called for each line of log output generated by the Chat SDK. The @logLevel@ sets the verbosity of logs that will be output by the SDK. The following log levels are available to set: From 8358e84d5a48f8c405d416df51ab55bf490fde6d Mon Sep 17 00:00:00 2001 From: Marat Al Date: Thu, 5 Dec 2024 00:05:12 +0100 Subject: [PATCH 02/10] Added swift texts and samples. --- content/chat/connect.textile | 56 ++++++++++++++++- content/chat/rooms/history.textile | 48 +++++++++++--- content/chat/rooms/index.textile | 93 ++++++++++++++++++++++------ content/chat/rooms/messages.textile | 38 +++++++++--- content/chat/rooms/occupancy.textile | 24 ++++++- content/chat/rooms/presence.textile | 73 +++++++++++++++++++--- content/chat/rooms/reactions.textile | 35 +++++++++-- content/chat/rooms/typing.textile | 47 +++++++++++--- 8 files changed, 352 insertions(+), 62 deletions(-) diff --git a/content/chat/connect.textile b/content/chat/connect.textile index 31e2591eab..1e3a7e461c 100644 --- a/content/chat/connect.textile +++ b/content/chat/connect.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- When you "instantiate":/chat/setup#instantiate a client, a realtime connection is established and maintained with Ably. You can interact with the connection using the @ChatClient.connection@ object in order to monitor a client's connection status. @@ -24,6 +25,9 @@ A connection can have any of the following statuses: blang[javascript]. Use the "@current@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#current property to check which status a connection is currently in: +blang[swift]. + Use the "@status@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.ConnectionStatus.html#status property to check which status a connection is currently in: + blang[react]. Use the "@currentStatus@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseChatConnectionResponse.html#currentStatus property returned in the response of the "@useChatConnection@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useChatConnection.html hook to check which status a connection is currently in: @@ -44,6 +48,10 @@ const MyComponent = () => { }; ``` +```[swift] +let status = await chatClient.connection.status +``` + blang[react]. Hooks related to chat features, such as @useMessages@ and @useTyping@, also return the current @connectionStatus@ in their response. @@ -61,7 +69,7 @@ blang[react]. }; ``` -blang[javascript]. +blang[javascript,swift]. blang[javascript]. Use the "@connection.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#onChange method to register a listener for status change updates: @@ -69,6 +77,9 @@ blang[javascript]. blang[react]. Listeners can also be registered to monitor the changes in connection status. Any hooks that take an optional listener to monitor their events, such as typing indicator events in the @useTyping@ hook, can also register a status change listener. Changing the value provided for a listener will cause the previously registered listener instance to stop receiving events. All messages will be received by exactly one listener. +blang[swift]. + Use the "@connection.onStatusChange(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Connection.html#onStatusChange method to create a subscription through which you can asynchronously iterate for the status updates: + ```[javascript] const { off } = chatClient.connection.status.onStatusChange((change) => console.log(change)); ``` @@ -86,6 +97,13 @@ const MyComponent = () => { }; ``` +```[swift] +let subscription = chatClient.connection.onStatusChange(bufferingPolicy: .unbounded) +for await statusChange in subscription { + print("Connection status changed to: \(statusChange.current)") +} +``` + blang[javascript]. To remove the connection status listener, call the @off()@ function returned in the @subscribe()@ response: @@ -101,14 +119,21 @@ blang[javascript]. blang[react]. +blang[swift]. + To stop the subscription from firing new status events, call its @unsubscribe()@ method: + + ```[swift] + subscription.unsubscribe() + ``` + h2(#discontinuity). Handle connection discontinuity If a client briefly loses connection to Ably, for example when driving through a tunnel, the SDK will attempt to recover the connection. If the disruption lasts for less than 2 minutes, then on reconnection the SDK will automatically reattach to any rooms and replay any missed messages. During periods of discontinuity greater than 2 minutes then you will need to take steps to recover any missed messages, such as by calling "history":/chat/rooms/history. -blang[javascript]. - Each feature of the Chat SDK provides an @onDiscontinuity()@ handler to assist with this. These methods enable you to register a listener that will be notified when discontinuity occurs in that feature so that you can handle it, as needed. +blang[javascript,swift]. + Each feature of the Chat SDK provides an @onDiscontinuity()@@subscribeToDiscontinuities()@ handler to assist with this. These methods enable you to register a listener that will be notified when discontinuity occurs in that feature so that you can handle it, as needed. blang[react]. Any hooks that take an optional listener to monitor their events, such as typing indicator events in the @useTyping@ hook, can also register a listener to be notified of, and handle, periods of discontinuity. @@ -136,6 +161,13 @@ const MyComponent = () => { }; ``` +```[swift] +let subscription = room.messages.subscribeToDiscontinuities() +for await error in subscription { + print("Recovering from the error: \(error)") +} +``` + blang[react]. blang[javascript]. @@ -145,10 +177,28 @@ blang[javascript]. off(); ``` +blang[swift]. + To cancel discontinuity subscribtion, call the provided @unsubscribe()@ method: + + ```[swift] + subscription.unsubscribe() + ``` + +blang[javascript,swift]. The following discontinuity handlers are available: + +blang[react]. +blang[javascript]. * "Messages":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#onDiscontinuity * "Presence":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#onDiscontinuity * "Occupancy":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#onDiscontinuity * "Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#onDiscontinuity * "Room reactions":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#onDiscontinuity + +blang[swift]. + * "Messages":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribeToDiscontinuities + * "Presence":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#subscribeToDiscontinuities + * "Occupancy":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#subscribeToDiscontinuities + * "Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#subscribeToDiscontinuities + * "Room reactions":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribeToDiscontinuities diff --git a/content/chat/rooms/history.textile b/content/chat/rooms/history.textile index ac5239acca..f39627dd52 100644 --- a/content/chat/rooms/history.textile +++ b/content/chat/rooms/history.textile @@ -5,14 +5,15 @@ product: chat languages: - javascript - react + - swift --- The history feature enables users to retrieve messages that have been previously sent in a room. Ably stores chat messages for 24 hours by default. You can extend this up to 30 days by "contacting us":https://forms.gle/SmCLNFoRrYmkbZSf8. h2(#get). Retrieve previously sent messages -blang[javascript]. - Use the "@messages.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#get method to retrieve messages that have been previously sent to a room: +blang[javascript,swift]. + Use the "@messages.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#get"@messages.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#get method to retrieve messages that have been previously sent to a room: blang[react]. Use the "@get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#get method available from the response of the @useMessages@ hook to retrieve messages that have been previously sent to a room. @@ -50,20 +51,38 @@ const MyComponent = () => { }; ``` +```[swift] +let paginatedResult = try await room.messages.get(options: .init(orderBy: .newestFirst)) +print(paginatedResult.items) +if let next = try await paginatedResult.next { + print(next.items) +} else { + print("End of messages") +} +``` + The following optional parameters can be passed when retrieving previously sent messages: -|_. Parameter |_. Description | -| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. | -| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. | -| direction | The direction in which to retrieve messages from; either @forwards@ or @backwards@. | -| limit | Maximum number of messages to be retrieved, up to 1,000. | +blang[javascript]. + |_. Parameter |_. Description | + | start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. | + | end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. | + | direction | The direction in which to retrieve messages from; either @forwards@ or @backwards@. | + | limit | Maximum number of messages to be retrieved, up to 1,000. | + +blang[swift]. + |_. Parameter |_. Description | + | start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. | + | end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. | + | orderBy | The direction in which to retrieve messages from; either @oldestFirst@ or @newestFirst@. | + | limit | Maximum number of messages to be retrieved, up to 1,000. | h2(#subscribe). Retrieve messages sent prior to subscribing Users can also retrieve historical messages that were sent to a room before the point that they registered a listener by "subscribing":/chat/rooms/messages#subscribe. The order of messages returned is from most recent, to oldest. This is useful for providing conversational context when a user first joins a room, or when they subsequently rejoin it later on. It also ensures that the message history they see is continuous, without any overlap of messages being returned between their subscription and their history call. -blang[javascript]. - Use the "@getPreviousMessages()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.MessageSubscriptionResponse.html#getPreviousMessages function returned as part of a "message subscription":/chat/rooms/messages#subscribe response to only retrieve messages that were received before the listener was subscribed to the room: +blang[javascript,swift]. + Use the "@getPreviousMessages()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.MessageSubscriptionResponse.html#getPreviousMessages"@getPreviousMessages()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.MessageSubscription.html#getPreviousMessages function returned as part of a "message subscription":/chat/rooms/messages#subscribe response to only retrieve messages that were received before the listener was subscribed to the room: blang[react]. Use the "@getPrevious()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#getPreviousMessages method available from the response of the @useMessages@ hook to only retrieve messages that were received before the listener subscribed to the room. As long as a defined value is provided for the listener, and there are no message discontinuities, @getPreviousMessages()@ will return messages from the same point across component renders. If the listener becomes undefined, the subscription to messages will be removed. If you subsequently redefine the listener then @getPreviousMessages()@ will return messages from the new point of subscription. @@ -114,6 +133,17 @@ const MyComponent = () => { }; ``` +```[swift] +let messagesSubscription = try await room.messages.subscribe(bufferingPolicy: .unbounded) +let paginatedResult = try await messagesSubscription.getPreviousMessages(params: .init(limit: 50)) // `orderBy` here is ignored and always `newestFirst` +print(paginatedResult.items) +if let next = try await paginatedResult.next { + print(next.items) +} else { + print("End of messages") +} +``` + The following parameters can be passed when retrieving previously sent messages: |_. Parameter |_. Description | diff --git a/content/chat/rooms/index.textile b/content/chat/rooms/index.textile index f53b049797..825a9ee671 100644 --- a/content/chat/rooms/index.textile +++ b/content/chat/rooms/index.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- Rooms are used to organize and logically separate your users and chat messages into 'rooms'. They are the entry object into using chat and provide access to all other chat features, such as messages, online status and typing indicators. A room can represent a 1:1 chat between an agent and a customer, a private message between two users in a chat application, a large group conversation, or the chat section of a livestream with thousands of users. @@ -15,8 +16,8 @@ h2(#create). Create or retrieve a room Users send messages to a room and subscribe to the room in order to receive messages. Other features, such as indicating which users are online, or which users are typing are configured as part of a room's options. -blang[javascript]. - A @room@ is created, or an existing one is retrieved from the @rooms@ collection using the "@rooms.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#get method: +blang[javascript,swift]. + A @room@ is created, or an existing one is retrieved from the @rooms@ collection using the "@rooms.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#get"@rooms.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Rooms.html#get method: blang[react]. The "@ChatRoomProvider@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.ChatRoomProvider.html provides access to a specific chat room to all child components in the component tree. @@ -53,6 +54,10 @@ const App = () => { }; ``` +```[swift] +let room = try await chatClient.rooms.get(roomID: "basketball-stream", options: RoomOptions()) +``` + blang[react]. -blang[javascript]. - -blang[javascript]. - When you create or retrieve a room using @rooms.get()@, you need to choose which additional chat features you want enabled for that room. This is configured by passing a "@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html object as the second argument. In addition to setting which features are enabled, @RoomOptions@ also configures the properties of the associated features, such as the timeout period for typing indicators. +blang[javascript,swift]. + When you create or retrieve a room using @rooms.get()@, you need to choose which additional chat features you want enabled for that room. This is configured by passing a "@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomOptions.html object as the second argument. In addition to setting which features are enabled, @RoomOptions@ also configures the properties of the associated features, such as the timeout period for typing indicators. ```[javascript] const presence = {enter: false}; @@ -73,6 +76,15 @@ blang[javascript]. const room = chatClient.rooms.get('basketball-stream', {presence, reactions, typing, occupancy}); ``` + ```[swift] + let presence = PresenceOptions(enter: false) + let typing = TypingOptions(timeout: 5.0) // seconds + // using defaults for reactions and occupancy + let options = RoomOptions(presence: presence, typing: typing, reactions: nil, occupancy: nil) + let room = try await chatClient.rooms.get(roomID: "basketball-stream", options: options) + ``` + +blang[javascript]. You can also use the @RoomOptionsDefaults@ property for each @RoomOption@ to configure whether the default settings should be used: ```[javascript] @@ -85,15 +97,23 @@ blang[javascript]. const room = chatClient.rooms.get('basketball-stream', {typing: {timeoutMs: 5000}}); ``` -blang[react]. +blang[react,swift]. Enable each feature using its associated option. The details of the options available to each feature are documented on their respective pages: -| Feature | @RoomOption@ | Default settings | -| "Presence":/chat/rooms/presence | @presence@ | @RoomOptionsDefaults.presence@ | -| "Occupancy":/chat/rooms/occupancy | @occupancy@ | @RoomOptionsDefaults.occupancy@ | -| "Typing indicators":/chat/rooms/typing | @typing@ | @RoomOptionsDefaults.typing@ | -| "Room reactions":/chat/rooms/reactions | @reactions@ | @RoomOptionsDefaults.reactions@ | +blang[javascript]. + | Feature | @RoomOption@ | Default settings | + | "Presence":/chat/rooms/presence | @presence@ | @RoomOptionsDefaults.presence@ | + | "Occupancy":/chat/rooms/occupancy | @occupancy@ | @RoomOptionsDefaults.occupancy@ | + | "Typing indicators":/chat/rooms/typing | @typing@ | @RoomOptionsDefaults.typing@ | + | "Room reactions":/chat/rooms/reactions | @reactions@ | @RoomOptionsDefaults.reactions@ | + +blang[swift]. + | Feature | @RoomOption@ | Default settings | + | "Presence":/chat/rooms/presence | @presence@ | @PresenceOptions()@ | + | "Occupancy":/chat/rooms/occupancy | @occupancy@ | @OccupancyOptions()@ | + | "Typing indicators":/chat/rooms/typing | @typing@ | @TypingOptions()@ | + | "Room reactions":/chat/rooms/reactions | @reactions@ | @RoomReactionsOptions()@ | h3(#release). Release a room @@ -101,13 +121,17 @@ Releasing a room allows the underlying resources to be garbage collected or rele Releasing a room may be optional for many applications. If you have multiple transient rooms, such as in the case of a 1:1 support chat, then it is may be more beneficial. -blang[javascript]. - Once "@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#release has been called, the room will be unusable and a new instance will need to be created using "@rooms.get()@":#create if you want to reuse it. +blang[javascript,swift]. + Once "@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#release"@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Rooms.html#release has been called, the room will be unusable and a new instance will need to be created using "@rooms.get()@":#create if you want to reuse it. ```[javascript] await rooms.release('basketball-stream'); ``` + ```[swift] + try await rooms.release(roomID: "basketball-stream") + ``` + blang[react]. By default the @ChatRoomProvider@ will automatically call "@release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#release on the room when it unmounts. Set the "@release@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.ChatRoomProviderProps.html#release property to @false@ to change this behavior and have the room only "detach":#detach when the component unmounts. You can manually control this attachment behavior using the "@useRoom@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useRoom.html hook. @@ -115,10 +139,10 @@ h2(#attach). Attach to a room As soon as a client is attached to a room, Ably will begin streaming messages and events to them, regardless of whether or not they have registered any listeners to receive those messages and events. -blang[javascript]. +blang[javascript,swift]. Once a reference to a room has been created using @rooms.get()@, clients attach to it in order to ensure it is created in the Ably system. - Use the "@attach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#attach method on a room to attach to it: + Use the "@attach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#attach"@attach()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#attach method on a room to attach to it: blang[react]. By default the @ChatRoomProvider@ will automatically call "@attach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#attach on the room when it first mounts. Set the "@attach@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.ChatRoomProviderProps.html#attach property to @false@ to manually control the attachment using the "@useRoom@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useRoom.html hook instead. @@ -142,15 +166,23 @@ const MyComponent = () => { }; ``` +```[swift] +try await room.attach() +``` + h3(#detach). Detach from a room -blang[javascript]. - Use the "@detach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#detach method on a room to detach from it and stop receiving messages and events: +blang[javascript,swift]. + Use the "@detach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#detach"@detach()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#detach method on a room to detach from it and stop receiving messages and events: ```[javascript] await room.detach(); ``` + ```[swift] + try await room.detach() + ``` + blang[react]. By default the @ChatRoomProvider@ will automatically call "@release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#release on the room when it unmounts. Set the "@release@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.ChatRoomProviderProps.html#release property to @false@ to change this behavior and have the room only "detach":#detach when the component unmounts. You can manually control this attachment behavior using the "@useRoom@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useRoom.html hook. @@ -174,8 +206,9 @@ A room can have any of the following statuses: | suspended | The room, having previously been attached, has lost continuity. This is normally due to the client being disconnected from Ably for more than two minutes. The client will automatically attempt to reattach as soon as connectivity is restored. | | failed | An indefinite failure condition. This status is entered if an error has been received from Ably, such as an attempt to attach without the necessary access rights. | -blang[javascript]. - Use the "@current@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#current property to check which status a room is currently in: + +blang[javascript,swift]. + Use the "@current@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#current"@status@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomStatus.html property to check which status a room is currently in: blang[react]. Use the @roomStatus@ property to view the current "@Room@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html status changes. The @roomError@ property is its associated error. Any hooks that take an optional listener have these properties available in their response, such as @useMessages@ or @useTyping@. It is more common that you will monitor the room status in the specific feature hooks rather than needing to use @useRoom@. These events are related to the room instance of the nearest "@ChatRoomProvider@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.ChatRoomProvider.html. For example, with the @useMessages@ hook: @@ -203,6 +236,10 @@ const MyComponent = () => { }; ``` +```[swift] +let status = try await room.status +``` + blang[javascript]. You can also subscribe to room status updates by registering a listener. An event will be emitted whenever the status of the room changes. @@ -243,3 +280,19 @@ blang[react]. return
Occupancy Component
; }; ``` + +blang[swift]. + You can also create a subscribtion to the room status updates. An event will be emitted whenever the status of the room changes. + + ```[swift] + let statusSubscription = try await room.onStatusChange(bufferingPolicy: .unbounded) + for await status in statusSubscription { + print("Room status: \(status)") + } + ``` + + To cancel the room status subscribtion, call the provided @unsubscribe()@ method: + + ```[swift] + statusSubscription.unsubscribe() + ``` diff --git a/content/chat/rooms/messages.textile b/content/chat/rooms/messages.textile index b6a7ab46fd..322c6c558d 100644 --- a/content/chat/rooms/messages.textile +++ b/content/chat/rooms/messages.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- You can send and receive messages in a chat room with any number of participants. These users subscribe to messages by registering a listener, and send messages to all users that are subscribed to receive them. @@ -19,6 +20,9 @@ blang[react]. Providing a listener will also enable you to retrieve messages that have been "previously sent to the room.":/chat/rooms/history +blang[swift]. + Subscribe to receive messages in a room by creating a subscription. Use the "@messages.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribe method in a room to receive all messages that are sent to it: + ```[javascript] const {unsubscribe} = room.messages.subscribe((message) => { console.log(message); @@ -40,6 +44,13 @@ const MyComponent = () => { }; ``` +```[swift] +let messagesSubscription = try await room.messages.subscribe(bufferingPolicy: .unbounded) +for await message in messagesSubscription { + print("Message received: \(message)") +} +``` + h3(#structure). Message structure The following is the structure of a message: @@ -88,19 +99,26 @@ blang[javascript]. await room.messages.unsubscribeAll(); ``` - - blang[react]. When you unmount the component that is using the @useMessages@ hook, it will automatically handle unsubscribing any associated listeners registered to receive messages. +blang[swift]. + To cancel the room messages subscribtion, call the provided @unsubscribe()@ method: + + ```[swift] + messagesSubscription.unsubscribe() + ``` + + + h2(#send). Send a message -blang[javascript]. - Use the "@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#send method to send a message in a chat room. All users that are "subscribed":#subscribe to messages on that room will receive it: +blang[javascript,swift]. + Use the "@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#send"@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#send method to send a message in a chat room. All users that are "subscribed":#subscribe to messages on that room will receive it: blang[react]. Use the "@send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#send method available from the response of the @useMessages@ hook to to send a message to the room: @@ -126,3 +144,7 @@ const MyComponent = () => { ); }; ``` + +```[swift] +let message = try await room.messages.send(params: .init(text: "hello")) +``` diff --git a/content/chat/rooms/occupancy.textile b/content/chat/rooms/occupancy.textile index 8847151036..fd4959b89e 100644 --- a/content/chat/rooms/occupancy.textile +++ b/content/chat/rooms/occupancy.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- Occupancy enables you to view the number of users currently online in a room. This feature can be used to display user counts to highlight popular, or trending chat rooms. @@ -21,12 +22,22 @@ blang[javascript]. blang[react]. Subscribe to a room's occupancy with the "@useOccupancy@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useOccupancy.html hook. +blang[swift]. + Subscribe to a room's occupancy by creating a subscription. Use the "@occupancy.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#subscribe method in a room to receive updates: + ```[javascript] const {unsubscribe} = room.occupancy.subscribe((event) => { console.log(event); }); ``` +```[swift] +let occupancySubscription = try await room.occupancy.subscribe(bufferingPolicy: .unbounded) +for await event in occupancySubscription { + occupancyInfo = "Connections: \(event.presenceMembers) (\(event.connections))" +} +``` + ```[react] import { useOccupancy } from '@ably/chat/react'; @@ -97,9 +108,16 @@ blang[javascript]. blang[react]. When you unmount the component that is using the @useOccupancy@ hook, it will automatically handle unsubscribing any associated listeners registered for room occupancy. +blang[swift]. + To cancel the room occupancy subscribtion, call the provided @unsubscribe()@ method: + + ```[swift] + occupancySubscription.unsubscribe() + ``` + h2(#retrieve). Retrieve room occupancy -blang[javascript]. +blang[javascript,swift]. The occupancy of a room can be retrieved in one-off calls instead of subscribing to updates. Use the "@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#get method to retrieve the occupancy of a room: @@ -108,6 +126,10 @@ blang[javascript]. const occupancy = await room.occupancy.get(); ``` + ```[swift] + let occupancy = try await room.occupancy.get() + ``` + blang[react]. Use the "@connections@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseOccupancyResponse.html#connections and "@presenceMembers@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseOccupancyResponse.html#presenceMembers properties available from the response of the @useOccupancy@ hook to view the occupancy of a room. diff --git a/content/chat/rooms/presence.textile b/content/chat/rooms/presence.textile index d581985726..fde441ef17 100644 --- a/content/chat/rooms/presence.textile +++ b/content/chat/rooms/presence.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- Subscribe to the online status of room members using the presence feature. Presence enables you to show which members are currently online, indicate when a user goes offline, and have users optionally set additional information about their profile, or their current status within the application. @@ -23,6 +24,9 @@ blang[react]. To enter the presence set of a room, use the "@usePresence@":#set hook instead. +blang[swift]. + Subscribe to users' presence status by creating a subscription. Presence events are emitted whenever a member enters or leaves the presence set, or updates their user data. Use the "@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#subscribe method in a room to receive updates: + ```[javascript] const { unsubscribe } = room.presence.subscribe((event) => { console.log(`${event.clientId} entered with data: ${event.data}`); @@ -57,7 +61,14 @@ const MyComponent = () => { }; ``` -blang[javascript]. +```[swift] +let presenceSubscription = try await room.presence.subscribe(events: [.enter, .leave, .update]) +for await event in presenceSubscription { + print("Presence event `\(event.action)` from `\(event.clientId)` with data `\(event.data)`") +} +``` + +blang[javascript,swift]. You can also subscribe to only specific presence events, or an array of presence events: ```[javascript] @@ -72,6 +83,14 @@ blang[javascript]. }); ``` + ```[swift] + // Subscribe to only 'enter' events: + let presenceSubscription = try await room.presence.subscribe(event: .enter) + + // Subscribe to 'update' and 'leave' events: + let presenceSubscription = try await room.presence.subscribe(events: [.leave, .update]) + ``` + blang[react]. h3(#event-structure). Presence event structure @@ -121,6 +140,13 @@ blang[javascript]. blang[react]. When you unmount the component that is using the @usePresenceListener@ hook, it will automatically handle unsubscribing any associated listeners registered for presence status updates. +blang[swift]. + To cancel the room presence subscribtion, call the provided @unsubscribe()@ method: + + ```[swift] + presenceSubscription.unsubscribe() + ``` + h2(#set). Set user presence Users can enter and leave the presence set of a room to indicate when they are online or offline. They can also set user data when entering and leaving the set, such as their current status. Presence is also linked to a user's "connection status":/chat/connect. For example, if a user goes offline then a leave event will be emitted for them. @@ -129,8 +155,8 @@ Users can enter and leave the presence set of a room to indicate when they are o

Users must be identified to enter into the presence set. This means that they must set a @clientId@ when "instantiating their client":/chat/setup#instantiate.

-blang[javascript]. - Use the "@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#enter method to indicate when a user joins a room. This will send a presence event to all users subscribed to presence indicating that a new member has joined the chat. You can also set an optional data field with information such as the status of a user: +blang[javascript,swift]. + Use the "@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#enter"@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#enter method to indicate when a user joins a room. This will send a presence event to all users subscribed to presence indicating that a new member has joined the chat. You can also set an optional data field with information such as the status of a user: blang[react]. Indicate when a user joins a room with the "@usePresence@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.usePresence.html hook. Users will automatically be entered into the presence set when the component mounts. @@ -159,8 +185,12 @@ const MyComponent = () => { }; ``` -blang[javascript]. - Use the "@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#update method when a user wants to update their data, such as an update to their status, or to indicate that they're raising their hand. Updates will send a presence event ao all users subscribed to presence: +```[swift] +try await room.presence.enter(data: .init(userCustomData: ["status": .string("Online")])) +``` + +blang[javascript,swift]. + Use the "@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#update"@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#update method when a user wants to update their data, such as an update to their status, or to indicate that they're raising their hand. Updates will send a presence event to all users subscribed to presence: blang[react]. Use the "@update()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UsePresenceResponse.html#update property available from the response of the @usePresence@ hook to update a user's data, such as setting their status to 'Away from keyboard'. @@ -191,8 +221,12 @@ const MyComponent = () => { }; ``` +```[swift] +try await room.presence.update(data: .init(userCustomData: ["status": .string("Busy")])) +``` + blang[javascript]. - Use the "@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#leave method to explicitly remove a user from the presence set. This will send a presence event to all users subscribed to presence. You can also set an optional data field such as setting a status of 'Back later'. + Use the "@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#leave"@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#leave method to explicitly remove a user from the presence set. This will send a presence event to all users subscribed to presence. You can also set an optional data field such as setting a status of 'Back later'. blang[react]. Indicate when a user leaves a room with the "@usePresence@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.usePresence.html hook. Users will automatically be removed from the presence set when the component unmounts. @@ -218,6 +252,10 @@ const MyComponent = () => { }; ``` +```[swift] +try await room.presence.leave(data: .init(userCustomData: ["status": .string("Be back later!")])) +``` + When a user goes offline or closes their "connection":/chat/connect, a leave event is also emitted and they are removed from the presence set. h2(#options). Presence options @@ -237,10 +275,10 @@ blang[react]. h2(#retrieve). Retrieve the presence set -blang[javascript]. +blang[javascript,swift]. The online presence of users can be retrieved in one-off calls. This can be used to check the status of an individual user, or return the entire presence set as an array. - Use the "@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#get method to retrieve an array of all users currently entered into the presence set, or individual users: + Use the "@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#get"@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#get method to retrieve an array of all users currently entered into the presence set, or individual users: ```[javascript] // Retrieve all users entered into presence as an array: @@ -250,15 +288,32 @@ blang[javascript]. const presentMember = await room.presence.get({ clientId: 'clemons123' }); ``` - Alternatively, use the "@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#isUserPresent method and pass in a user's @clientId@ to check whether they are online or not. This will return a boolean: + ```[swift] + // Retrieve all users entered into presence as an array: + let presentMembers = try await room.presence.get() + + // Retrieve the status of specific users by their clientId: + let presentMember = try await room.presence.get(params: .init(clientID: "clemons123")) + ``` + +blang[react]. + +blang[javascript,swift]. + Alternatively, use the "@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#isUserPresent"@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#isUserPresent method and pass in a user's @clientId@ to check whether they are online or not. This will return a boolean: ```[javascript] const isPresent = await room.presence.isUserPresent('clemons123'); ``` + ```[swift] + let isPresent = try await room.presence.isUserPresent(clientID: "clemons123") + ``` + blang[react]. Use the "@presenceData@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UsePresenceListener.html#presenceData property available from the response of the @usePresence@ hook to view a list of all member's presence status in the room. +blang[javascript,swift]. + h3(#member-structure). Presence member structure The following is the structure of an individual presence member within the presence set: diff --git a/content/chat/rooms/reactions.textile b/content/chat/rooms/reactions.textile index 2e771dab4d..89b4f8823d 100644 --- a/content/chat/rooms/reactions.textile +++ b/content/chat/rooms/reactions.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- Users can send reactions to the entire chat room to show their sentiment as to what is happening. For example, agreeing with the content in a livestream using a thumbs up, or sending a heart when their team scores in a sports game. @@ -17,11 +18,16 @@ Room reactions are ephemeral and not stored or aggregated by Ably. The intention h2(#subscribe). Subscribe to room reactions +Room reactions events are emitted whenever a user sends a reaction, such as by hitting a 'like' button or clicking a heart emoji. + blang[javascript]. - Subscribe to room reactions by registering a listener. These events are emitted whenever a user sends a reaction, such as by hitting a 'like' button or clicking a heart emoji. Use the "@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe method in a room to receive reactions: + Subscribe to room reactions by registering a listener. Use the "@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe method in a room to receive reactions: blang[react]. - Subscribe to room reactions with the "@useRoomReactions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useRoomReactions.html hook. Supply an optional listener to receive the room reactions. + Subscribe to room reactions with the "@useRoomReactions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat_react.useRoomReactions.html hook. Supply an optional listener to receive the room reactions. + +blang[swift]. + Subscribe to a room reactions by creating a subscription. Use the "@reactions.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribe method in a room to receive reactions: ```[javascript] const {unsubscribe} = room.reactions.subscribe((reaction) => { @@ -42,6 +48,13 @@ const MyComponent = () => { }; ``` +```[swift] +let reactionSubscription = try await room.reactions.subscribe(bufferingPolicy: .unbounded) +for await reaction in reactionSubscription { + print("Received a reaction of type \(reaction.type), and metadata \(reaction.metadata)") +} +``` + h3(#structure). Room reaction event structure The following is the structure of a room reaction event: @@ -95,10 +108,17 @@ blang[javascript]. blang[react]. When you unmount the component that is using the @useRoomReactions@ hook, it will automatically handle unsubscribing any associated listeners registered for room reactions. +blang[swift]. + To cancel the room reactions subscribtion, call the provided @unsubscribe()@ method: + + ```[swift] + reactionSubscription.unsubscribe() + ``` + h2(#send). Send a room reaction -blang[javascript]. - Use the "@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#send method to send a room-level reaction. The most common way of using this method is to trigger it whenever a user clicks an emoji button in a room: +blang[javascript,swift]. + Use the "@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#send"@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#send method to send a room-level reaction. The most common way of using this method is to trigger it whenever a user clicks an emoji button in a room: blang[react]. Use the "@send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseRoomReactionsResponse.html#send method available from the response of the @useRoomReactions@ hook to emit an event when a user reacts, for example when they click an emoji button: @@ -126,3 +146,10 @@ const MyComponent = () => { ); }; ``` + +```[swift] +try await room.reactions.send(params: .init(type: "like")) + +try await room.reactions.send(params: .init(type: "heart", + metadata: ["effect": .string("fireworks")])) +``` diff --git a/content/chat/rooms/typing.textile b/content/chat/rooms/typing.textile index caee9146f1..0445cdb9ca 100644 --- a/content/chat/rooms/typing.textile +++ b/content/chat/rooms/typing.textile @@ -5,9 +5,10 @@ product: chat languages: - javascript - react + - swift --- -Typing indicators enable you to display which users are currently writing a message in a room. This feature can be used to display a message such as __Sandi is typing...__, or when a certain threshold is reached you could instead display __Multiple people are typing...__ or _12 people are typing..._. +Typing indicators enable you to display which users are currently writing a message in a room. This feature can be used to display a message such as __Sandi is typing...__, or when a certain threshold is reached you could instead display __Multiple people are typing...__ or _12 people are typing..._. Typing events can be emitted when a user starts or stops typing. blang[javascript,swift]. - When you create or retrieve a room using @rooms.get()@, you need to choose which additional chat features you want enabled for that room. This is configured by passing a "@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/roomoptions object as the second argument. In addition to setting which features are enabled, @RoomOptions@ also configures the properties of the associated features, such as the timeout period for typing indicators. + When you create or retrieve a room using @rooms.get()@, you need to choose which additional chat features you want enabled for that room. This is configured by passing a "@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomoptions object as the second argument. In addition to setting which features are enabled, @RoomOptions@ also configures the properties of the associated features, such as the timeout period for typing indicators. ```[javascript] const presence = {enter: false}; @@ -122,7 +122,7 @@ Releasing a room allows the underlying resources to be garbage collected or rele Releasing a room may be optional for many applications. If you have multiple transient rooms, such as in the case of a 1:1 support chat, then it is may be more beneficial. blang[javascript,swift]. - Once "@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#release"@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/rooms/release%28roomid%3A%29 has been called, the room will be unusable and a new instance will need to be created using "@rooms.get()@":#create if you want to reuse it. + Once "@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#release"@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/rooms/release%28roomid%3A%29 has been called, the room will be unusable and a new instance will need to be created using "@rooms.get()@":#create if you want to reuse it. ```[javascript] await rooms.release('basketball-stream'); @@ -142,7 +142,7 @@ As soon as a client is attached to a room, Ably will begin streaming messages an blang[javascript,swift]. Once a reference to a room has been created using @rooms.get()@, clients attach to it in order to ensure it is created in the Ably system. - Use the "@attach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#attach"@attach()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/room/attach%28%29 method on a room to attach to it: + Use the "@attach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#attach"@attach()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/room/attach%28%29 method on a room to attach to it: blang[react]. By default the @ChatRoomProvider@ will automatically call "@attach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#attach on the room when it first mounts. Set the "@attach@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.ChatRoomProviderProps.html#attach property to @false@ to manually control the attachment using the "@useRoom@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useRoom.html hook instead. @@ -173,7 +173,7 @@ try await room.attach() h3(#detach). Detach from a room blang[javascript,swift]. - Use the "@detach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#detach"@detach()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/room/detach%28%29 method on a room to detach from it and stop receiving messages and events: + Use the "@detach()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#detach"@detach()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/room/detach%28%29 method on a room to detach from it and stop receiving messages and events: ```[javascript] await room.detach(); @@ -208,7 +208,7 @@ A room can have any of the following statuses: blang[javascript,swift]. - Use the "@current@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#current"@status@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/roomstatus property to check which status a room is currently in: + Use the "@current@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#current"@status@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomstatus property to check which status a room is currently in: blang[react]. Use the @roomStatus@ property to view the current "@Room@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html status changes. The @roomError@ property is its associated error. Any hooks that take an optional listener have these properties available in their response, such as @useMessages@ or @useTyping@. It is more common that you will monitor the room status in the specific feature hooks rather than needing to use @useRoom@. These events are related to the room instance of the nearest "@ChatRoomProvider@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.ChatRoomProvider.html. For example, with the @useMessages@ hook: @@ -243,7 +243,7 @@ let status = try await room.status blang[javascript,swift]. You can also subscribe to room status updates by registering a listener. An event will be emitted whenever the status of the room changes. - Use the "@room.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#onChange"@room.onStatusChange()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/room/onstatuschange%28%29-s9g method in a room to register a listener for status change updates: + Use the "@room.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#onChange"@room.onStatusChange()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/room/onstatuschange%28%29-s9g method in a room to register a listener for status change updates: ```[javascript] const { off } = room.onStatusChange((change) => diff --git a/content/chat/rooms/messages.textile b/content/chat/rooms/messages.textile index f06dcf217f..fa23ec396a 100644 --- a/content/chat/rooms/messages.textile +++ b/content/chat/rooms/messages.textile @@ -13,7 +13,7 @@ You can send and receive messages in a chat room with any number of participants h2(#subscribe). Subscribe to messages blang[javascript,swift]. - Subscribe to receive messages in a room by registering a listener. Use the "@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#subscribe"@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/messages/subscribe%28%29-360z1 method in a room to receive all messages that are sent to it: + Subscribe to receive messages in a room by registering a listener. Use the "@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#subscribe"@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/subscribe%28%29-360z1 method in a room to receive all messages that are sent to it: blang[react]. Subscribe to messages with the "@useMessages@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useMessages.html hook. Supply a listener and the hook will automatically subscribe to messages sent to the room. As long as a defined value is provided, the subscription will persist across renders. If the listener value is undefined, the subscription will be removed until it becomes defined again. @@ -123,7 +123,7 @@ blang[react]. h2(#send). Send a message blang[javascript,swift]. - Use the "@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#send"@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/messages/send%28params%3A%29 method to send a message in a chat room. All users that are "subscribed":#subscribe to messages on that room will receive it: + Use the "@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#send"@messages.send()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/send%28params%3A%29 method to send a message in a chat room. All users that are "subscribed":#subscribe to messages on that room will receive it: blang[react]. Use the "@send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#send method available from the response of the @useMessages@ hook to send a message to the room: diff --git a/content/chat/rooms/occupancy.textile b/content/chat/rooms/occupancy.textile index 3584ae234d..8bc39086d9 100644 --- a/content/chat/rooms/occupancy.textile +++ b/content/chat/rooms/occupancy.textile @@ -17,7 +17,7 @@ Occupancy enables you to view the number of users currently online in a room. Th h2(#subscribe). Subscribe to room occupancy blang[javascript,swift]. - Subscribe to a room's occupancy by registering a listener. Occupancy events are emitted whenever the number of online users within a room changes. Use the "@occupancy.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#subscribe"@occupancy.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/occupancy/subscribe%28%29-3loon method in a room to receive updates: + Subscribe to a room's occupancy by registering a listener. Occupancy events are emitted whenever the number of online users within a room changes. Use the "@occupancy.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#subscribe"@occupancy.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/occupancy/subscribe%28%29-3loon method in a room to receive updates: blang[react]. Subscribe to a room's occupancy with the "@useOccupancy@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useOccupancy.html hook. @@ -121,7 +121,7 @@ h2(#retrieve). Retrieve room occupancy blang[javascript,swift]. The occupancy of a room can be retrieved in one-off calls instead of subscribing to updates. - Use the "@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#get"@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/occupancy/get%28%29 method to retrieve the occupancy of a room: + Use the "@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#get"@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/occupancy/get%28%29 method to retrieve the occupancy of a room: ```[javascript] const occupancy = await room.occupancy.get(); diff --git a/content/chat/rooms/presence.textile b/content/chat/rooms/presence.textile index e55a59695f..8479feee5d 100644 --- a/content/chat/rooms/presence.textile +++ b/content/chat/rooms/presence.textile @@ -17,7 +17,7 @@ Subscribe to the online status of room members using the presence feature. Prese h2(#subscribe). Subscribe to presence blang[javascript,swift]. - Subscribe to users' presence status by registering a listener. Presence events are emitted whenever a member enters or leaves the presence set, or updates their user data. Use the "@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#subscribe"@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/presence/subscribe%28event%3A%29-95gdn method in a room to receive updates: + Subscribe to users' presence status by registering a listener. Presence events are emitted whenever a member enters or leaves the presence set, or updates their user data. Use the "@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#subscribe"@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence/subscribe%28event%3A%29-95gdn method in a room to receive updates: blang[react]. Subscribe to users' presence status with the "@usePresenceListener@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.usePresenceListener.html hook. Supply an optional listener to receive presence status updates, or use the "@presenceData@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UsePresenceListenerResponse.html#presenceData property returned by the hook. @@ -157,7 +157,7 @@ Users can enter and leave the presence set of a room to indicate when they are o blang[javascript,swift]. - Use the "@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#enter"@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/presence/enter%28data%3A%29 method to indicate when a user joins a room. This will send a presence event to all users subscribed to presence indicating that a new member has joined the chat. You can also set an optional data field with information such as the status of a user: + Use the "@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#enter"@presence.enter()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence/enter%28data%3A%29 method to indicate when a user joins a room. This will send a presence event to all users subscribed to presence indicating that a new member has joined the chat. You can also set an optional data field with information such as the status of a user: blang[react]. Indicate when a user joins a room with the "@usePresence@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.usePresence.html hook. Users will automatically be entered into the presence set when the component mounts. @@ -191,7 +191,7 @@ try await room.presence.enter(data: .init(userCustomData: ["status": .string("On ``` blang[javascript,swift]. - Use the "@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#update"@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/presence/update%28data%3A%29 method when a user wants to update their data, such as an update to their status, or to indicate that they're raising their hand. Updates will send a presence event to all users subscribed to presence: + Use the "@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#update"@presence.update()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence/update%28data%3A%29 method when a user wants to update their data, such as an update to their status, or to indicate that they're raising their hand. Updates will send a presence event to all users subscribed to presence: blang[react]. Use the "@update()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UsePresenceResponse.html#update property available from the response of the @usePresence@ hook to update a user's data, such as setting their status to 'Away from keyboard'. @@ -227,7 +227,7 @@ try await room.presence.update(data: .init(userCustomData: ["status": .string("B ``` blang[javascript]. - Use the "@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#leave"@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/presence/leave%28data%3A%29 method to explicitly remove a user from the presence set. This will send a presence event to all users subscribed to presence. You can also set an optional data field such as setting a status of 'Back later'. + Use the "@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#leave"@presence.leave()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence/leave%28data%3A%29 method to explicitly remove a user from the presence set. This will send a presence event to all users subscribed to presence. You can also set an optional data field such as setting a status of 'Back later'. blang[react]. Indicate when a user leaves a room with the "@usePresence@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.usePresence.html hook. Users will automatically be removed from the presence set when the component unmounts. @@ -279,7 +279,7 @@ h2(#retrieve). Retrieve the presence set blang[javascript,swift]. The online presence of users can be retrieved in one-off calls. This can be used to check the status of an individual user, or return the entire presence set as an array. - Use the "@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#get"@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/presence/get%28%29 method to retrieve an array of all users currently entered into the presence set, or individual users: + Use the "@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#get"@presence.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence/get%28%29 method to retrieve an array of all users currently entered into the presence set, or individual users: ```[javascript] // Retrieve all users entered into presence as an array: @@ -301,7 +301,7 @@ blang[react]. Use the "@presenceData@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UsePresenceListener.html#presenceData property available from the response of the @usePresence@ hook to view a list of all member's presence status in the room. blang[javascript,swift]. - Alternatively, use the "@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#isUserPresent"@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/presence/isuserpresent%28clientid%3A%29 method and pass in a user's @clientId@ to check whether they are online or not. This will return a boolean: + Alternatively, use the "@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#isUserPresent"@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence/isuserpresent%28clientid%3A%29 method and pass in a user's @clientId@ to check whether they are online or not. This will return a boolean: ```[javascript] const isPresent = await room.presence.isUserPresent('clemons123'); diff --git a/content/chat/rooms/reactions.textile b/content/chat/rooms/reactions.textile index 5eb6762214..473f52324f 100644 --- a/content/chat/rooms/reactions.textile +++ b/content/chat/rooms/reactions.textile @@ -19,7 +19,7 @@ Room reactions are ephemeral and not stored or aggregated by Ably. The intention h2(#subscribe). Subscribe to room reactions blang[javascript,swift]. - Subscribe to room reactions by registering a listener. Use the "@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe"@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/roomreactions/subscribe%28%29-64gdf method in a room to receive reactions: + Subscribe to room reactions by registering a listener. Use the "@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe"@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomreactions/subscribe%28%29-64gdf method in a room to receive reactions: blang[react]. Subscribe to room reactions with the "@useRoomReactions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat_react.useRoomReactions.html hook. Supply an optional listener to receive the room reactions. @@ -117,7 +117,7 @@ blang[react,swift]. h2(#send). Send a room reaction blang[javascript,swift]. - Use the "@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#send"@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/roomreactions/send%28params%3A%29 method to send a room-level reaction. The most common way of using this method is to trigger it whenever a user clicks an emoji button in a room: + Use the "@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#send"@reactions.send()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomreactions/send%28params%3A%29 method to send a room-level reaction. The most common way of using this method is to trigger it whenever a user clicks an emoji button in a room: blang[react]. Use the "@send()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseRoomReactionsResponse.html#send method available from the response of the @useRoomReactions@ hook to emit an event when a user reacts, for example when they click an emoji button: diff --git a/content/chat/rooms/typing.textile b/content/chat/rooms/typing.textile index 58f82c664d..87df65425c 100644 --- a/content/chat/rooms/typing.textile +++ b/content/chat/rooms/typing.textile @@ -17,7 +17,7 @@ Typing indicators enable you to display which users are currently writing a mess h2(#subscribe). Subscribe to typing events blang[javascript,swift]. - Subscribe to typing events by registering a listener. Typing events can be emitted when a user starts typing, and when they stop typing. Use the "@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#subscribe"@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/typing/subscribe%28%29-7uox7 method in a room to receive these updates: + Subscribe to typing events by registering a listener. Typing events can be emitted when a user starts typing, and when they stop typing. Use the "@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#subscribe"@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/subscribe%28%29-7uox7 method in a room to receive these updates: blang[react]. Subscribe to typing events with the "@useTyping@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useTyping.html hook. Supply an optional listener to receive the typing events, or use the "@currentlyTyping@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseTypingResponse.html#currentlyTyping property returned by the hook to access the list of those users that are currently typing. @@ -115,7 +115,7 @@ blang[react,swift]. h2(#set). Set typing status blang[javascript,swift]. - Use the "@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#start"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/typing/start%28%29 method to emit a typing event with @isTyping@ set to @true@. + Use the "@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#start"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/start%28%29 method to emit a typing event with @isTyping@ set to @true@. blang[react]. Use the "@start()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseTypingResponse.html#start method available from the response of the @useTyping@ hook to emit an event when a user has started typing. @@ -150,7 +150,7 @@ try await room.typing.start() ``` blang[javascript,swift]. - Use the "@stop()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#stop"@stop()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/typing/stop%28%29 method to emit a typing event with @isTyping@ set to @false@. + Use the "@stop()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#stop"@stop()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/stop%28%29 method to emit a typing event with @isTyping@ set to @false@. blang[react]. Use the "@stop()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseTypingResponse.html#stop method available from the response of the @useTyping@ hook to emit an event when a user has stopped typing. @@ -184,7 +184,7 @@ try await room.typing.stop() h2(#retrieve). Retrieve a list of users that are currently typing blang[javascript,swift]. - Use the "@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#get"@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/typing/get%28%29 method to retrieve a set of @clientId@s for all users that are currently typing in the room: + Use the "@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#get"@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/get%28%29 method to retrieve a set of @clientId@s for all users that are currently typing in the room: ```[javascript] const currentlyTypingClientIds = await room.typing.get(); From 2cf050a9fae56a4df347196f5ebdd1c3a7262e1d Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Thu, 19 Dec 2024 12:02:55 -0300 Subject: [PATCH 10/10] Update Swift Chat metadata example Reflects the fact that we now use JSONValue (see ably-chat-swift commit c360d7c). --- content/chat/rooms/reactions.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/chat/rooms/reactions.textile b/content/chat/rooms/reactions.textile index 473f52324f..307a646903 100644 --- a/content/chat/rooms/reactions.textile +++ b/content/chat/rooms/reactions.textile @@ -150,5 +150,5 @@ const MyComponent = () => { try await room.reactions.send(params: .init(type: "like")) try await room.reactions.send(params: .init(type: "heart", - metadata: ["effect": .string("fireworks")])) + metadata: ["effect": "fireworks"])) ```