Skip to content

Call client life cycle

Marco Brescianini edited this page Nov 5, 2024 · 12 revisions

The following guide will teach you how to handle the call client lifecycle for the 4.0 version, if you are looking for the 3.x version take a look a this guide instead.

Conference

The Kaleyra Video SDK conference is the component managing the call capabilities of the SDK.

Table of contents

Lifecycle

The lifecycle of the Kaleyra Video conference begins after the configuration of the SDK. Once the SDK is configured, a conference object will be created and it will be accessible from the KaleyraVideo singleton instance. When the SDK is told to start connecting, it will try to connect to the KaleyraVideo platform and the conference object state will change reflecting the state of the connection with its services. While in the connected state, the SDK can place outgoing calls, receive incoming calls, and it can handle the state of any ongoing call. Whereas, while in any other state, it can't do such things, so outgoing calls cannot be started, incoming calls won't be received, and so on. When your app goes in background, the call client is paused automatically, closing any connection to the Kaleyra Video platform (unless there's a call in progress), and it resumes automatically when your app returns in foreground. As you might expect, while in those states the SDK cannot perform any task, nor it can receive incoming calls (unless you have integrated VoIP notifications in your app).

State changes

In order to be notified about conference connection state changes, you can and you should subscribe as a subscriber to the conference statePublisher The following code listing will show you how to subscribe as subscriber of the conference state publisher:

KaleyraVideo.instance.conference?.statePublisher.removeDuplicates().receive(on: DispatchQueue.main).sink { state in
    debugPrint("Conference state changed \(state)")
}.store(in: &subscriptions)

Note

Subscribers will be notified on a background queue unless you subscribe to a different scheduler

Calls

You can and you should also subscribe to the callPublisher property of the conference object to get notified when an incoming call is received via WebSocket or VoIP notifications, or when an outgoing call is ready to be presented to the end user.

KaleyraVideo.instance.conference?.callPublisher.compactMap({ $0 }).receive(on: DispatchQueue.main).sink { call in
    // Show the call user interface
}.store(in: &subscriptions)

Note

Subscribers will be notified on a background queue unless you subscribe to a different scheduler

What's next

Clone this wiki locally