Link Search Menu Expand Document

livedigital Chat SDK usage: getting started

See README for integration instructions. Further steps assume you have successfully integrated the SDK and host application project can be built as normally.

  1. Choose or create a class in your app that will be the main livedigital Chat service client. Let’s call it ChatCoordinator. Some terms from Coordinator pattern are used in the example, but both Core and UI of the livedigital Chat may be used in app with any presentation layer architecture.

  2. In the beginning of ChatCoordinator.swift file, import the SDK module:

     import livedigitalChatSDK
    
  3. Create an instance of the livedigital Chat core and store it as a property in your client class:

     final class ChatCoordinator {
         private let chatCore: ChatCore
    
         init() {
             let authenticator = ExternalAuthenticator()
             self.chatCore = StockChatCore(authenticator: authenticator)
             authenticator.delegate = self
         }
     }
    
  4. Implement ExternalAuthenticator delegate protocol to provide fresh authorization token when it’s requested:

     extension ChatCoordinator: ExternalAuthenticatorDelegate {
         func fetchToken(_ completion: @escaping DataCompletion<AuthToken, Error>) {
                 let token = AuthToken(value: "token_string_provided_by_your_auth_server")
                 completion(.success(token))
             }
         }
     }
    

    To use this flow, you should have some sort of authorization in your app and integrate with the livedigital Chat M2M API on your server side. There are other authorization schemes to use livedigital Chat as a stand-alone solution. See Authorization for details.

  5. Display channels list screen:

     let channelsListVC = ChannelsListVC(channelsList: chatCore.channels)
     channelsListVC.delegate = self
     router.present(channelsListVC)
    
  6. Adopt ChannelsListVCDelegate protocol to implement routing to the selected channel. Display channel screen:

     extension ViewController: ChannelsListVCDelegate {
         func channelSelected(_ channelsListItem: ChannelsListItem, in list: ChannelsListVC) {
             let channel = chatCore.channel(for: channelsListItem)
             let channelVC = ChannelVC(channel: channel)
             router.present(channelVC)
         }
     }
    

This document describes basic scenario for integrating livedigital Chat into your application. It involves using a predefined UI of the chat. See UI customization document for details on applying custom styles and colors or Using Core layer directly if you want to incorporate chat functionality into existing UI or implement some other kind of deep integration.