Skip to content

Commit

Permalink
Updated to the recent swift API changes to fit JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
maratal committed Dec 5, 2024
1 parent 868ea84 commit 3ca59a6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions content/chat/connect.textile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ blang[react].
blang[javascript,swift].

blang[javascript,swift].
Use the <span lang="javascript">"@connection.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#onChange</span><span lang="swift">"@connection.onStatusChange(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Connection.html#onStatusChange</span> method to register a listener for status change updates:
Use the <span lang="javascript">"@connection.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#onChange</span><span lang="swift">"@connection.onStatusChange()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Connection.html#onStatusChange</span> 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.
Expand All @@ -95,7 +95,7 @@ const MyComponent = () => {
```

```[swift]
let subscription = chatClient.connection.onStatusChange(bufferingPolicy: .unbounded)
let subscription = chatClient.connection.onStatusChange()
for await statusChange in subscription {
print("Connection status changed to: \(statusChange.current)")
}
Expand Down Expand Up @@ -130,7 +130,7 @@ If a client briefly loses connection to Ably, for example when driving through a
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,swift].
Each feature of the Chat SDK provides an <span lang="javascript">@onDiscontinuity()@</span><span lang="swift">@subscribeToDiscontinuities()@</span> 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.
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[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.
Expand Down Expand Up @@ -159,7 +159,7 @@ const MyComponent = () => {
```

```[swift]
let subscription = room.messages.subscribeToDiscontinuities()
let subscription = room.messages.onDiscontinuity()
for await error in subscription {
print("Recovering from the error: \(error)")
}
Expand All @@ -168,7 +168,7 @@ for await error in subscription {
blang[react].

blang[javascript,swift].
Use the <span lang="javascript">@off()@</span><span lang="swift">@unsubscribe()@</span> function returned in the <span lang="javascript">@onDiscontinuity()@</span><span lang="swift">@subscribeToDiscontinuities()@</span> response to remove a listener:
Use the <span lang="javascript">@off()@</span><span lang="swift">@unsubscribe()@</span> function returned in the @onDiscontinuity()@ response to remove a listener:

```[javascript]
off();
Expand All @@ -191,8 +191,8 @@ blang[javascript].
* "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
* "Messages":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#onDiscontinuity
* "Presence":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#onDiscontinuity
* "Occupancy":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#onDiscontinuity
* "Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#onDiscontinuity
* "Room reactions":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#onDiscontinuity
2 changes: 1 addition & 1 deletion content/chat/rooms/history.textile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const MyComponent = () => {
```

```[swift]
let messagesSubscription = try await room.messages.subscribe(bufferingPolicy: .unbounded)
let messagesSubscription = try await room.messages.subscribe()
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 {
Expand Down
4 changes: 2 additions & 2 deletions content/chat/rooms/index.textile
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ 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 <span lang="javascript">"@room.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#onChange</span><span lang="swift">"@room.onStatusChange(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#onStatusChange</span> method in a room to register a listener for status change updates:
Use the <span lang="javascript">"@room.status.onChange()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomStatus.html#onChange</span><span lang="swift">"@room.onStatusChange()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Room.html#onStatusChange</span> method in a room to register a listener for status change updates:

```[javascript]
const { off } = room.onStatusChange((change) =>
console.log(change));
```

```[swift]
let statusSubscription = try await room.onStatusChange(bufferingPolicy: .unbounded)
let statusSubscription = try await room.onStatusChange()
for await status in statusSubscription {
print("Room status: \(status)")
}
Expand Down
4 changes: 2 additions & 2 deletions content/chat/rooms/messages.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span lang="javascript">"@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#subscribe</span><span lang="swift">"@messages.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribe</span> 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 <span lang="javascript">"@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#subscribe</span><span lang="swift">"@messages.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#subscribe</span> 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.
Expand Down Expand Up @@ -42,7 +42,7 @@ const MyComponent = () => {
```

```[swift]
let messagesSubscription = try await room.messages.subscribe(bufferingPolicy: .unbounded)
let messagesSubscription = try await room.messages.subscribe()
for await message in messagesSubscription {
print("Message received: \(message)")
}
Expand Down
2 changes: 1 addition & 1 deletion content/chat/rooms/occupancy.textile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {unsubscribe} = room.occupancy.subscribe((event) => {
```

```[swift]
let occupancySubscription = try await room.occupancy.subscribe(bufferingPolicy: .unbounded)
let occupancySubscription = try await room.occupancy.subscribe()
for await event in occupancySubscription {
occupancyInfo = "Connections: \(event.presenceMembers) (\(event.connections))"
}
Expand Down
4 changes: 2 additions & 2 deletions content/chat/rooms/reactions.textile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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,swift].
Subscribe to room reactions by registering a listener. Use the <span lang="javascript">"@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe</span><span lang="swift">"@reactions.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribe</span> method in a room to receive reactions:
Subscribe to room reactions by registering a listener. Use the <span lang="javascript">"@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#subscribe</span><span lang="swift">"@reactions.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#subscribe</span> 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.
Expand All @@ -46,7 +46,7 @@ const MyComponent = () => {
```

```[swift]
let reactionSubscription = try await room.reactions.subscribe(bufferingPolicy: .unbounded)
let reactionSubscription = try await room.reactions.subscribe()
for await reaction in reactionSubscription {
print("Received a reaction of type \(reaction.type), and metadata \(reaction.metadata)")
}
Expand Down
4 changes: 2 additions & 2 deletions content/chat/rooms/typing.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span lang="javascript">"@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#subscribe</span><span lang="swift">"@typing.subscribe(bufferingPolicy: .unbounded)@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#subscribe</span> 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 <span lang="javascript">"@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#subscribe</span><span lang="swift">"@typing.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#subscribe</span> 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.
Expand Down Expand Up @@ -48,7 +48,7 @@ const MyComponent = () => {
```

```[swift]
let typingSubscription = try await room.typing.subscribe(bufferingPolicy: .unbounded)
let typingSubscription = try await room.typing.subscribe()
for await typing in typingSubscription {
typingInfo = typing.currentlyTyping.isEmpty ? "" :
"Typing: \(typing.currentlyTyping.joined(separator: ", "))..."
Expand Down

0 comments on commit 3ca59a6

Please sign in to comment.