Before using Stringee Video Conference API for the first time, you must have a Stringee account If you do not have a Stringee account, sign up for free here: https://developer.stringee.com/account/register
Create a Project on Stringee Dashboard: https://developer.stringee.com/project
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":
<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
For testing purpose, go to Dashboard -> Tools -> Generate Access token and generates an 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];
When the client connects to Stringee Server, instantiate a StringeeRoom object and call the makeRoomWithCompletionHandler method:
self.stringeeRoom = [[StringeeRoom alloc] initWithStringeeClient:self.stringeeClient];
[self.stringeeRoom makeRoomWithCompletionHandler:^(BOOL status, int code, NSString *message) {
if (status) {
// Sucess
} else {
// Fail
}
}];
When the client connects to Stringee Server, you will instantiate a StringeeRoom object and call the joinRoomWithRoomId:sompletionHandler method:
self.stringeeRoom = [[StringeeRoom alloc] initWithStringeeClient:self.stringeeClient];
[self.stringeeRoom joimRoomWithRoomId:self.roomId completionHandler:^(BOOL status, int code, NSString *message) {
if (status) {
// Success
} else {
// Fail
}
}];
roomId is the id of the room you will join.
Implements the StringeeRoomDelegate protocol
in .h file:
#import <Stringee/Stringee.h>
@interface ViewController : UIViewController <StringeeRoomDelegate>
@property(strong, nonatomic) StringeeClient * stringeeClient;
@end
in .m file:
- (void)didRoomConnect:(StringeeRoom *) stringeeRoom streams:(NSArray<StringeeRoomStream *>*) streams {
}
- (void)didRoomError:(StringeeRoom *) stringeeRoom code:(int) code message:(NSString *) message {
}
- (void)didRoomDisConnect:(StringeeRoom *) stringeeRoom {
}
- (void)didStreamAdd:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream {
}
- (void)didStreamRemove:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream {
}
- (void)didStreamSubscribe:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream {
}
- (void)didStreamSubscribeError:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream error:(NSString *) error {
}
- (void)didStreamPublish:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream {
}
- (void)didStreamPublishError:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream error:(NSString *) error {
}
- (void)didStreamUnPublish:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream {
}
- (void)didStreamUnPublishError:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream error:(NSString *) error {
}
- (void)didStreamUnSubscribe:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream {
}
- (void)didStreamUnSubscribeError:(StringeeRoom *) stringeeRoom stream:(StringeeRoomStream *) stream error:(NSString *) error {
}
and set delegate for stringeeRoom:
stringeeRoom.delegate = self;
When the client joins the room, in order to publish the local audio/video stream to the room, instantiate a StringeeRoomStream object and call the publish method of the StringeeRoom instance.
StringeeRoomStreamConfig * config = [[StringeeRoomStreamConfig alloc] init];
config.streamVideoResolution = StreamVideoResolution_Normal;
StringeeRoomStream * localStream = [[StringeeRoomStream alloc] initLocalStreamWithConfig:config];
[self.stringeeRoom publish:localStream];
When the client joins the room, you will receive participants' streams. In order to subscribe these streams, call the subscribe method of the StringeeRoom instance.
- (void)didRoomConnect:(StringeeRoom *)stringeeRoom streams:(NSArray<StringeeRoomStream *> *)streams {
for (StringeeRoomStream * stream in streams) {
[self.stringeeRoom subscribe:stream];
}
}
When a new client joins the room, you will receive the didStreamAdd event with the client's stream. You can subscribe the stream as described above.
-(void) didStreamAdd:(StringeeRoom *)stringeeRoom stream:(StringeeRoomStream *)stream {
[self.stringeeRoom subscribe:stream];
}
Stringee iOS SDK renders a video stream to a view. Then you can add this view to your UI. After the local stream has been initialzied,display the stream:
localStream = [[StringeeRoomStream alloc] initLocalStreamWithConfig:config];
localStream.localVideoView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
[self.view insertSubview:localStream.localVideoView atIndex:0];
After a stream has been subscribed, display the stream:
-(void) didStreamSubscribe:(StringeeRoom *)stringeeRoom stream:(StringeeRoomStream *)stream {
[stream.remoteVideoView setFrame:CGRectMake(0, 0, 100, 100)];
stream.remoteVideoView.delegate = self;
[self.view addSubview:stream.remoteVideoView];
}
The size of the remote streams'views can be changed when rendering. You need caculate the remoteVideoView size to display it correctly:
#import <Stringee/Stringee.h>
@interface ViewController : UIViewController <StringeeRemoteViewDelegate>
@property(strong, nonatomic) StringeeClient * stringeeClient;
@end
[stream.remoteVideoView setFrame:CGRectMake(0, 0, 100, 100)];
stream.remoteVideoView.delegate = self;
[self.view addSubview:stream.remoteVideoView];
-(void)videoView:(StringeeRemoteVideoView *)videoView didChangeVideoSize:(CGSize)size {
// Get width and height of superview
CGFloat superWidth = videoView.superview.bounds.size.width;
CGFloat superHeight = videoView.superview.bounds.size.height;
CGFloat newWidth;
CGFloat newHeight;
if (size.width > size.height) {
newWidth = superWidth;
newHeight = newWidth * size.height / size.width;
[videoView setFrame:CGRectMake(0, (superHeight - newHeight) / 2, newWidth, newHeight)];
} else {
newHeight = superHeight;
newWidth = newHeight * size.width / size.height;
[videoView setFrame:CGRectMake((superWidth - newWidth) / 2, 0, newWidth, newHeight)];
}
}
When your app supports auto-orientation, you need implement the following method of your ViewController:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[localStream autoOrientationOfLocalVideoViewWithSize:size withTransitionCoordinator:coordinator];
}
Then call the autoOrientationOfLocalVideoViewWithSize: withTransitionCoordinator: method of the StringeeRoomStream instance.
When the client leaves a room, you will remove all video views:
// remove localVideoView
if (localStream.localVideoView.superview) {
[localStream.localVideoView removeFromSuperview];
}
// remove remoteVideoView
for (StringeeRoomStream * stream in arrayRemoteStreams) {
if (stream.remoteVideoView.superview) {
[stream.remoteVideoView removeFromSuperview];
}
}
Then call the destroy method of StringeeRoom instance.
// destroy room
[self.stringeeRoom destroy];
You can view a completed version of this sample app on GitHub: https://github.com/stringeecom/ios-sdk-samples