This tutorial will walk you through the steps to make or reveive a call on Mobile App to StringeeX Contact Center.
Before you use Stringee Video Call API to make or receive a video call, you must sign up for a Stringee account. Here are 2 ways to do it:
Sign up a Stringee account on: https://developer.stringee.com/account/register
Go to the Dashboard and Create a project
Create a portal
Generate an access token: Tools -> Generate Access Token
Sign up a StringeeX account on: https://stringeex.com/en/register
Create a portal
Generate an access token: Sign in stringee.com with the StringeeX account then go to Tools -> Generate Access Token
The simplest way to import the SDK into an iOS project is with CocoaPods. Open your project's Podfile and add this line to your app's target:
pod 'Stringee'
Then from the command line run:
pod install --repo-update
If you're new to CocoaPods, see their official documentation for info on how to create and use Podfiles.
In the "Build Settings" tab -> "Other linker flags" add "$(inherited)" flag
In the "Build Settings" tab -> "Enable bitcode" select "NO"
To add the SDK in Xcode:
Add the following libraries and frameworks to Target -> "Build Phases" -> "Link Binary With Libraries":
In the "Build Settings" tab -> "Other linker flags" add "-ObjC" flag
In the "Build Settings" tab -> "Enable bitcode" select "NO"
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses Camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses Microphone</string>
In order to connect to Stringee Server, 3-parties authentication is required as described here: Client authentication, sample code generates access token here: https://github.com/stringeecom/server-samples/tree/master/access_token.
#import <Stringee/Stringee.h>
In .h file
@interface ViewController : UIViewController <StringeeConnectionDelegate>
@property(strong, nonatomic) StringeeClient *stringeeClient;
@end
In .m file
- (void)requestAccessToken:(StringeeClient *)stringeeClient {
NSLog(@"requestAccessToken");
}
- (void)didConnect:(StringeeClient *)stringeeClient isReconnecting:(BOOL)isReconnecting {
NSLog(@"Successfully connected to Stringee Server, user ID: %@", stringeeClient.userId);
}
- (void)didDisConnect:(StringeeClient *)stringeeClient isReconnecting:(BOOL)isReconnecting {
NSLog(@"didDisConnect");
}
- (void)didFailWithError:(StringeeClient *)stringeeClient code:(int)code message:(NSString *)message {
NSLog(@"Failed connection to Stringee Server with error: %@", message);
}
NSString *accessToken = @"...";
self.stringeeClient = [[StringeeClient alloc] initWithConnectionDelegate:self];
[self.stringeeClient connectWithAccessToken:accessToken];
Before making a call, you need to learn about the flow of a call from a mobile app to StringeeX Contact Center.
For more detail, go to https://developer.stringee.com/docs/integrable-contact-center-overview. When you create a portal in the Step 1, a Contact Center number is auto-generated. You can configure this number in your portal -> Settings -> Call Center -> Hotline.
Now you can make a call from your mobile app to the Contact Center: Instantiate a StringeeCall2 object and call the makeCallWithCompletionHandler method:
StringeeCall2 *stringeeCall2 = [[StringeeCall2 alloc] initWithStringeeClient:self.stringeeClient from:@"1273065979" to:@"testcall"];
[stringeeCall2 makeCallWithCompletionHandler:^(BOOL status, int code, NSString * message, NSString *data){
NSLog(@"Make call result: code=%d, message: %@", code, message);
}];
Implements the StringeeCallDelegate protocol
#import <Stringee/Stringee.h>
@interface ViewController : UIViewController <StringeeConnectionDelegate, StringeeCall2Delegate>
@property(strong, nonatomic) StringeeClient *stringeeClient;
@end
in .m file:
//----------- StringeeCall2Delegate -->
- (void)didChangeSignalingState2:(StringeeCall2 *)stringeeCall2 signalingState:(SignalingState)signalingState reason:(NSString *)reason sipCode:(int)sipCode sipReason:(NSString *)sipReason {
NSLog(@"signalingState: %d", signalingState);
}
- (void)didChangeMediaState2:(StringeeCall2 *)stringeeCall2 mediaState:(MediaState)mediaState {
NSLog(@"mediaState: %d", mediaState);
}
- (void)didReceiveLocalStream2:(StringeeCall2 *)stringeeCall2 {
NSLog(@"didReceiveLocalStream");
}
- (void)didReceiveRemoteStream2:(StringeeCall2 *)stringeeCall2 {
NSLog(@"didReceiveRemoteStream");
}
- (void)didHandleOnAnotherDevice2:(StringeeCall2 *)stringeeCall2 signalingState:(SignalingState)signalingState reason:(NSString *)reason sipCode:(int)sipCode sipReason:(NSString *)sipReason {
NSLog(@"didAnsweredOnOtherDevice %d", signalingState);
}
//----------- StringeeCall2Delegate <--
and set delegates for stringeeCall:
stringeeCall2.delegate = self;
Implements the StringeeIncomingCallDelegate protocol
#import <Stringee/Stringee.h>
@interface ViewController : UIViewController <StringeeConnectionDelegate, StringeeCall2Delegate, StringeeIncomingCallDelegate>
@property(strong, nonatomic) StringeeClient *stringeeClient;
@end
in .m file:
- (void)incomingCallWithStringeeClient:(StringeeClient *)stringeeClient stringeeCall2:(StringeeCall2 *)stringeeCall2 {
NSLog(@"incomingCallWithStringeeClient, from: %@, to: %@", stringeeCall2.from, stringeeCall2.to);
}
and set incomingCallDelegate for stringeeClient:
self.stringeeClient.incomingCallDelegate = self;
To make a test call from the Contact Center to your mobile app, go to your StringeeX portal, open the softphone, make a call to the user id which is used to generate access token in the Step 4.
When the client receives an incoming call
- (void)incomingCallWithStringeeClient:(StringeeClient *)stringeeClient stringeeCall2:(StringeeCall2 *)stringeeCall2 {
NSLog(@"incomingCallWithStringeeClient, from: %@, to: %@", stringeeCall2.from, stringeeCall2.to);
stringeeCall2.delegate = self;
}
Call the following method to initialize resources:
[stringeeCall2 initAnswerCall];
Call the following method to answer and start the conversation:
[stringeeCall2 answerCallWithCompletionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"%@", message);
}];
Call the following method to Hang up a call.
[stringeeCall2 hangupWithCompletionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"%@", message);
}];
Call the following method to reject a call.
[stringeeCall2 rejectWithCompletionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"%@", message);
}];
stringeeCall2.isVideoCall = YES;
- (void)didReceiveLocalStream2:(StringeeCall2 *)stringeeCall2 {
dispatch_async(dispatch_get_main_queue(), ^{
[stringeeCall2.localVideoView setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.view insertSubview:stringeeCall2.localVideoView atIndex:0];
});
}
-(void) didReceiveRemoteStream2:(StringeeCall2 *)stringeeCall2 {
dispatch_async(dispatch_get_main_queue(), ^{
[stringeeCall2.remoteVideoView setFrame:CGRectMake(0, 0, self.containRemoteView.bounds.size.width, self.containRemoteView.bounds.size.height)];
[self.containRemoteView addSubview:stringeeCall2.remoteVideoView];
});
}
- (void)didChangeMediaState2:(StringeeCall2 *)stringeeCall2 mediaState:(MediaState)mediaState {
dispatch_async(dispatch_get_main_queue(), ^{
if (mediaState == MediaStateConnected) {
[[StringeeAudioManager instance] setLoudspeaker:YES];
}
});
}
You can view a completed version of this sample app on GitHub: https://github.com/stringeecom/ios-sdk-samples/tree/master/CallkitSample-Call2