Skip to content

Commit aed9ab7

Browse files
maratalumair-ably
authored andcommitted
Added documentation comments (based on JS repo in 69ea478). Adopted to swift docc syntax.
1 parent c1915d4 commit aed9ab7

29 files changed

+1600
-41
lines changed

.github/workflows/check.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,39 @@ jobs:
178178
- name: Build example app
179179
run: swift run BuildTool build-example-app --platform ${{ matrix.platform }}
180180

181+
check-documentation:
182+
runs-on: macos-15
183+
steps:
184+
- uses: actions/checkout@v4
185+
with:
186+
submodules: true
187+
188+
# This step can be removed once the runners’ default version of Xcode is 16 or above
189+
- uses: maxim-lobanov/setup-xcode@v1
190+
with:
191+
xcode-version: 16
192+
193+
# Build the documentation using Swift DocC
194+
- name: Build documentation
195+
run: swift run BuildTool build-documentation
196+
197+
# Configure AWS credentials for uploading documentation
198+
- name: Configure AWS Credentials
199+
uses: aws-actions/configure-aws-credentials@v4
200+
with:
201+
aws-region: eu-west-2
202+
role-to-assume: arn:aws:iam::${{ secrets.ABLY_AWS_ACCOUNT_ID_SDK }}:role/ably-sdk-builds-ably-chat-swift
203+
role-session-name: "${{ github.run_id }}-${{ github.run_number }}"
204+
205+
# Upload the generated documentation
206+
- name: Upload Documentation
207+
uses: ably/sdk-upload-action@v2
208+
with:
209+
sourcePath: documentation # Path to the Swift DocC output folder
210+
githubToken: ${{ secrets.GITHUB_TOKEN }}
211+
artifactName: documentation # Optional root-level directory name
212+
213+
181214
# We use this job as a marker that all of the required checks have completed.
182215
# This allows us to configure a single required status check in our branch
183216
# protection rules instead of having to type loads of different check names
@@ -193,6 +226,7 @@ jobs:
193226
- build-and-test-xcode
194227
- build-release-configuration-xcode
195228
- check-example-app
229+
- check-documentation
196230

197231
steps:
198232
- name: No-op

AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ let package = Package(
3434
url: "https://github.com/JanGorman/Table.git",
3535
from: "1.1.1"
3636
),
37+
.package(
38+
url: "https://github.com/apple/swift-docc-plugin",
39+
from: "1.0.0"
40+
),
3741
],
3842
targets: [
3943
.target(

Sources/AblyChat/BufferingPolicy.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Describes what to do with realtime events that come in faster than the consumer of an `AsyncSequence` can handle them.
2-
// (This is the same as `AsyncStream<T>.Continuation.BufferingPolicy` but with the generic type parameter `T` removed.)
1+
/**
2+
* Describes what to do with realtime events that come in faster than the consumer of an `AsyncSequence` can handle them.
3+
* (This is the same as `AsyncStream<T>.Continuation.BufferingPolicy` but with the generic type parameter `T` removed.)
4+
*/
35
public enum BufferingPolicy: Sendable {
46
case unbounded
57
case bufferingOldest(Int)

Sources/AblyChat/ChatClient.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
11
import Ably
22

33
public protocol ChatClient: AnyObject, Sendable {
4+
/**
5+
* Returns the rooms object, which provides access to chat rooms.
6+
*
7+
* - Returns: The rooms object.
8+
*/
49
var rooms: any Rooms { get }
10+
11+
/**
12+
* Returns the underlying connection to Ably, which can be used to monitor the clients
13+
* connection to Ably servers.
14+
*
15+
* - Returns: The connection object.
16+
*/
517
var connection: any Connection { get }
18+
19+
/**
20+
* Returns the clientId of the current client.
21+
*
22+
* - Returns: The clientId.
23+
*/
624
var clientID: String { get }
25+
26+
/**
27+
* Returns the underlying Ably Realtime client.
28+
*
29+
* - Returns: The Ably Realtime client.
30+
*/
731
var realtime: RealtimeClient { get }
32+
33+
/**
34+
* Returns the resolved client options for the client, including any defaults that have been set.
35+
*
36+
* - Returns: The client options.
37+
*/
838
var clientOptions: ClientOptions { get }
939
}
1040

1141
public typealias RealtimeClient = any RealtimeClientProtocol
1242

43+
/**
44+
* This is the core client for Ably chat. It provides access to chat rooms.
45+
*/
1346
public actor DefaultChatClient: ChatClient {
1447
public let realtime: RealtimeClient
1548
public nonisolated let clientOptions: ClientOptions
@@ -20,6 +53,13 @@ public actor DefaultChatClient: ChatClient {
2053
// (CHA-CS4) The chat client must allow its connection status to be observed by clients.
2154
public nonisolated let connection: any Connection
2255

56+
/**
57+
* Constructor for Chat
58+
*
59+
* - Parameters:
60+
* - realtime: The Ably Realtime client.
61+
* - clientOptions: The client options.
62+
*/
2363
public init(realtime: RealtimeClient, clientOptions: ClientOptions?) {
2464
self.realtime = realtime
2565
self.clientOptions = clientOptions ?? .init()
@@ -34,8 +74,22 @@ public actor DefaultChatClient: ChatClient {
3474
}
3575
}
3676

77+
/**
78+
* Configuration options for the chat client.
79+
*/
3780
public struct ClientOptions: Sendable {
81+
/**
82+
* A custom log handler that will be used to log messages from the client.
83+
*
84+
* By default, the client will log messages to the console.
85+
*/
3886
public var logHandler: LogHandler?
87+
88+
/**
89+
* The minimum log level at which messages will be logged.
90+
*
91+
* By default, ``LogLevel/error`` will be used.
92+
*/
3993
public var logLevel: LogLevel?
4094

4195
public init(logHandler: (any LogHandler)? = nil, logLevel: LogLevel? = nil) {

Sources/AblyChat/Connection.swift

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
import Ably
22

3+
/**
4+
* Represents a connection to Ably.
5+
*/
36
public protocol Connection: AnyObject, Sendable {
7+
/**
8+
* The current status of the connection.
9+
*/
410
var status: ConnectionStatus { get async }
11+
512
// TODO: (https://github.com/ably-labs/ably-chat-swift/issues/12): consider how to avoid the need for an unwrap
13+
/**
14+
* The current error, if any, that caused the connection to enter the current status.
15+
*/
616
var error: ARTErrorInfo? { get async }
17+
18+
/**
19+
* Subscribes a given listener to a connection status changes.
20+
*
21+
* - Parameters:
22+
* - bufferingPolicy: The ``BufferingPolicy`` for the created subscription.
23+
*
24+
* - Returns: A subscription `AsyncSequence` that can be used to iterate through ``ConnectionStatusChange`` events.
25+
*/
726
func onStatusChange(bufferingPolicy: BufferingPolicy) -> Subscription<ConnectionStatusChange>
8-
/// Same as calling ``onStatusChange(bufferingPolicy:)`` with ``BufferingPolicy.unbounded``.
27+
28+
/// Same as calling ``onStatusChange(bufferingPolicy:)`` with ``BufferingPolicy/unbounded``.
929
///
1030
/// The `Connection` protocol provides a default implementation of this method.
1131
func onStatusChange() -> Subscription<ConnectionStatusChange>
@@ -17,18 +37,50 @@ public extension Connection {
1737
}
1838
}
1939

40+
/**
41+
* The different states that the connection can be in through its lifecycle.
42+
*/
2043
public enum ConnectionStatus: Sendable {
2144
// (CHA-CS1a) The INITIALIZED status is a default status when the realtime client is first initialized. This value will only (likely) be seen if the realtime client doesn’t have autoconnect turned on.
45+
46+
/**
47+
* A temporary state for when the library is first initialized.
48+
*/
2249
case initialized
50+
2351
// (CHA-CS1b) The CONNECTING status is used when the client is in the process of connecting to Ably servers.
52+
53+
/**
54+
* The library is currently connecting to Ably.
55+
*/
2456
case connecting
57+
2558
// (CHA-CS1c) The CONNECTED status is used when the client connected to Ably servers.
59+
60+
/**
61+
* The library is currently connected to Ably.
62+
*/
2663
case connected
64+
2765
// (CHA-CS1d) The DISCONNECTED status is used when the client is not currently connected to Ably servers. This state may be temporary as the underlying Realtime SDK seeks to reconnect.
66+
67+
/**
68+
* The library is currently disconnected from Ably, but will attempt to reconnect.
69+
*/
2870
case disconnected
71+
2972
// (CHA-CS1e) The SUSPENDED status is used when the client is in an extended state of disconnection, but will attempt to reconnect.
73+
74+
/**
75+
* The library is in an extended state of disconnection, but will attempt to reconnect.
76+
*/
3077
case suspended
78+
3179
// (CHA-CS1f) The FAILED status is used when the client is disconnected from the Ably servers due to some non-retriable failure such as authentication failure. It will not attempt to reconnect.
80+
81+
/**
82+
* The library is currently disconnected from Ably and will not attempt to reconnect.
83+
*/
3284
case failed
3385

3486
internal init(from realtimeConnectionState: ARTRealtimeConnectionState) {
@@ -51,11 +103,30 @@ public enum ConnectionStatus: Sendable {
51103
}
52104
}
53105

106+
/**
107+
* Represents a change in the status of the connection.
108+
*/
54109
public struct ConnectionStatusChange: Sendable {
110+
/**
111+
* The new status of the connection.
112+
*/
55113
public var current: ConnectionStatus
114+
115+
/**
116+
* The previous status of the connection.
117+
*/
56118
public var previous: ConnectionStatus
119+
57120
// TODO: (https://github.com/ably-labs/ably-chat-swift/issues/12): consider how to avoid the need for an unwrap
121+
/**
122+
* An error that provides a reason why the connection has
123+
* entered the new status, if applicable.
124+
*/
58125
public var error: ARTErrorInfo?
126+
127+
/**
128+
* The time in milliseconds that the client will wait before attempting to reconnect.
129+
*/
59130
public var retryIn: TimeInterval
60131

61132
public init(current: ConnectionStatus, previous: ConnectionStatus, error: ARTErrorInfo? = nil, retryIn: TimeInterval) {

Sources/AblyChat/Dependencies.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public protocol RealtimeClientProtocol: ARTRealtimeProtocol, Sendable {
1414
var connection: Connection { get }
1515
}
1616

17-
/// Expresses the requirements of the object returned by ``RealtimeClientProtocol.channels``.
17+
/// Expresses the requirements of the object returned by ``RealtimeClientProtocol/channels``.
1818
public protocol RealtimeChannelsProtocol: ARTRealtimeChannelsProtocol, Sendable {
1919
associatedtype Channel: RealtimeChannelProtocol
2020

2121
// It’s not clear to me why ARTRealtimeChannelsProtocol doesn’t include this function (https://github.com/ably/ably-cocoa/issues/1968).
2222
func get(_ name: String, options: ARTRealtimeChannelOptions) -> Channel
2323
}
2424

25-
/// Expresses the requirements of the object returned by ``RealtimeChannelsProtocol.get(_:)``.
25+
/// Expresses the requirements of the object returned by ``RealtimeChannelsProtocol/get(_:options:)``.
2626
public protocol RealtimeChannelProtocol: ARTRealtimeChannelProtocol, Sendable {}
2727

2828
public protocol ConnectionProtocol: ARTConnectionProtocol, Sendable {}

Sources/AblyChat/EmitsDiscontinuities.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@ public struct DiscontinuityEvent: Sendable, Equatable {
99
}
1010
}
1111

12+
/**
13+
* An interface to be implemented by objects that can emit discontinuities to listeners.
14+
*/
1215
public protocol EmitsDiscontinuities {
16+
/**
17+
* Subscribes a given listener to a detected discontinuity.
18+
*
19+
* - Parameters:
20+
* - bufferingPolicy: The ``BufferingPolicy`` for the created subscription.
21+
*
22+
* - Returns: A subscription `AsyncSequence` that can be used to iterate through ``DiscontinuityEvent`` events.
23+
*/
1324
func onDiscontinuity(bufferingPolicy: BufferingPolicy) async -> Subscription<DiscontinuityEvent>
14-
/// Same as calling ``onDiscontinuity(bufferingPolicy:)`` with ``BufferingPolicy.unbounded``.
25+
26+
/// Same as calling ``onDiscontinuity(bufferingPolicy:)`` with ``BufferingPolicy/unbounded``.
1527
///
1628
/// The `EmitsDiscontinuities` protocol provides a default implementation of this method.
1729
func onDiscontinuity() async -> Subscription<DiscontinuityEvent>

0 commit comments

Comments
 (0)