Make a Video Call with iOS SDK

iOS SDK Integration Architecture

The iOS SDK is a fast and effective way to include a live video chat in a mobile application. The SDK makes it easy to embed one to one, many to many high-quality voice and video calls into your mobile app, with a seamless integration with the Android/iOS operating system. It features a fully fledged set of collaborative tools comprehensive of: messaging, screen sharing, remote snapshot, collaborative interactive board and call recording capabilities.

The following diagram represents the most common integration layout of the Mobile SDK and the section following the diagram elaborates on the flow:

📘

Note:

The access token used by the SDK is obtained on the server side. This implementation ensures that the apiKey is not shared publicly, and the access token is bound to the user session on the integrated website.

Using the apiKey on the client side is strongly discouraged and should be absolutely avoided in production.

1. Authenticate User

The user accesses the application by leveraging an authentication method of choice. User authentication is done externally from Kaleyra Video.

2. Obtain Access Token

To access Kaleyra SDK services an access token is required.

This operation is usually done in the context of user authentication so that the access token is returned to the client along with the user information. Alternatively, it can be retrieved at a later time. This is an implementation choice.

A back-end service needs to call the API Generate SDK Credentials passing the following payload and using the appropriate userId.

{
   "user_id": "user id",
   "expires_in": 3600
}
{
    "access_token": 
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoidGVzdCIsImNvbXBhbnlJZCI6IjEzM2Q0MmNlLWVkZGItMTFlNi05OTUzLTAyMTI0YWI0M2Q2NyIsImFsbG93Q2FtZXJhIjp0cnVlLCJpYXQiOjE2NTEwNTQ4MjEsImV4cCI6MTY1MTA1ODQyMSwiaXNzIjoiQHN3aXRjaGJvYXJkLWNvcmUiLCJzdWIiOiJ0ZXN0IzEzM2Q0MmNlLWVkZGItMTFlNi05OTUzLTAyMTI0YWI0M2Q2NyJ9.une0gwwke1ZwShfXbSPk3KDtbEQ39-aMXWmgsq8M8M0",
    "expires_at": "2022-01-10T11:41:19.000Z",
    "user_id": "user_xxx"
}

📘

Access Token Expiration

A refresh policy for the token may be needed to ensure a smooth experience for the user.

The expires_in parameter represents the access token’s expiration time expressed in seconds. It must be chosen within a range between 360 (6 minutes) and 86400 (24 hours).

3. Add SDK

platform :ios, '10.0'
use_frameworks!

target '<YOUR_TARGET_NAME>' do
    pod 'Bandyer', ~> 'latestVersion'
end

You can find the latest released version here: https://github.com/Bandyer/Bandyer-iOS-SDK/releases.

4. Video call

You can make a basic integration of the SDK for testing purposes by simply copy-pasting the following snippet of code.

Set userId, appId, region and environment variables as indicated in the following code:

let userId = "user id"
let appId = "app id associated to your account starts with mAppID"
let region = .europe // region to which your account belongs: europe or india;
let environment = .sandbox // .sandbox or .production;	
     

// configure
let config = try! ConfigBuilder(appID: appId, environment: environment, region: region).build()
BandyerSDK.instance.configure(config)

// connect
class TokenProvider: AccessTokenProvider {
  func provideAccessToken(userId: String, completion: @escaping (Result<String, Error>) -> Void) {
    // rest call to your server to request an accessToken for the user1
		completion(.success("accessToken")
 }
}
BandyerSDK.instance.connect(Session(userId: userId, tokenProvider: TokenProvider()))

// call
let usersToCall = ["user to call"]
let intent = StartOutgoingCallIntent(callees: usersToCall,
                                     options: .init(callType: .audioUpgradable))

let callWindow = CallWindow.instance ?? CallWindow()
callWindow.presentCallViewController(for: intent)
NSString *userId = @"user id";
NSString *appId = @"app id associated to your account starts with mAppID";
BandyerSDKRegion region = BandyerSDKRegionEurope; // region to which your account belongs: Europe or India;
BandyerSDKEnvironment environment = BandyerSDKEnvironmentSandbox; // BandyerSDKEnvironmentSandbox or BandyerSDKEnvironmentProduction;


// configure
BDKConfig *config = BDKConfigBuilder.create(appId, environment, region).build();
[BandyerSDK.instance configure:config];

// connect
@interface TokenProvider : NSObject <BDKAccessTokenProvider>

@end

@implementation TokenProvider

- (void)provideAccessTokenWithUserId:(NSString * _Nonnull)userId
                             success:(void (^_Nonnull)(NSString * _Nonnull))success
                             error:(void (^_Nonnull)(NSError * _Nonnull))failure
{
    // rest call to your server to request an accessToken for the user
    success(@"accessToken");
}

@end

BDKSession *session = [[BDKSession alloc] initWithUserId:userId tokenProvider:[TokenProvider new] observer:nil];
[BandyerSDK.instance connect:session];

// call
BDKStartOutgoingCallIntent *intent = [BDKStartOutgoingCallIntent intentWithCallees:@[@"user to call"]
                                                                     options:[BDKCallOptions optionsWithCallType:BDKCallTypeAudioVideo]];
BDKCallWindow *callWindow = BDKCallWindow.instance ?: [[BDKCallWindow alloc] init];
[callWindow presentCallViewControllerFor:intent completion:nil];

📘

Note

In sandbox environment ‘region’ is always ‘eu’.

👍

Good Job!

There are more customizations available. Refer to Video-iOS-SDK for further information.