SippoClient

This section explains how to create and register a SippoClient

First step needed is configure client with backend url

SippoClient.configure(url: "https://www.mywac.es")

At this point we need Auth class to authenticate an User, we can use token, basic or anonymous authenticate method, and as response receives a task with a Bool or SippoClientError

SippoClient.client.auth.connect(authentication: .anonymous) { task in
    switch task {
    case let .success(registered):
        if (registered) {
            print("I'm registered")
        }
    case let .error(error):
        print("An error ocurred: \(error)")
    }
}

In case we use Wac as oauth provider we should request a token to /sapi/o/token and pass the given token with token authentication

An example for requesting the token

func requestToken(for user: String, using password: String, completionBlock: @escaping (String) -> ()) {
    var request = URLRequest(url: URL(string: "https://wac/sapi/o/token")!)
    request.httpMethod = "POST"
    let body = ["grant_type": "password", "username": user, "password": password]
    request.httpBody = try! JSONSerialization.data(withJSONObject: body, options: [])

    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    request.addValue("application/json", forHTTPHeaderField: "Accept")

    let task = URLSession.shared.dataTask(with: request) { data, response, error in
        guard let dataReceived = data, let token = JSON(dataReceived).dictionaryObject else {
            print("Error: \(String(describing: error?.localizedDescription))")
            return
        }
        completionBlock(token["access_token"]! as! String)
    }
    task.resume()
}

requestToken(for: "User1", using: "password") { token in

//Once we get the token use token authentication

    SippoClient.client.auth.connect(authentication: .token(token: token, provider: "wac")) { task in
        switch task {
        case let .success(registered):
            if (registered) {
                print("I'm registered")
            }
        case let .error(error):
            print("An error ocurred: \(error)")
        }
    }
}

To receive state changes in SippoClient we need to set a delegate ClientStateDelegate

class ClientStateDelegateExample: ClientStateDelegate {
    func onStateChanged(_ sessionState: SessionState) {

    }
}
let delegate = ClientStateDelegateExample()
SippoClient.client.delegate = delegate

To close SippoClient session send logout action with Auth class

SippoClient.client.auth.logout()

SippoClient.configure creates a new client accesible from SippoClient.client, but other clients still alive, so SippoClient.client.auth.logout is required to clean a Session

Call SippoClient.client.auth.connect is a must to access the other services (Invitations, Conferences..)