Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "lobby-placeholder.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions VideoCalls/Images.xcassets/lobby.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "lobby.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added VideoCalls/Images.xcassets/lobby.imageset/lobby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions VideoCalls/Images.xcassets/timer.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added VideoCalls/Images.xcassets/timer.imageset/timer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions VideoCalls/NCAPIController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef void (^ExitRoomCompletionBlock)(NSError *error);
typedef void (^FavoriteRoomCompletionBlock)(NSError *error);
typedef void (^NotificationLevelCompletionBlock)(NSError *error);
typedef void (^ReadOnlyCompletionBlock)(NSError *error);
typedef void (^SetLobbyStateCompletionBlock)(NSError *error);

typedef void (^GetParticipantsFromRoomCompletionBlock)(NSMutableArray *participants, NSError *error);
typedef void (^LeaveRoomCompletionBlock)(NSInteger errorCode, NSError *error);
Expand Down Expand Up @@ -94,6 +95,7 @@ typedef void (^UnsubscribeToPushProxyCompletionBlock)(NSError *error);
- (NSURLSessionDataTask *)removeRoomFromFavorites:(NSString *)token withCompletionBlock:(FavoriteRoomCompletionBlock)block;
- (NSURLSessionDataTask *)setNotificationLevel:(NCRoomNotificationLevel)level forRoom:(NSString *)token withCompletionBlock:(NotificationLevelCompletionBlock)block;
- (NSURLSessionDataTask *)setReadOnlyState:(NCRoomReadOnlyState)state forRoom:(NSString *)token withCompletionBlock:(ReadOnlyCompletionBlock)block;
- (NSURLSessionDataTask *)setLobbyState:(NCRoomLobbyState)state withTimer:(NSString *)timer forRoom:(NSString *)token withCompletionBlock:(SetLobbyStateCompletionBlock)block;

// Participants Controller
- (NSURLSessionDataTask *)getParticipantsFromRoom:(NSString *)token withCompletionBlock:(GetParticipantsFromRoomCompletionBlock)block;
Expand Down
22 changes: 22 additions & 0 deletions VideoCalls/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,28 @@ - (NSURLSessionDataTask *)setReadOnlyState:(NCRoomReadOnlyState)state forRoom:(N
return task;
}

- (NSURLSessionDataTask *)setLobbyState:(NCRoomLobbyState)state withTimer:(NSString *)timer forRoom:(NSString *)token withCompletionBlock:(SetLobbyStateCompletionBlock)block
{
NSString *URLString = [self getRequestURLForSpreedEndpoint:[NSString stringWithFormat:@"room/%@/webinary/lobby", token]];
NSMutableDictionary *parameters = [NSMutableDictionary new];
[parameters setObject:@(state) forKey:@"state"];
if (timer) {
[parameters setObject:timer forKey:@"timer"];
}

NSURLSessionDataTask *task = [[NCAPISessionManager sharedInstance] PUT:URLString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (block) {
block(nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (block) {
block(error);
}
}];

return task;
}

#pragma mark - Participants Controller

- (NSURLSessionDataTask *)getParticipantsFromRoom:(NSString *)token withCompletionBlock:(GetParticipantsFromRoomCompletionBlock)block
Expand Down
101 changes: 89 additions & 12 deletions VideoCalls/NCChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ @interface NCChatViewController ()
@property (nonatomic, strong) UIButton *unreadMessageButton;
@property (nonatomic, strong) UIBarButtonItem *videoCallButton;
@property (nonatomic, strong) UIBarButtonItem *voiceCallButton;
@property (nonatomic, strong) NSTimer *lobbyCheckTimer;

@end

Expand Down Expand Up @@ -80,6 +81,7 @@ - (instancetype)initForRoom:(NCRoom *)room
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveChatHistory:) name:NCRoomControllerDidReceiveChatHistoryNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveChatMessages:) name:NCRoomControllerDidReceiveChatMessagesNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSendChatMessage:) name:NCRoomControllerDidSendChatMessageNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveChatBlocked:) name:NCRoomControllerDidReceiveChatBlockedNotification object:nil];
}

