Skip to content

Commit

Permalink
fixup! Updated to the recent swift API changes to fit JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-hulbert committed Dec 6, 2024
1 parent 3ca59a6 commit 4417090
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 49 deletions.
31 changes: 10 additions & 21 deletions content/chat/connect.textile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ A connection can have any of the following statuses:
| suspended | A long term failure condition when no current connection exists because there is no network connectivity or available host. The suspended status is entered after a failed connection attempt if there has then been no connection for a period of two minutes. In the suspended status, an SDK will periodically attempt to open a new connection every 30 seconds. Rooms will be reattached on a successful reconnection, however message history will not be automatically recovered. |
| failed | This status is entered if the SDK encounters a failure condition that it cannot recover from. This may be a fatal connection error received from the Ably service, such as an attempt to connect with an incorrect API key, or some local terminal error, such as that the token in use has expired and the SDK does not have any way to renew it. |

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[javascript,swift].
Use the <span lang="javascript">"@current@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.ConnectionStatus.html#current</span><span lang="swift">"@status@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.ConnectionStatus.html#status</span> 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:
Expand Down Expand Up @@ -76,7 +73,7 @@ blang[javascript,swift].

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.

```[javascript]
const { off } = chatClient.connection.status.onStatusChange((change) => console.log(change));
```
Expand Down Expand Up @@ -178,21 +175,13 @@ blang[javascript,swift].
subscription.unsubscribe()
```

blang[react].

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#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
* <span lang="javascript">"Messages":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#onDiscontinuity</span><span lang="swift">"Messages":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Messages.html#onDiscontinuity</span>
* <span lang="javascript">"Presence":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#onDiscontinuity</span><span lang="swift">"Presence":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#onDiscontinuity</span>
* <span lang="javascript">"Occupancy":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#onDiscontinuity</span><span lang="swift">"Occupancy":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#onDiscontinuity</span>
* <span lang="javascript">"Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#onDiscontinuity</span><span lang="swift">"Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Typing.html#onDiscontinuity</span>
* <span lang="javascript">"Room reactions":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#onDiscontinuity</span><span lang="swift">"Room reactions":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.RoomReactions.html#onDiscontinuity</span>
10 changes: 5 additions & 5 deletions content/chat/rooms/messages.textile
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ blang[react].

blang[javascript,swift].

<aside data-type='note'>
<p>There is a difference between unsubscribing from messages and detaching from a room that is important to understand. </p>
<p>Messages are sent to users as soon as they "attach":/chat/rooms#attach to a room, irrespective of whether a listener has been registered by calling @subscribe()@. Calling @unsubscribe()@ only deregisters the listener.</p>
<p>The "@detach()@":/chat/rooms#detach method detaches a user from the room. At that point a user will no longer receive any messages that are sent to the room.</p>
</aside>
<aside data-type='note'>
<p>There is a difference between unsubscribing from messages and detaching from a room that is important to understand. </p>
<p>Messages are sent to users as soon as they "attach":/chat/rooms#attach to a room, irrespective of whether a listener has been registered by calling @subscribe()@. Calling @unsubscribe()@ only deregisters the listener.</p>
<p>The "@detach()@":/chat/rooms#detach method detaches a user from the room. At that point a user will no longer receive any messages that are sent to the room.</p>
</aside>

h2(#send). Send a message

Expand Down
4 changes: 1 addition & 3 deletions content/chat/rooms/presence.textile
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ blang[javascript,swift].
```

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 <span lang="javascript">"@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#isUserPresent</span><span lang="swift">"@presence.isUserPresent()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#isUserPresent</span> method and pass in a user's @clientId@ to check whether they are online or not. This will return a boolean:
Expand All @@ -311,9 +312,6 @@ blang[javascript,swift].
```

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

Expand Down
10 changes: 3 additions & 7 deletions content/chat/rooms/reactions.textile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ 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,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()@":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.

```[javascript]
const {unsubscribe} = room.reactions.subscribe((reaction) => {
console.log(`Received a reaction of type ${reaction.type}, and metadata ${reaction.metadata}`);
Expand Down Expand Up @@ -101,6 +99,7 @@ blang[javascript,swift].
```

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[javascript].
Use the "@reactions.unsubscribeAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#unsubscribeAll method to remove all reaction listeners in a room:
Expand All @@ -109,10 +108,7 @@ blang[javascript].
await room.reactions.unsubscribeAll();
```

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[javascript,swift].
blang[react,swift].

h2(#send). Send a room reaction

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 @@ -8,7 +8,7 @@ languages:
- 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 events can be emitted when a user starts or stops 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 are emitted whenever a user starts or stops typing.

<aside data-type='note'>
<p>Typing indicators need to be "enabled":/chat/rooms#create when creating or retrieving a room.</p>
Expand Down Expand Up @@ -91,7 +91,7 @@ blang[javascript,swift].
// To remove the listener
unsubscribe();
```

```[swift]
typingSubscription.unsubscribe()
```
Expand Down
17 changes: 6 additions & 11 deletions content/chat/setup.textile
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ The Chat SDK is built on top of the Ably Pub/Sub SDK and uses that to establish

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';
Expand Down Expand Up @@ -111,8 +111,6 @@ blang[javascript].
</script>
```

blang[react,swift].

blang[swift].
h3(#spm). Swift Package Manager

Expand All @@ -127,15 +125,13 @@ blang[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

Instantiate a realtime client using the Pub/Sub SDK and pass the generated client into the Chat constructor.
Expand All @@ -145,7 +141,6 @@ blang[react].

blang[javascript,swift].


```[javascript]
const realtimeClient = new Ably.Realtime({ key: '{{API_KEY}}', clientId: '<clientId>'});
const chatClient = new ChatClient(realtimeClient);
Expand Down

1 comment on commit 4417090

@maratal
Copy link
Collaborator

@maratal maratal commented on 4417090 Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.