Permalink
Browse files

subscribing works!

tested so far:

  * sessionConnected
  * streamCreated
  * streamDestroyed
  * session.subscribe(stream) .. no fancy options
  * subscriberConnected
  * subscriberStarted
  * subscriber.close() .. only really tested when the stream was destroyed, should also test for valid streams
  • Loading branch information...
1 parent edaa300 commit dbd786d51aea04b2166db337b1ea177618025ee6 @aoberoi committed Apr 23, 2012
@@ -274,7 +274,7 @@ - (id)publish:(id)args
// TODO: not sure if returning the existing publisher proxy is a good idea
} else {
// parse options
- id firstArg = [args objectAtIndex:0];
+ id firstArg = [args count] > 0 ? [args objectAtIndex:0] : nil;
if (firstArg != nil && [firstArg isKindOfClass:[NSDictionary class]]) {
NSDictionary *options = (NSDictionary *)firstArg;
name = [ComTokboxTiOpentokSessionProxy validString:[options objectForKey:@"name"]];
@@ -310,6 +310,10 @@ - (id)subscribe:(id)args
BOOL subscribeToAudio = YES, subscribeToVideo = YES;
// TODO: can we do more than one subscriber for the same stream? probably.
+ if ([args count] < 1) {
+ return nil;
+ }
+
// parse args
id firstArg = [args objectAtIndex:0];
if (![firstArg isKindOfClass:[ComTokboxTiOpentokStreamProxy class]]) {
@@ -318,7 +322,7 @@ - (id)subscribe:(id)args
}
ComTokboxTiOpentokStreamProxy *stream = (ComTokboxTiOpentokStreamProxy *)firstArg;
- id secondArg = [args objectAtIndex:1];
+ id secondArg = [args count] > 1 ? [args objectAtIndex:1] : nil;
if (secondArg != nil && [secondArg isKindOfClass:[NSDictionary class]]) {
NSDictionary *options = (NSDictionary *)secondArg;
subscribeToAudio = [ComTokboxTiOpentokSessionProxy validBool:[options objectForKey:@"subscribeToAudio"] fallback:YES];
@@ -403,19 +407,19 @@ - (void)session:(OTSession*)session didDropStream:(OTStream*)stream
if ([self _hasListeners:@"streamDestroyed"]) {
- // Find the stream proxy in _streamProxies
- ComTokboxTiOpentokStreamProxy *deadStreamProxy = [_streamProxies objectForKey:stream.streamId];
+ // Find and remove the stream proxy in _streamProxies
+ ComTokboxTiOpentokStreamProxy *deadStreamProxy = [[_streamProxies objectForKey:stream.streamId] retain];
+ [_streamProxies removeObjectForKey:deadStreamProxy.streamId];
- // If the stream proxy is not found, create an autoreleased one for the event properties
- // else we need to remove it from _streamProxies
+ // If the stream proxy is not found, create one for the event properties
if (deadStreamProxy == nil) {
- deadStreamProxy = [[[ComTokboxTiOpentokStreamProxy alloc] initWithStream:stream sessionProxy:self] autorelease];
- } else {
- [_streamProxies removeObjectForKey:deadStreamProxy];
+ NSLog(@"Could not find stream proxy during drop, initializing new one here")
+ deadStreamProxy = [[ComTokboxTiOpentokStreamProxy alloc] initWithStream:stream sessionProxy:self];
}
// put the stream proxy object in the event parameters
NSDictionary *eventProperties = [NSDictionary dictionaryWithObject:deadStreamProxy forKey:@"stream"];
+ [deadStreamProxy release];
// fire event
[self fireEvent:@"streamDestroyed" withObject:eventProperties];
@@ -17,6 +17,7 @@
@private
OTStream *_stream;
ComTokboxTiOpentokSessionProxy *_sessionProxy;
+ ComTokboxTiOpentokConnectionProxy *_connectionProxy;
}
- (id)initWithStream:(OTStream *)existingStream sessionProxy:(ComTokboxTiOpentokSessionProxy *)sessionProxy;
@@ -37,6 +37,7 @@ - (id)initWithStream:(OTStream *)existingStream sessionProxy:(ComTokboxTiOpentok
if (self) {
// Initializations
_stream = [existingStream retain];
+ _connectionProxy = nil;
// Not retained, weak reference, be careful
_sessionProxy = sessionProxy;
@@ -54,6 +55,7 @@ - (id)init {
- (void)dealloc {
[_stream release];
+ [_connectionProxy release];
[super dealloc];
}
@@ -67,7 +69,10 @@ -(OTStream *)stream
- (ComTokboxTiOpentokConnectionProxy *)connection
{
- return _sessionProxy.connection;
+ if (_connectionProxy == nil) {
+ _connectionProxy = [[ComTokboxTiOpentokConnectionProxy alloc] initWithConnection:_stream.connection];
+ }
+ return _connectionProxy;
}
- (id)creationTime {
@@ -29,6 +29,6 @@
@property (readonly) NSNumber *subscribeToVideo;
// Methods
--(void)close;
+-(void)close:(id)args;
@end
@@ -100,7 +100,7 @@ -(id)subscribeToVideo
#pragma mark - Methods
--(void)close
+-(void)close:(id)args
{
[_subscriber close];
[_sessionProxy removeSubscriber:self];
@@ -105,6 +105,7 @@
32C88DFF0371C24200C91783 /* Other Sources */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
034768DFFF38A50411DB9C8B /* Products */,
+ AA747D9E0F9514B9006C5449 /* ComTokboxTiOpentok_Prefix.pch */,
);
name = "opentok-titanium";
sourceTree = "<group>";
@@ -139,7 +140,6 @@
32C88DFF0371C24200C91783 /* Other Sources */ = {
isa = PBXGroup;
children = (
- AA747D9E0F9514B9006C5449 /* ComTokboxTiOpentok_Prefix.pch */,
24DD6D1B1134B66800162E58 /* titanium.xcconfig */,
);
name = "Other Sources";

0 comments on commit dbd786d

Please sign in to comment.