diff --git a/content/chat/setup.textile b/content/chat/setup.textile index 27cf84318e..269770cc34 100644 --- a/content/chat/setup.textile +++ b/content/chat/setup.textile @@ -5,6 +5,7 @@ product: chat languages: - javascript - react + - swift --- Use these instructions to install, authenticate and instantiate the Chat SDK. @@ -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 @@ -81,7 +83,32 @@ blang[javascript]. ``` -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@. + + Please note the version listed in the language dropdown selector on this page corresponds to the Ably Pub/Sub SDK version, and not the Chat SDK version. Information on the latest Chat SDK release can be found at "https://github.com/ably/ably-chat-swift":https://github.com/ably/ably-chat-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 AblyChat 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 @@ -90,7 +117,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] @@ -111,13 +138,27 @@ const App = () => { }; ``` +```[swift] +let realtimeOptions = ARTClientOptions() +realtimeOptions.key = "{{API_KEY}}" +realtimeOptions.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 @@ -145,7 +186,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 = "" +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: