Skip to content

Commit

Permalink
Put listener terminology in swift in lieu to "create subscription".
Browse files Browse the repository at this point in the history
  • Loading branch information
maratal committed Dec 5, 2024
1 parent 8358e84 commit 868ea84
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 106 deletions.
36 changes: 15 additions & 21 deletions content/chat/connect.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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:

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));
Expand All @@ -103,29 +100,29 @@ 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 <span lang="javascript">@off()@</span><span lang="swift">@unsubscribe()@</span> 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

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.
Expand Down Expand Up @@ -170,16 +167,13 @@ 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 <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:

```[javascript]
off();
```

blang[swift].
To cancel discontinuity subscribtion, call the provided @unsubscribe()@ method:

```[swift]
subscription.unsubscribe()
```
Expand Down
38 changes: 19 additions & 19 deletions content/chat/rooms/index.textile
Original file line number Diff line number Diff line change
Expand Up @@ -240,28 +240,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 <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:

```[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 <span lang="javascript">@off()@</span><span lang="swift">@unsubscribe()@</span> 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.

Expand All @@ -280,19 +296,3 @@ blang[react].
return <div>Occupancy Component</div>;
};
```

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()
```
27 changes: 14 additions & 13 deletions content/chat/rooms/messages.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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:

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);
Expand Down Expand Up @@ -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 <span lang="javascript">"@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.MessageSubscriptionResponse.html#unsubscribe</span><span lang="swift">"@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.MessageSubscription.html#unsubscribe</span> function returned in the @subscribe()@ response to remove a listener:

```[javascript]
// Initial subscription
Expand All @@ -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].

<aside data-type='note'>
<p>There is a difference between unsubscribing from messages and detaching from a room that is important to understand. </p>
Expand Down
29 changes: 15 additions & 14 deletions content/chat/rooms/occupancy.textile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ Occupancy enables you to view the number of users currently online in a room. Th

h2(#subscribe). Subscribe to room occupancy

blang[javascript].
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 method in a room to receive updates:
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 <span lang="javascript">"@occupancy.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#subscribe</span><span lang="swift">"@occupancy.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#subscribe</span> 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.

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);
Expand Down Expand Up @@ -84,10 +81,10 @@ The following are the properties of an occupancy event:

h3(#unsubscribe). Unsubscribe from room occupancy

blang[javascript].
blang[javascript,swift].
Unsubscribe from room occupancy to remove previously registered listeners.

Use the "@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.OccupancySubscriptionResponse.html#unsubscribe function returned in the @subscribe()@ response to remove a listener:
Use the <span lang="javascript">"@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.OccupancySubscriptionResponse.html#unsubscribe</span><span lang="swift">"@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.OccupancySubscriptionResponse.html#unsubscribe</span> function returned in the @subscribe()@ response to remove a listener:

```[javascript]
// Initial subscription
Expand All @@ -99,28 +96,32 @@ blang[javascript].
unsubscribe();
```

```[swift]
occupancySubscription.unsubscribe()
```

blang[react].

blang[javascript].
Use the "@occupancy.unsubscribeAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#unsubscribeAll method to remove all occupancy listeners in a room:

```[javascript]
await room.occupancy.unsubscribeAll();
```

blang[react,swift].

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()
```
blang[javascript,swift].

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 method to retrieve the occupancy of a room:
Use the <span lang="javascript">"@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#get</span><span lang="swift">"@occupancy.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Occupancy.html#get</span> method to retrieve the occupancy of a room:

```[javascript]
const occupancy = await room.occupancy.get();
Expand Down
27 changes: 14 additions & 13 deletions content/chat/rooms/presence.textile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ Subscribe to the online status of room members using the presence feature. Prese

h2(#subscribe). Subscribe to presence

blang[javascript].
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 method in a room to receive updates:
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 <span lang="javascript">"@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#subscribe</span><span lang="swift">"@presence.subscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.Presence.html#subscribe</span> 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.

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}`);
Expand Down Expand Up @@ -116,10 +113,10 @@ The following are the properties of a presence event:

h3(#unsubscribe). Unsubscribe from presence

blang[javascript].
blang[javascript,swift].
Unsubscribe from online presence to remove previously registered listeners.

Use the "@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.PresenceSubscriptionResponse.html#unsubscribe function returned in the @subscribe()@ response to remove a listener:
Use the <span lang="javascript">"@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.PresenceSubscriptionResponse.html#unsubscribe</span><span lang="swift">"@unsubscribe()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/typedoc/interfaces/chat.PresenceSubscription.html#unsubscribe</span> function returned in the @subscribe()@ response to remove a listener:

```[javascript]
// Initial subscription
Expand All @@ -131,21 +128,25 @@ blang[javascript].
unsubscribe();
```

```[swift]
presenceSubscription.unsubscribe()
```

blang[react].

blang[javascript].
Use the "@presence.unsubscribeAll()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#unsubscribeAll method to remove all presence listeners in a room:

```[javascript]
await room.presence.unsubscribeAll();
```

blang[react,swift].

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()
```
blang[javascript,swift].

h2(#set). Set user presence

Expand Down
Loading

0 comments on commit 868ea84

Please sign in to comment.