Skip to content

Commit

Permalink
'dev' -> 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
peetonn committed Sep 26, 2015
2 parents f3c1f56 + 9699210 commit 1c51b5d
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 107 deletions.
4 changes: 2 additions & 2 deletions NdnCon copy-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.6.6</string>
<string>0.6.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>24</string>
<string>25</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.video</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Binary file not shown.
55 changes: 28 additions & 27 deletions ndncon/NCDiscoveryLibraryController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,35 @@ -(void)onSetMessage:(const std::string&)msg withTimestamp:(double)timestamp;
void
onStateChanged(MessageTypes type, const char *msg, double timestamp)
{
// NSLog(@"DISCOVERY: type: %d, msg: %s, timestamp: %f", type, msg, timestamp);
std::string msgStr(msg);

if (controller_)
switch (type) {
case MessageTypes::ADD:
{
dispatch_async(dispatch_get_main_queue(), ^{
[controller_ onAddMessage:msgStr withTimestamp:timestamp];
});
}
break;
case MessageTypes::REMOVE:
{
dispatch_async(dispatch_get_main_queue(), ^{
[controller_ onRemoveMessage:msgStr withTimestamp:timestamp];
});
}
break;
case MessageTypes::SET:{
dispatch_async(dispatch_get_main_queue(), ^{
[controller_ onSetMessage:msgStr withTimestamp:timestamp];
});
@autoreleasepool {
std::string msgStr(msg);

if (controller_)
switch (type) {
case MessageTypes::ADD:
{
dispatch_async(dispatch_get_main_queue(), ^{
[controller_ onAddMessage:msgStr withTimestamp:timestamp];
});
}
break;
case MessageTypes::REMOVE:
{
dispatch_async(dispatch_get_main_queue(), ^{
[controller_ onRemoveMessage:msgStr withTimestamp:timestamp];
});
}
break;
case MessageTypes::SET:{
dispatch_async(dispatch_get_main_queue(), ^{
[controller_ onSetMessage:msgStr withTimestamp:timestamp];
});
}
break;
default:
break;
}
break;
default:
break;
}
}
}

private:
Expand Down
10 changes: 6 additions & 4 deletions ndncon/NCFaceSingleton.mm
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ -(void)cancelFaceTimer

-(void)runFace
{
try {
_face->processEvents();
} catch (std::exception& exception) {
NSLog(@"got exception from ndn-cpp face: %s", exception.what());
@autoreleasepool {
try {
_face->processEvents();
} catch (std::exception& exception) {
NSLog(@"got exception from ndn-cpp face: %s", exception.what());
}
}
}

Expand Down
95 changes: 53 additions & 42 deletions ndncon/NCNdnRtcLibraryController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,30 @@ +(NCSessionStatus)ncStatus:(ndnrtc::SessionStatus)ndnrtcStatus;
public:
void onStateChanged(const char *state, const char *args)
{
NSLog(@"Library state changed: %s - %s", state, args);
@autoreleasepool {
NSLog(@"Library state changed: %s - %s", state, args);
}
}

void onErrorOccurred(int errorCode, const char* message)
{
[[NCErrorController sharedInstance] postErrorWithCode:errorCode
andMessage:[NSString ncStringFromCString:message]];

switch (errorCode) {
case NRTC_ERR_SIGPIPE:
{
if ([NCNdnRtcLibraryController sharedInstance].sessionPrefix)
[[NCNdnRtcLibraryController sharedInstance] stopSession];

[[NCFaceSingleton sharedInstance] markInvalid];
@autoreleasepool {
[[NCErrorController sharedInstance] postErrorWithCode:errorCode
andMessage:[NSString ncStringFromCString:message]];

switch (errorCode) {
case NRTC_ERR_SIGPIPE:
{
if ([NCNdnRtcLibraryController sharedInstance].sessionPrefix)
[[NCNdnRtcLibraryController sharedInstance] stopSession];

[[NCFaceSingleton sharedInstance] markInvalid];
}
break;
default:
// do nothing
break;
}
break;
default:
// do nothing
break;
}
}
};
Expand All @@ -96,46 +100,53 @@ void onErrorOccurred(int errorCode, const char* message)
onSessionStatusUpdate(const char* username, const char* sessionPrefix,
SessionStatus status)
{
if (![NCNdnRtcLibraryController sharedInstance].sessionPrefix)
[NCNdnRtcLibraryController sharedInstance].sessionPrefix = [NSString stringWithCString:sessionPrefix encoding:NSASCIIStringEncoding];

NCSessionStatus oldStatus = [NCNdnRtcLibraryController sharedInstance].sessionStatus;
[NCNdnRtcLibraryController sharedInstance].sessionStatus = [NCNdnRtcLibraryController ncStatus:status];

NSLog(@"new local session status - %d", status);
NSString *usernameStr = [NSString ncStringFromCString:username];
NSString *sessionPrefixStr = [NSString ncStringFromCString:sessionPrefix];
dispatch_async(dispatch_get_main_queue(), ^{
[[[NSObject alloc] init] notifyNowWithNotificationName:NCLocalSessionStatusUpdateNotification
andUserInfo:@{kSessionUsernameKey: usernameStr,
kSessionPrefixKey: sessionPrefixStr,
kSessionStatusKey: @([NCNdnRtcLibraryController ncStatus:status]),
kSessionOldStatusKey: @(oldStatus)}];
});
@autoreleasepool {
if (![NCNdnRtcLibraryController sharedInstance].sessionPrefix)
[NCNdnRtcLibraryController sharedInstance].sessionPrefix = [NSString stringWithCString:sessionPrefix encoding:NSASCIIStringEncoding];

NCSessionStatus oldStatus = [NCNdnRtcLibraryController sharedInstance].sessionStatus;
[NCNdnRtcLibraryController sharedInstance].sessionStatus = [NCNdnRtcLibraryController ncStatus:status];

NSLog(@"new local session status - %d", status);
NSString *usernameStr = [NSString ncStringFromCString:username];
NSString *sessionPrefixStr = [NSString ncStringFromCString:sessionPrefix];
dispatch_async(dispatch_get_main_queue(), ^{
[[[NSObject alloc] init] notifyNowWithNotificationName:NCLocalSessionStatusUpdateNotification
andUserInfo:@{kSessionUsernameKey: usernameStr,
kSessionPrefixKey: sessionPrefixStr,
kSessionStatusKey: @([NCNdnRtcLibraryController ncStatus:status]),
kSessionOldStatusKey: @(oldStatus)}];
});
}
}

void
onSessionError(const char* username, const char* sessionPrefix,
SessionStatus status, unsigned int errorCode,
const char* errorMessage)
{
[NCNdnRtcLibraryController sharedInstance].sessionStatus = [NCNdnRtcLibraryController ncStatus:status];

dispatch_async(dispatch_get_main_queue(), ^{
[[[NSObject alloc] init] notifyNowWithNotificationName: NCLocalSessionErrorNotification
andUserInfo:@{kSessionUsernameKey: [NSString stringWithCString:username encoding:NSASCIIStringEncoding],
kSessionPrefixKey: [NSString stringWithCString:sessionPrefix encoding:NSASCIIStringEncoding],
kSessionStatusKey: @([NCNdnRtcLibraryController ncStatus:status]),
kSessionErrorCodeKey: @(errorCode),
kSessionErrorMessageKey: [NSString stringWithCString:errorMessage encoding:NSASCIIStringEncoding]}];
@autoreleasepool {
[NCNdnRtcLibraryController sharedInstance].sessionStatus = [NCNdnRtcLibraryController ncStatus:status];

});
dispatch_async(dispatch_get_main_queue(), ^{
[[[NSObject alloc] init] notifyNowWithNotificationName: NCLocalSessionErrorNotification
andUserInfo:@{kSessionUsernameKey: [NSString stringWithCString:username encoding:NSASCIIStringEncoding],
kSessionPrefixKey: [NSString stringWithCString:sessionPrefix encoding:NSASCIIStringEncoding],
kSessionStatusKey: @([NCNdnRtcLibraryController ncStatus:status]),
kSessionErrorCodeKey: @(errorCode),
kSessionErrorMessageKey: [NSString stringWithCString:errorMessage encoding:NSASCIIStringEncoding]}];

});
}
}

void
onSessionInfoUpdate(const new_api::SessionInfo& sessionInfo)
{
[[NCUserDiscoveryController sharedInstance] announceInfo:[NCSessionInfoContainer containerWithSessionInfo:(new_api::SessionInfo*)&sessionInfo]];
@autoreleasepool {
[[NCUserDiscoveryController sharedInstance]
announceInfo:[NCSessionInfoContainer containerWithSessionInfo:(new_api::SessionInfo*)&sessionInfo]];
}
}
};

Expand Down
90 changes: 88 additions & 2 deletions ndncon/NCRosterWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,56 @@
#import "NCNdnRtcLibraryController.h"
#import "NSDictionary+NCAdditions.h"

//******************************************************************************
@implementation NSDictionary (NCRosterUiChecks)

-(NSDictionary*)uiReleveantStreamInfo
{
NSMutableDictionary *d = [NSMutableDictionary dictionary];

d[kNameKey] = self[kNameKey];
d[kThreadsArrayKey] = [NSMutableArray array];

for (NSDictionary *dd in self[kThreadsArrayKey])
[d[kThreadsArrayKey] addObject:[dd uiReleveantThreadInfo]];

return [NSDictionary dictionaryWithDictionary:d];
}

-(NSDictionary*)uiReleveantThreadInfo
{
NSMutableDictionary *d = [NSMutableDictionary dictionary];

d[kNameKey] = self[kNameKey];
d[kBitrateKey] = self[kBitrateKey];

// check for audio threads
if (self[kEncodingHeightKey] && self[kEncodingWidthKey])
{
d[kEncodingWidthKey] = self[kEncodingWidthKey];
d[kEncodingHeightKey] = self[kEncodingHeightKey];
}

return [NSDictionary dictionaryWithDictionary:d];
}

@end

@implementation NSArray (NCRosterUiChecks)

-(NSArray*)streamConfigurationsUiRelevantInfo
{
NSMutableArray *a = [NSMutableArray array];

for (NSDictionary *d in self)
[a addObject:[d uiReleveantStreamInfo]];

return [NSArray arrayWithArray:a];
}

@end

//******************************************************************************
@interface NCRosterWindowController()

@property (weak) IBOutlet NSView *localContrainerView;
Expand Down Expand Up @@ -90,8 +140,12 @@ -(void)onUserDiscovered:(NSNotification*)notification

-(void)onUserUpdated:(NSNotification*)notification
{
self.discoveredUsers = [NCUserDiscoveryController sharedInstance].discoveredUsers;
[self.outlineView reloadData];
if ([self checkForUiUpdates: [NCUserDiscoveryController sharedInstance].discoveredUsers])
{
self.discoveredUsers = [NCUserDiscoveryController sharedInstance].discoveredUsers;
NSLog(@"your new users: %@", self.discoveredUsers);
[self.outlineView reloadData];
}
}

-(void)onUserWithdrawed:(NSNotification*)notification
Expand Down Expand Up @@ -330,4 +384,36 @@ -(void)rosterUserCell:(NCRosterUserCell *)cell didSelectToStopStreams:(NSArray *
[self.outlineView reloadItem:cell.userInfo reloadChildren:YES];
}

#pragma mark - private
-(BOOL)checkForUiUpdates:(NSArray*)updatedUsers
{
BOOL hasUpdate = NO;

// we need to check whether there are any UI updates required.
// check every user's stream number and parameters
if (self.discoveredUsers.count == updatedUsers.count)
{
for (NCActiveUserInfo *userInfo in self.discoveredUsers)
{
NSArray *uarr = [updatedUsers filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NCActiveUserInfo *u, NSDictionary *bindings) {
return [u.username isEqualToString:userInfo.username] && [u.hubPrefix isEqualToString:userInfo.hubPrefix];
}]];

if (!uarr.count)
return YES;

NCActiveUserInfo *correspondingUser = uarr[0];
hasUpdate = !([[userInfo.streamConfigurations streamConfigurationsUiRelevantInfo]
isEqualToArray:[correspondingUser.streamConfigurations streamConfigurationsUiRelevantInfo]]);

if (hasUpdate)
break;
}
}
else
hasUpdate = YES;

return hasUpdate;
}

@end
Loading

0 comments on commit 1c51b5d

Please sign in to comment.