return self;
Expand All @@ -96,6 +98,11 @@ - (void)viewDidLoad
{
[super viewDidLoad];

self.titleView = [[NCChatTitleView alloc] init];
self.titleView.frame = CGRectMake(0, 0, 800, 30);
self.titleView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.titleView.title addTarget:self action:@selector(titleButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = _titleView;
[self setTitleView];
[self configureActionItems];

Expand Down Expand Up @@ -197,6 +204,7 @@ - (void)viewDidDisappear:(BOOL)animated

// Leave chat when the view controller has been removed from its parent view.
if (self.isMovingFromParentViewController) {
[_lobbyCheckTimer invalidate];
[[NCRoomsManager sharedInstance] leaveChatInRoom:_room.token];
}
}
Expand All @@ -205,11 +213,7 @@ - (void)viewDidDisappear:(BOOL)animated

- (void)setTitleView
{
_titleView = [[NCChatTitleView alloc] init];
_titleView.frame = CGRectMake(0, 0, 800, 30);
_titleView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_titleView.title setTitle:_room.displayName forState:UIControlStateNormal];
[_titleView.title addTarget:self action:@selector(titleButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

// Set room image
switch (_room.type) {
Expand Down Expand Up @@ -239,8 +243,6 @@ - (void)setTitleView
} else if ([_room.objectType isEqualToString:NCRoomObjectTypeSharePassword]) {
[_titleView.image setImage:[UIImage imageNamed:@"password-bg"]];
}

self.navigationItem.titleView = _titleView;
}

- (void)configureActionItems
Expand Down Expand Up @@ -269,13 +271,53 @@ - (void)checkRoomControlsAvailability
[_voiceCallButton setEnabled:YES];
}

if (_room.readOnlyState == NCRoomReadOnlyStateReadOnly) {
if (_room.readOnlyState == NCRoomReadOnlyStateReadOnly || [self shouldPresentLobbyView]) {
// Hide text input
self.textInputbarHidden = YES;
// Disable call buttons
[_videoCallButton setEnabled:NO];
[_voiceCallButton setEnabled:NO];
} else if ([self isTextInputbarHidden]) {
// Show text input if it was hidden in a previous state
[self setTextInputbarHidden:NO animated:YES];
}
}

- (void)checkLobbyState
{
if ([self shouldPresentLobbyView]) {
[_chatBackgroundView.placeholderText setText:@"You are currently waiting in the lobby."];
[_chatBackgroundView.placeholderImage setImage:[UIImage imageNamed:@"lobby-placeholder"]];
NSDate *date = [NCUtils dateFromDateAtomFormat:_room.lobbyTimer];
if (date) {
NSString *meetingStart = [NCUtils readableDateFromDate:date];
NSString *placeHolderText = [NSString stringWithFormat:@"You are currently waiting in the lobby.\nThis meeting is scheduled for\n%@", meetingStart];
[_chatBackgroundView.placeholderText setText:placeHolderText];
[_chatBackgroundView.placeholderImage setImage:[UIImage imageNamed:@"lobby-placeholder"]];
}
[_chatBackgroundView.placeholderView setHidden:NO];
[_chatBackgroundView.loadingView stopAnimating];
[_chatBackgroundView.loadingView setHidden:YES];
// Clear current chat since chat history will be retrieve when lobby is disabled
_messages = [[NSMutableDictionary alloc] init];
_dateSections = [[NSMutableArray alloc] init];
_hasReceiveInitialHistory = NO;
[self hideNewMessagesView];
[self.tableView reloadData];
} else {
[_chatBackgroundView.placeholderText setText:@"No messages yet, start the conversation!"];
[_chatBackgroundView.placeholderImage setImage:[UIImage imageNamed:@"chat-placeholder"]];
[_chatBackgroundView.placeholderView setHidden:YES];
[_chatBackgroundView.loadingView startAnimating];
[_chatBackgroundView.loadingView setHidden:NO];
// Stop checking lobby flag
[_lobbyCheckTimer invalidate];
// Retrieve initial chat history
if (!_hasReceiveInitialHistory) {
[_roomController getInitialChatHistory];
}
}
[self checkRoomControlsAvailability];
}

#pragma mark - Utils
Expand Down Expand Up @@ -419,6 +461,7 @@ - (void)didUpdateRoom:(NSNotification *)notification

_room = room;
[self setTitleView];
[self checkLobbyState];
}

- (void)didJoinRoom:(NSNotification *)notification
Expand Down Expand Up @@ -545,6 +588,38 @@ - (void)didSendChatMessage:(NSNotification *)notification
}
}

