diff --git a/content/chat/connect.textile b/content/chat/connect.textile index e5ca34079a..c5fb80cd83 100644 --- a/content/chat/connect.textile +++ b/content/chat/connect.textile @@ -71,14 +71,11 @@ blang[react]. 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: +blang[javascript,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 register a listener for status change updates: 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)); @@ -103,28 +100,28 @@ 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: + +blang[javascript,swift]. + To remove the connection status listener, call the @unsubscribe()@ function returned in the @subscribe()@ response: ```[javascript] off(); ``` - - Use the "@connection.status.offAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_js.ConnectionStatus.html#offAll method to remove all connection status listeners: - - ```[javascript] - chatClient.connection.status.offAll(); + + ```[swift] + subscription.unsubscribe() ``` blang[react]. -blang[swift]. - To stop the subscription from firing new status events, call its @unsubscribe()@ method: +blang[javascript]. + Use the "@connection.status.offAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_js.ConnectionStatus.html#offAll method to remove all connection status listeners: - ```[swift] - subscription.unsubscribe() + ```[javascript] + chatClient.connection.status.offAll(); ``` + +blang[react,swift]. h2(#discontinuity). Handle connection discontinuity @@ -170,15 +167,12 @@ for await error in subscription { blang[react]. -blang[javascript]. - Use the @off()@ function returned in the @onDiscontinuity()@ response to remove a listener: +blang[javascript,swift]. + Use the @unsubscribe()@ function returned in the @subscribeToDiscontinuities()@ response to remove a listener: ```[javascript] off(); ``` - -blang[swift]. - To cancel discontinuity subscribtion, call the provided @unsubscribe()@ method: ```[swift] subscription.unsubscribe() diff --git a/content/chat/rooms/index.textile b/content/chat/rooms/index.textile index 744b159266..3467be1d73 100644 --- a/content/chat/rooms/index.textile +++ b/content/chat/rooms/index.textile @@ -239,28 +239,44 @@ const MyComponent = () => { let status = try await room.status ``` -blang[javascript]. +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 method in a room to register a listener for status change updates: + Use the "@room.onStatusChange(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#onStatusChange method in a room to register a listener for status change updates: ```[javascript] const { off } = room.onStatusChange((change) => console.log(change)); ``` - To remove the room status listener, call the provided @off()@ function: + ```[swift] + let statusSubscription = try await room.onStatusChange(bufferingPolicy: .unbounded) + for await status in statusSubscription { + print("Room status: \(status)") + } + ``` + + To remove the room status listener, call the provided @unsubscribe()@ function: ```[javascript] off(); ``` + ```[swift] + statusSubscription.unsubscribe() + ``` + +blang[react]. + +blang[javascript]. Use the "@room.status.offAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_js.RoomStatus.html#offAll method to remove all room status listeners in a room: ```[javascript] room.status.offAll(); ``` +blang[swift]. + blang[react]. Listeners can also be registered to monitor the changes in room 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. @@ -279,19 +295,3 @@ 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 d74d82ed20..b25874ded1 100644 --- a/content/chat/rooms/messages.textile +++ b/content/chat/rooms/messages.textile @@ -12,17 +12,14 @@ You can send and receive messages in a chat room with any number of participants h2(#subscribe). Subscribe to messages -blang[javascript]. - 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 method in a room to receive all messages that are sent to it: +blang[javascript,swift]. + Subscribe to receive messages in a room by registering a listener. 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: 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. 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); @@ -80,10 +77,10 @@ The following are the properties of a message: h3(#unsubscribe). Unsubscribe from messages -blang[javascript]. +blang[javascript,swift]. Unsubscribe from messages to remove previously registered listeners. - Use the "@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_js.MessageSubscriptionResponse.html#unsubscribe function returned in the @subscribe()@ response to remove a listener: + Use the "@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.MessageSubscription.html#unsubscribe function returned in the @subscribe()@ response to remove a listener: ```[javascript] // Initial subscription @@ -93,21 +90,25 @@ blang[javascript]. unsubscribe(); ``` + ```[swift] + messagesSubscription.unsubscribe() + ``` + +blang[react]. + +blang[javascript]. Use the "@messages.unsubscribeAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_js.Messages.html#unsubscribeAll method to deregister all chat message listeners in a room: ```[javascript] await room.messages.unsubscribeAll(); ``` +blang[react,swift]. + 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() - ``` +blang[javascript,swift].