Add waiting screen when call starts.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2017-12-15 17:42:37 +01:00
Родитель 7314c386fe
Коммит f92b5628e4
6 изменённых файлов: 148 добавлений и 51 удалений

Просмотреть файл

@ -21,10 +21,13 @@
@interface CallViewController : UIViewController
@property (nonatomic, weak) id<CallViewControllerDelegate> delegate;
@property (nonatomic, copy) NSString *room;
@property (nonatomic, strong) NCRoom *room;
@property (nonatomic, strong) IBOutlet RTCCameraPreviewView *localVideoView;
@property (nonatomic, strong) IBOutlet UIView *waitingView;
@property (nonatomic, strong) IBOutlet UIImageView *waitingImageView;
@property (nonatomic, strong) IBOutlet UILabel *waitingLabel;
- (instancetype)initCallInRoom:(NSString *)room asUser:(NSString*)displayName;
- (instancetype)initCallInRoom:(NCRoom *)room asUser:(NSString*)displayName;
@end

Просмотреть файл

@ -42,7 +42,7 @@ typedef NS_ENUM(NSInteger, CallState) {
@synthesize delegate = _delegate;
- (instancetype)initCallInRoom:(NSString *)room asUser:(NSString*)displayName
- (instancetype)initCallInRoom:(NCRoom *)room asUser:(NSString*)displayName
{
self = [super init];
if (!self) {
@ -50,8 +50,9 @@ typedef NS_ENUM(NSInteger, CallState) {
}
_callController = [[NCCallController alloc] initWithDelegate:self];
_callController.room = room;
_callController.room = room.token;
_callController.userDisplayName = displayName;
_room = room;
_peersInCall = [[NSMutableArray alloc] init];
_renderersDict = [[NSMutableDictionary alloc] init];
@ -64,6 +65,16 @@ typedef NS_ENUM(NSInteger, CallState) {
[_callController startCall];
self.collectionView.delegate = self;
self.collectionView.backgroundView = self.waitingView;
self.waitingLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.waitingLabel.numberOfLines = 0;
self.waitingImageView.layer.cornerRadius = 64;
self.waitingImageView.layer.masksToBounds = YES;
[self setWaitingScreen];
[self.collectionView registerNib:[UINib nibWithNibName:kCallParticipantCellNibName bundle:nil] forCellWithReuseIdentifier:kCallParticipantCellIdentifier];
if (@available(iOS 11.0, *)) {
@ -76,7 +87,7 @@ typedef NS_ENUM(NSInteger, CallState) {
// Dispose of any resources that can be recreated.
}
#pragma mark - Call State
#pragma mark - User Interface
- (void)setCallState:(CallState)state
{
@ -95,6 +106,24 @@ typedef NS_ENUM(NSInteger, CallState) {
}
}
- (void)setWaitingScreen
{
if (_room.type == kNCRoomTypeOneToOneCall) {
self.waitingLabel.text = @"Waiting for user to join call …";
} else {
self.waitingLabel.text = @"Waiting for others to join call …";
if (_room.type == kNCRoomTypeGroupCall) {
[self.waitingImageView setImage:[UIImage imageNamed:@"group-white85"]];
} else {
[self.waitingImageView setImage:[UIImage imageNamed:@"public-white85"]];
}
self.waitingImageView.backgroundColor = [UIColor colorWithRed:0.898 green:0.898 blue:0.898 alpha:1]; /*#e5e5e5*/
self.waitingImageView.contentMode = UIViewContentModeCenter;
}
}
#pragma mark - Call actions
- (IBAction)audioButtonPressed:(id)sender

Просмотреть файл

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -14,6 +14,9 @@
<outlet property="collectionView" destination="aUh-Z0-hO6" id="jmc-BV-dTa"/>
<outlet property="localVideoView" destination="TXj-7E-NAa" id="nXn-uK-PDD"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
<outlet property="waitingImageView" destination="1c5-9J-hVV" id="cHW-Zs-j0r"/>
<outlet property="waitingLabel" destination="ihe-9I-8ts" id="xiL-CE-VVw"/>
<outlet property="waitingView" destination="BF4-kz-lxP" id="vLf-wm-y8K"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
@ -77,6 +80,24 @@
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<point key="canvasLocation" x="34.5" y="53.5"/>
</view>
<view contentMode="scaleToFill" id="BF4-kz-lxP">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Waiting …" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ihe-9I-8ts">
<rect key="frame" x="67" y="296" width="240" height="68"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1c5-9J-hVV">
<rect key="frame" x="123" y="110" width="128" height="128"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
</subviews>
<point key="canvasLocation" x="582.5" y="53.5"/>
</view>
</objects>
<resources>
<image name="audio" width="48" height="48"/>

Просмотреть файл

@ -15,7 +15,7 @@
typedef void (^GetContactsCompletionBlock)(NSMutableArray *contacts, NSError *error);
typedef void (^GetRoomsCompletionBlock)(NSMutableArray *rooms, NSError *error, NSInteger statusCode);
typedef void (^GetRoomCompletionBlock)(NSDictionary *room, NSError *error);
typedef void (^GetRoomCompletionBlock)(NCRoom *room, NSError *error);
typedef void (^CreateRoomCompletionBlock)(NSString *token, NSError *error);
typedef void (^RenameRoomCompletionBlock)(NSError *error);
typedef void (^AddParticipantCompletionBlock)(NSError *error);
@ -61,7 +61,8 @@ extern NSString * const NCRoomCreatedNotification;
// Rooms Controller
- (void)getRoomsWithCompletionBlock:(GetRoomsCompletionBlock)block;
- (void)getRoom:(NSString *)token withCompletionBlock:(GetRoomCompletionBlock)block;
- (void)getRoomWithToken:(NSString *)token withCompletionBlock:(GetRoomCompletionBlock)block;
- (void)getRoomWithId:(NSInteger)roomId withCompletionBlock:(GetRoomCompletionBlock)block;
- (void)createRoomWith:(NSString *)invite ofType:(NCRoomType)type withCompletionBlock:(CreateRoomCompletionBlock)block;
- (void)renameRoom:(NSString *)token withName:(NSString *)newName andCompletionBlock:(RenameRoomCompletionBlock)block;
- (void)addParticipant:(NSString *)user toRoom:(NSString *)token withCompletionBlock:(AddParticipantCompletionBlock)block;

Просмотреть файл

@ -131,12 +131,13 @@ NSString * const NCRoomCreatedNotification = @"NCRoomCreatedNotification";
}];
}
- (void)getRoom:(NSString *)token withCompletionBlock:(GetRoomCompletionBlock)block
- (void)getRoomWithToken:(NSString *)token withCompletionBlock:(GetRoomCompletionBlock)block
{
NSString *URLString = [self getRequestURLForSpreedEndpoint:[NSString stringWithFormat:@"room/%@", token]];
[[NCAPISessionManager sharedInstance] GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *room = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
NSDictionary *roomDict = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
NCRoom *room = [NCRoom roomWithDictionary:roomDict];
if (block) {
block(room, nil);
}
@ -147,6 +148,27 @@ NSString * const NCRoomCreatedNotification = @"NCRoomCreatedNotification";
}];
}
- (void)getRoomWithId:(NSInteger)roomId withCompletionBlock:(GetRoomCompletionBlock)block
{
NSString *URLString = [self getRequestURLForSpreedEndpoint:@"room"];
[[NCAPISessionManager sharedInstance] GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
NSArray *responseRooms = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
for (NSDictionary *room in responseRooms) {
NCRoom *ncRoom = [NCRoom roomWithDictionary:room];
if (ncRoom.roomId == roomId) {
if (block) {
block(ncRoom, nil);
}
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (block) {
block(nil, error);
}
}];
}
- (void)createRoomWith:(NSString *)invite ofType:(NCRoomType)type withCompletionBlock:(CreateRoomCompletionBlock)block
{
NSString *URLString = [self getRequestURLForSpreedEndpoint:@"room"];

Просмотреть файл

@ -122,15 +122,16 @@
- (void)roomHasBeenCreated:(NSNotification *)notification
{
NSString *roomToken = [notification.userInfo objectForKey:@"token"];
NSLog(@"Joining to created room: %@", roomToken);
if (!_currentCallToken) {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:YES completion:^{
[self presentCallViewControllerForCallToken:roomToken];
}];
} else {
[self presentCallViewControllerForCallToken:roomToken];
}
NCRoom *room = [self getRoomForToken:roomToken];
if (room) {
[self startCallInRoom:room];
} else {
//TODO: Show spinner?
[[NCAPIController sharedInstance] getRoomWithToken:roomToken withCompletionBlock:^(NCRoom *room, NSError *error) {
if (!error) {
[self startCallInRoom:room];
}
}];
}
}
@ -163,37 +164,19 @@
- (void)joinCallWithCallId:(NSInteger)callId
{
NSString *callToken = nil;
if (_rooms) {
for (NCRoom *room in _rooms) {
if (room.roomId == callId) {
callToken = room.token;
[self presentCallViewControllerForCallToken:callToken];
NCRoom *room = [self getRoomForId:callId];
if (room) {
[self startCallInRoom:room];
} else {
//TODO: Show spinner?
[[NCAPIController sharedInstance] getRoomWithId:callId withCompletionBlock:^(NCRoom *room, NSError *error) {
if (!error) {
[self startCallInRoom:room];
}
}
if (!callToken) {
[self searchForCallInServer:callId];
}
}];
}
}
- (void)searchForCallInServer:(NSInteger)callId
{
[[NCAPIController sharedInstance] getRoomsWithCompletionBlock:^(NSMutableArray *rooms, NSError *error, NSInteger statusCode) {
if (!error) {
for (NCRoom *room in rooms) {
if (room.roomId == callId) {
[self presentCallViewControllerForCallToken:room.token];
}
}
} else {
NSLog(@"Error while searching for call: %@", error);
}
}];
}
#pragma mark - Interface Builder Actions
- (IBAction)addButtonPressed:(id)sender
@ -491,16 +474,54 @@
#pragma mark - Calls
- (void)presentCallViewControllerForCallToken:(NSString *)token
- (NCRoom *)getRoomForToken:(NSString *)token
{
NCRoom *room = nil;
for (NCRoom *localRoom in _rooms) {
if (localRoom.token == token) {
room = localRoom;
}
}
return room;
}
- (NCRoom *)getRoomForId:(NSInteger)roomId
{
NCRoom *room = nil;
for (NCRoom *localRoom in _rooms) {
if (localRoom.roomId == roomId) {
room = localRoom;
}
}
return room;
}
- (void)presentCall:(CallViewController *)callVC
{
CallViewController *callVC = [[CallViewController alloc] initCallInRoom:token asUser:[[NCSettingsController sharedInstance] ncUserDisplayName]];
callVC.delegate = self;
[self presentViewController:callVC animated:YES completion:^{
// Disable sleep timer
[UIApplication sharedApplication].idleTimerDisabled = YES;
}];
}
- (void)presentCallViewController:(CallViewController *)callVC
{
if (self.presentedViewController) {
[self dismissViewControllerAnimated:YES completion:^{
[self presentCall:callVC];
}];
} else {
[self presentCall:callVC];
}
}
- (void)startCallInRoom:(NCRoom *)room
{
CallViewController *callVC = [[CallViewController alloc] initCallInRoom:room asUser:[[NCSettingsController sharedInstance] ncUserDisplayName]];
callVC.delegate = self;
[self presentCallViewController:callVC];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@ -675,7 +696,7 @@
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
_currentCallToken = room.token;
[self presentCallViewControllerForCallToken:_currentCallToken];
[self startCallInRoom:room];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}