SimpleSample-videochat-ios
Contents |
Sources
Project homepage on GIT — https://github.com/QuickBlox/Sample-VideoChat-ios
Download ZIP - https://github.com/QuickBlox/Sample-VideoChat-ios/archive/master.zip
Overview
This sample demonstrates how to work with QuickBlox VideoChat API.
It allows to organize video conference between 2 people
Guide: Get Started with VideoChat API
Get QuickBlox account
http://admin.quickblox.com/register
Create application in Admin panel
http://admin.quickblox.com/apps/new
Also you can look through 5 min guide.
Connect QuickBlox to your application
To get the information on how to connect to the QuickBlox.framework, please, refer to the IOS-how-to-connect-Quickblox-framework page.
Add Chat to your application
Login to Chat
Note: In order to login to chat please read info about Chat login/password formation.
In order to use QuickBlox Chat APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Chat
Please follow lines below:
Create session with User & Sign In to QuickBlox Chat
NSString *userLogin = @"videoChatUser1"; NSString *userPassword = @"videoChatUser1"; // Create session with user QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request]; extendedAuthRequest.userLogin = userLogin; extendedAuthRequest.userPassword = userPassword; [QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self]; #pragma mark - #pragma mark QBActionStatusDelegate // QuickBlox queries delegate - (void)completedWithResult:(Result *)result{ // Create session result if(result.success && [result isKindOfClass:QBAAuthSessionCreationResult.class]){ // You have successfully created the session QBAAuthSessionCreationResult *res = (QBAAuthSessionCreationResult *)result; // Sign In to QuickBlox Chat QBUUser *currentUser = [QBUUser user]; currentUser.ID = res.session.userID; // your current user's ID currentUser.password = userPassword; // your current user's password // set Chat delegate [QBChat instance].delegate = self; // login to Chat [[QBChat instance] loginWithUser:currentUser]; } } #pragma mark - #pragma mark QBChatDelegate // Chat delegate -(void) chatDidLogin{ // You have successfully signed in to QuickBlox Chat }
Keep in mind that QuickBlox Chat is a standard XMPP chat and you need to send presence periodically to remain available. Just create timer that will send presence each 30 seconds:
[NSTimer scheduledTimerWithTimeInterval:30 target:[QBChat instance] selector:@selector(sendPresence) userInfo:nil repeats:YES];
1 to 1 VideoChat
1 to 1 VideoChat is very easy.
Preparation
In order to use VideoChat API you have to do some extra things.
You need to set views where your & opponent's video stream will be rendered.
// Views probably connected with xib IBOutlet UIImageView *opponentVideoView; IBOutlet UIImageView *myVideoView; … #pragma mark - #pragma mark QBChatDelegate - (UIImageView *) viewToRenderOpponentVideoStream{ return opponentVideoView; } - (UIImageView *) viewToRenderOwnVideoStream{ return myVideoView; }
Call user
To call user just use method
[QBChat instance].delegate = self; // 3458 - opponent's user ID [[QBChat instance] callUser:3458 conferenceType:QBVideoChatConferenceTypeAudioAndVideo];
After this your opponent (user with ID=3458) will be receiving one call request per second during 15 seconds
#pragma mark - #pragma mark QBChatDelegate -(void) chatDidReceiveCallRequestFromUser:(NSUInteger)userID conferenceType:(enum QBVideoChatConferenceType)conferenceType{ }
If you want to increase call timeout, e.g. set 20 seconds:
NSMutableDictionary *videoChatConfiguration = [[QBSettings videoChatConfiguration] mutableCopy]; [videoChatConfiguration setObject:@20 forKey:kQBVideoChatCallTimeout]; [QBSettings setVideoChatConfiguration:videoChatConfiguration];
Accept the call
To accept call request just use method
[[QBChat instance] acceptCall];
After this your opponent will receive accept signal
#pragma mark - #pragma mark QBChatDelegate -(void) chatCallDidAcceptByUser:(NSUInteger)userID{ }
After this video call will be started. Delegate method bellow will signalize about this:
#pragma mark - #pragma mark QBChatDelegate - (void)chatCallDidStartWithUser:(NSUInteger)userID{ }
Reject the call
To reject call request just use method
[[QBChat instance] rejectCall];
After this your opponent will receive reject signal
#pragma mark - #pragma mark QBChatDelegate -(void) chatCallDidRejectByUser:(NSUInteger)userID{ }
Finish the call
To stop call request just use method
[[QBChat instance] finishCall];
After this your opponent will receive finish signal
#pragma mark - #pragma mark QBChatDelegate -(void) chatCallDidStopByUser:(NSUInteger)userID status:(NSString *)status{ }
There are 2 possible statuses (reasons):
- Opponent did not answer - kStopVideoChatCallStatus_OpponentDidNotAnswer
- Opponent has finished call with finishCall method - kStopVideoChatCallStatus_Manually
Mute
You can disable microphone during video call
[QBChat instance].muteVideoChat = YES;
Conclusion
Play with VideoChat code sample, try and integrate it into your apps or combine them with other QuickBlox APIs and create something exciting. As usual, QuickBlox developers assistance team is happy to answer your questions should you have any - just contact us.
Comments
Feel free to comment on this page using the form below.
blog comments powered by Disqus


