Skip to content

Commit

Permalink
Updates the Chat setup page to include setup instructions for chat-swift
Browse files Browse the repository at this point in the history
  • Loading branch information
umair-ably authored and maratal committed Dec 4, 2024
1 parent 278b5c9 commit bbfe712
Showing 1 changed file with 79 additions and 27 deletions.
106 changes: 79 additions & 27 deletions content/chat/setup.textile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ product: chat
languages:
- javascript
- react
- swift
---

Use these instructions to install, authenticate and instantiate the Chat SDK.
Expand Down Expand Up @@ -43,28 +44,29 @@ h2(#install). Install

The Chat SDK is built on top of the Ably Pub/Sub SDK and uses that to establish a connection with Ably.

Both SDKs are available as NPM modules and via CDN.

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';
```
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';
import { ChatClientProvider } from '@ably/chat/react';
```

```[react]
import * as Ably from 'ably';
import { ChatClient } from '@ably/chat';
import { ChatClientProvider } from '@ably/chat/react';
```
blang[swift].

blang[javascript].
h3(#cdn). CDN
Expand All @@ -81,7 +83,30 @@ blang[javascript].
</script>
```

blang[react].
blang[react,swift].

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

The SDK is distributed as a Swift Package and can be installed using Xcode or by adding it as a dependency in your package’s @Package.swift@.

To install the @ably-chat-swift@ package in your Xcode Project:
* Paste @https://github.com/ably/ably-chat-swift@ in the Swift Packages search box (Xcode project → Swift Packages.. . → @+@ button).
* Select the Ably Chat SDK for your target.

To install the @ably-chat-swift@ package in another Swift Package, add the following to your @Package.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

Expand All @@ -90,7 +115,7 @@ Instantiate a realtime client using the Pub/Sub SDK and pass the generated clien
blang[react].
Pass the @ChatClient@ into the "@ChatClientProvider@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat_react.ChatClientProvider.html. The @ChatClient@ instance will be available to all child components in your React component tree.

blang[javascript].
blang[javascript,swift].


```[javascript]
Expand All @@ -111,13 +136,27 @@ const App = () => {
};
```

```[swift]
let realtimeOptions = ARTClientOptions()
realtimeOptions.key = "<API_KEY>"
realtimeOptions.clientId = "<clientId>"
let realtime = ARTRealtime(options: realtimeOptions)
let chatClient = DefaultChatClient(realtime: realtime, clientOptions: nil)
```

A "@ClientOptions@":/api/realtime-sdk#client-options object may be passed to the Pub/Sub SDK instance to further customize the connection, however at a minimum you must set an API key and provide a @clientId@ to ensure that the client is "identified":/auth/identified-clients.

Additional options can also be passed to the Chat client to customize the following properties:

|_. Property |_. Description |
| logHandler | The function to call for each line of "log output":#logging. The default is @console.log@. |
| logLevel | The verbosity of the "log output":#logging. Options are; @trace@, @debug@, @info@, @warn@, @error@ or @silent@. The default is @error@. |
blang[javascript,react].
|_. Property |_. Description |
| logHandler | The function to call for each line of "log output":#logging. The default is @console.log@. |
| logLevel | The verbosity of the "log output":#logging. Options are; @trace@, @debug@, @info@, @warn@, @error@ or @silent@. The default is @error@. |

blang[swift].
|_. Property |_. Description |
| logHandler | This is your own custom log handler conforming to the @LogHandler@ protocol. A single @log@ function is called for each line of "log output":#logging. The default implementation uses Swift's @Logger@. |
| logLevel | The verbosity of the "log output":#logging. Options are; @.trace@, @.debug@, @.info@, @.warn@, @.error@ or @.silent@. The default is @.error@. |

h2(#logging). Logging

Expand Down Expand Up @@ -145,7 +184,20 @@ const App = => {
};
```

The @logHandler@ property is your own function that will be called for each line of log output generated by the Chat SDK.
```[swift]
let realtimeOptions = ARTClientOptions()
realtimeOptions.key = "<API_KEY>"
realtimeOptions.clientId = "<clientId>"
let realtime = ARTRealtime(options: realtimeOptions)
let clientOptions = ClientOptions(logHandler: SomeLogHandler(), logLevel: .debug)
return DefaultChatClient(realtime: realtime, clientOptions: clientOptions)
```

blang[javascript,react].
The @logHandler@ property is your own function that will be called for each line of log output generated by the Chat SDK.

blang[swift].
The @logHandler@ property is your custom @LogHandler@ implementation that will be called for each line of log output generated by the Chat SDK.

The @logLevel@ sets the verbosity of logs that will be output by the SDK. The following log levels are available to set:

Expand Down

0 comments on commit bbfe712

Please sign in to comment.