- (void)didReceiveChatBlocked:(NSNotification *)notification
{
NSString *room = [notification.userInfo objectForKey:@"room"];
if (![room isEqualToString:_room.token]) {
return;
}

[self startObservingRoomLobbyFlag];
}

#pragma mark - Lobby functions

- (void)startObservingRoomLobbyFlag
{
[self updateRoomInformation];

dispatch_async(dispatch_get_main_queue(), ^{
[_lobbyCheckTimer invalidate];
_lobbyCheckTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updateRoomInformation) userInfo:nil repeats:YES];
});
}

- (void)updateRoomInformation
{
[[NCRoomsManager sharedInstance] updateRoom:_room.token];
}

- (BOOL)shouldPresentLobbyView
{
return _room.lobbyState == NCRoomLobbyStateModeratorsOnly && !_room.canModerate;
}

#pragma mark - Chat functions

- (NSDate *)getKeyForDate:(NSDate *)date inDictionary:(NSDictionary *)dictionary
Expand Down Expand Up @@ -657,7 +732,7 @@ - (BOOL)shouldGroupMessage:(NCChatMessage *)newMessage withMessage:(NCChatMessag

- (BOOL)shouldRetireveHistory
{
return _hasReceiveInitialHistory && !_retrievingHistory && [_roomController hasHistory];
return _hasReceiveInitialHistory && !_retrievingHistory && [_roomController hasHistory] && _dateSections.count > 0;
}

- (void)showLoadingHistoryView
Expand Down Expand Up @@ -747,6 +822,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
return 1;
}

if ([tableView isEqual:self.tableView] && _dateSections.count > 0) {
self.tableView.backgroundView = nil;
} else {
self.tableView.backgroundView = _chatBackgroundView;
}

return _dateSections.count;
}

Expand All @@ -759,10 +840,6 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
NSDate *date = [_dateSections objectAtIndex:section];
NSMutableArray *messages = [_messages objectForKey:date];

if ([tableView isEqual:self.tableView] && messages.count > 0) {
self.tableView.backgroundView = nil;
}

return messages.count;
}

Expand Down
7 changes: 7 additions & 0 deletions VideoCalls/NCRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ typedef enum NCRoomReadOnlyState {
NCRoomReadOnlyStateReadOnly
} NCRoomReadOnlyState;

typedef enum NCRoomLobbyState {
NCRoomLobbyStateAllParticipants = 0,
NCRoomLobbyStateModeratorsOnly
} NCRoomLobbyState;

extern NSString * const NCRoomObjectTypeFile;
extern NSString * const NCRoomObjectTypeSharePassword;

Expand All @@ -56,6 +61,8 @@ extern NSString * const NCRoomObjectTypeSharePassword;
@property (nonatomic, copy) NSString *objectType;
@property (nonatomic, copy) NSString *objectId;
@property (nonatomic, assign) NCRoomReadOnlyState readOnlyState;
@property (nonatomic, assign) NCRoomLobbyState lobbyState;
@property (nonatomic, copy) NSString *lobbyTimer;

+ (instancetype)roomWithDictionary:(NSDictionary *)roomDict;

Expand Down
2 changes: 2 additions & 0 deletions VideoCalls/NCRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ + (instancetype)roomWithDictionary:(NSDictionary *)roomDict
room.objectType = [roomDict objectForKey:@"objectType"];
room.objectId = [roomDict objectForKey:@"objectId"];
room.readOnlyState = (NCRoomReadOnlyState)[[roomDict objectForKey:@"readOnly"] integerValue];
room.lobbyState = (NCRoomLobbyState)[[roomDict objectForKey:@"lobbyState"] integerValue];
room.lobbyTimer = [roomDict objectForKey:@"lobbyTimer"];

id name = [roomDict objectForKey:@"name"];
if ([name isKindOfClass:[NSString class]]) {
Expand Down
1 change: 1 addition & 0 deletions VideoCalls/NCRoomController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern NSString * const NCRoomControllerDidReceiveInitialChatHistoryNotification
extern NSString * const NCRoomControllerDidReceiveChatHistoryNotification;
extern NSString * const NCRoomControllerDidReceiveChatMessagesNotification;
extern NSString * const NCRoomControllerDidSendChatMessageNotification;
extern NSString * const NCRoomControllerDidReceiveChatBlockedNotification;

@interface NCRoomController : NSObject

Expand Down
Loading