Permalink
Browse files

CL-260: Presence Leave Event Not Occuring on Objective-C with SSL

Enabled
  • Loading branch information...
1 parent dcd5a04 commit ff9dcbf84c03fc0f71a8e9d64c82136f77f6211e @tanaji-kadam tanaji-kadam committed Nov 8, 2012
@@ -30,7 +30,8 @@
kCommand_FetchHistory,
kCommand_FetchDetailHistory,
kCommand_GetTime,
- kCommand_Here_Now
+ kCommand_Here_Now,
+ kCommand_Leave
} Command;
@interface PubNubConnection : NSURLConnection {
@@ -128,7 +129,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection*)connection {
}
} else if ([contentType hasPrefix:@"text/javascript"])
{
- if(_command== kCommand_Here_Now)
+ if(_command== kCommand_Here_Now || _command == kCommand_Leave)
{
NSError* error = nil;
@@ -455,6 +456,22 @@ - (void)presence:(NSString *)channel
[self subscribe:[NSString stringWithFormat:@"%@-pnpres", channel]];
}
+-(void)leave:(NSString *)channel
+{
+ if(channel == nil || channel ==@"")
+ {
+ NSLog(@"Missing channel");
+ return;
+ }
+
+ NSString *url = [NSString stringWithFormat:@"%@/v2/presence/sub_key/%@/channel/%@/leave?uuid=%@", _host, _subscribeKey, [channel urlEscapedString],_uuids];
+ PubNubConnection* connection = [[PubNubConnection alloc] initWithPubNub:self
+ url:[NSURL URLWithString:url]
+ command:kCommand_Leave
+ channel:channel];
+ [_connections addObject:connection];
+}
+
- (void)unsubscribeFromChannel:(NSString *)channel {
for (PubNubConnection* connection in [_connections copy]) {
if ((connection.command == kCommand_ReceiveMessage) && (!channel || [connection.channel isEqualToString:channel])) {
@@ -701,6 +718,9 @@ - (void)connection:(PubNubConnection *)connection didCompleteWithResponse:(id)re
[self hereNow:response onChannel:connection.channel];
}
break;
+ case kCommand_Leave:
+ NSLog(@"Leave sucessfully with %@",response);
+ break;
}
default:
// NOT_REACHED();
@@ -757,15 +777,12 @@ - (void)handleCommandReceiveMessageForConnection:(PubNubConnection *)connection
NSString *timeToken = @"0";
if(!isPresence)
{
-
if (response == nil ) {
for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:connection.channel])
{
-
if(it.first && it.connected) {
it.connected=NO;
-
[self disconnectFromChannel:connection.channel];
}
}
@@ -1010,6 +1027,7 @@ - (void)disconnectFromChannel:(NSString *)channel
if ([_delegate respondsToSelector:@selector(pubnub:DisconnectToChannel:)]) {
[_delegate pubnub:self DisconnectToChannel:channel];
}
+ [self leave:channel];
}
- (void)hereNow:(NSDictionary *)response onChannel:(NSString *)channel
@@ -7,8 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
- C866C144162D5EB1008A7F89 /* CL_215.m in Sources */ = {isa = PBXBuildFile; fileRef = C866C143162D5EB1008A7F89 /* CL_215.m */; };
- C866C148162D61FF008A7F89 /* CommonUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = C866C147162D61FF008A7F89 /* CommonUtil.m */; };
C8F6538915B98D2C008535CE /* Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6537C15B98D2C008535CE /* Base64.m */; };
C8F6538A15B98D2C008535CE /* CEPubnub.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6537E15B98D2C008535CE /* CEPubnub.m */; };
C8F6538B15B98D2C008535CE /* Cipher.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538015B98D2C008535CE /* Cipher.m */; };
@@ -26,11 +24,6 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- C866C142162D5EB1008A7F89 /* CL_215.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CL_215.h; sourceTree = "<group>"; };
- C866C143162D5EB1008A7F89 /* CL_215.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CL_215.m; sourceTree = "<group>"; };
- C866C146162D61FE008A7F89 /* CommonUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonUtil.h; sourceTree = "<group>"; };
- C866C147162D61FF008A7F89 /* CommonUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUtil.m; sourceTree = "<group>"; };
- C8C1CDEE161C424800FE66B6 /* CEPubnubDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CEPubnubDelegate.h; sourceTree = "<group>"; };
C8F6537B15B98D2C008535CE /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
C8F6537C15B98D2C008535CE /* Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Base64.m; sourceTree = "<group>"; };
C8F6537D15B98D2C008535CE /* CEPubnub.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CEPubnub.h; sourceTree = "<group>"; };
@@ -76,7 +69,6 @@
C8F6537A15B98D2C008535CE /* PubNub */ = {
isa = PBXGroup;
children = (
- C8C1CDEE161C424800FE66B6 /* CEPubnubDelegate.h */,
C8F6537B15B98D2C008535CE /* Base64.h */,
C8F6537C15B98D2C008535CE /* Base64.m */,
C8F6537D15B98D2C008535CE /* CEPubnub.h */,
@@ -131,10 +123,6 @@
C8FD6F5F15B93F9C00A299E6 /* ViewController.h */,
C8FD6F6015B93F9C00A299E6 /* ViewController.m */,
C8FD6F5115B93F9C00A299E6 /* Supporting Files */,
- C866C142162D5EB1008A7F89 /* CL_215.h */,
- C866C143162D5EB1008A7F89 /* CL_215.m */,
- C866C146162D61FE008A7F89 /* CommonUtil.h */,
- C866C147162D61FF008A7F89 /* CommonUtil.m */,
);
path = PubnubTest;
sourceTree = "<group>";
@@ -221,8 +209,6 @@
C8F6538C15B98D2C008535CE /* Common.m in Sources */,
C8F6538D15B98D2C008535CE /* JSON.m in Sources */,
C8F6538E15B98D2C008535CE /* JSONKit.m in Sources */,
- C866C144162D5EB1008A7F89 /* CL_215.m in Sources */,
- C866C148162D61FF008A7F89 /* CommonUtil.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -299,7 +285,6 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PubnubTest/PubnubTest-Prefix.pch";
INFOPLIST_FILE = "PubnubTest/PubnubTest-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 5.1;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -311,7 +296,6 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PubnubTest/PubnubTest-Prefix.pch";
INFOPLIST_FILE = "PubnubTest/PubnubTest-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 5.1;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -7,52 +7,26 @@
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
- filePath = "PubnubTest/CL_215.m"
- timestampString = "372078189.926125"
+ filePath = "PubnubTest/ViewController.m"
+ timestampString = "374051956.805014"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "53"
- endingLineNumber = "53"
- landmarkName = "-runCL_215UnitTest"
- landmarkType = "5">
- </FileBreakpoint>
- <FileBreakpoint
- shouldBeEnabled = "No"
- ignoreCount = "0"
- continueAfterRunningActions = "No"
- filePath = "PubnubTest/PubNub/CEPubnub.m"
- timestampString = "372077923.340544"
- startingColumnNumber = "9223372036854775807"
- endingColumnNumber = "9223372036854775807"
- startingLineNumber = "656"
- endingLineNumber = "656"
- landmarkName = "-connection:didCompleteWithResponse:"
- landmarkType = "5">
- </FileBreakpoint>
- <FileBreakpoint
- shouldBeEnabled = "No"
- ignoreCount = "0"
- continueAfterRunningActions = "No"
- filePath = "PubnubTest/PubNub/CEPubnub.m"
- timestampString = "372077923.340544"
- startingColumnNumber = "9223372036854775807"
- endingColumnNumber = "9223372036854775807"
- startingLineNumber = "945"
- endingLineNumber = "945"
- landmarkName = "-didSucceedPublishingMessageToChannel:withResponse:message:"
+ startingLineNumber = "404"
+ endingLineNumber = "404"
+ landmarkName = "-pubnub:presence:onChannel:"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
- filePath = "PubnubTest/CL_215.m"
- timestampString = "372078189.926125"
+ filePath = "PubnubTest/ViewController.m"
+ timestampString = "374051956.805014"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "132"
- endingLineNumber = "132"
- landmarkName = "-pubnub:hereNow:onChannel:"
+ startingLineNumber = "402"
+ endingLineNumber = "402"
+ landmarkName = "-pubnub:presence:onChannel:"
landmarkType = "5">
</FileBreakpoint>
</FileBreakpoints>
@@ -1,16 +0,0 @@
-//
-// CL_215.h
-// PubnubTest
-//
-// Created by itshastra on 16/10/12.
-//
-//
-
-#import <Foundation/Foundation.h>
-#import "CEPubnub.h"
-
-@interface CL_215:NSObject<CEPubnubDelegate>
--(void) runCL_215UnitTest;
-@property (strong) id<CEPubnubDelegate> delHolder;
-
-@end
@@ -1,147 +0,0 @@
-//
-// CL_215.m
-// PubnubTest
-//
-// Created by itshastra on 16/10/12.
-//
-//
-
-#import "CL_215.h"
-#import "CommonUtil.h"
-
-@implementation CL_215
-@synthesize delHolder;
-
--(id)getDelegate
-{
- return delHolder;
-}
-
--(id)init
-{
- delHolder=self;
- return self ;
-}
-
-NSString *_publish_key ,*_subscribe_key,*_secret_key,*_cipher_key,*_uuid;
-NSString *_crazy,*_channel;
-BOOL _ssl_on;
-CEPubnub *pubnub;
-
--(void) initParameter {
- _publish_key=_subscribe_key=_secret_key=_cipher_key=@"demo";
- _uuid=@"efc873ea-8512-45c2-b0c8-91c95b36a819";
- _ssl_on=NO;
- _crazy = @"~`!@#$%^&*(???)+=[]\\{}|;\':,./<>?abcd";
- pubnub = [[CEPubnub alloc] initWithPublishKey:_publish_key subscribeKey:_subscribe_key secretKey:_secret_key cipherKey:_cipher_key uuid:_uuid useSSL:NO];
-
- _channel=[NSString stringWithFormat:@"%d", (int)CFAbsoluteTimeGetCurrent()];
- NSLog(@"Channel:%@",_channel);
- NSLog(@"UUID:%@",_uuid);
-}
-
--(void)publishMessage
-{
- [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:_channel,@"channel",_crazy,@"message", nil]];
-
-}
-
--(void) runCL_215UnitTest
-{
- [self initParameter];
- [pubnub setDelegate:[self getDelegate]];
- [pubnub subscribe: _channel];
- [self publishMessage];
-
-
-
-}
-
-
-#pragma mark -
-#pragma mark CEPubnubDelegate stuff
-
-- (void)pubnub:(CEPubnub *)pubnub
-didSucceedPublishingMessageToChannel:(NSString *)channel
- withResponse:(id)response
- message:(id)message
-{
- [CommonUtil LogPass:YES WithMessage:@"Message sent sucessed."];
-
-}
-- (void) pubnub:(CEPubnub*)pubnub didFailPublishingMessageToChannel:(NSString*)channel error:(NSString*)error message:(id)message// "error" may be nil
-{
- NSLog(@"Publishing Error %@ \nFor Sent Message %@",error,message);
-}
-
-- (void) pubnub:(CEPubnub*)pubnub subscriptionDidFailWithResponse:(NSString *)message onChannel:(NSString *)channel
-{
- NSLog(@"Subscription Error: %@",message);
-}
-
-- (void) pubnub:(CEPubnub*)pubnub subscriptionDidReceiveDictionary:(NSDictionary *)message onChannel:(NSString *)channel{
-}
-
-- (void) pubnub:(CEPubnub*)pubnub subscriptionDidReceiveArray:(NSArray *)message onChannel:(NSString *)channel{
-}
-- (void) pubnub:(CEPubnub*)pubnub subscriptionDidReceiveString:(NSString *)message onChannel:(NSString *)channel{
- if([message isEqualToString:_crazy])
- {
- [CommonUtil LogPass:YES WithMessage:@"Message recevied."];
- }else
- {
- [CommonUtil LogPass:NO WithMessage:@"Message recevied."];
- }
- [pubnub hereNow: _channel];
-}
-
-- (void) pubnub:(CEPubnub*)pubnub didFetchHistory:(NSArray*)messages forChannel:(NSString*)channel{
-}
-
--(void) pubnub:(CEPubnub *)pubnub didFailFetchHistoryOnChannel:(NSString *)channel withError:(id)error{
-}
-
--(void) pubnub:(CEPubnub *)pubnub didFetchDetailedHistory:(NSArray *)messages forChannel:(NSString *)channel{
-
-}
-
--(void) pubnub:(CEPubnub *)pubnub didFailFetchDetailedHistoryOnChannel:(NSString *)channel withError:(id)error{
-}
-
-- (void) pubnub:(CEPubnub*)pubnub didReceiveTime:(NSTimeInterval)time{
- NSLog(@"Time: %f",time);
-}
-
-- (void) pubnub:(CEPubnub*)pubnub ConnectToChannel:(NSString *)channel{
- NSLog(@"Connect to Channel: %@",channel);
-}
-
-- (void) pubnub:(CEPubnub*)pubnub DisconnectToChannel:(NSString *)channel{
- NSLog(@"Disconnect to Channel: %@",channel);
-}
-- (void) pubnub:(CEPubnub*)pubnub Re_ConnectToChannel:(NSString *)channel{
- NSLog(@"Re-Connect to Channel: %@",channel);
-}
-
-- (void)pubnub:(CEPubnub *)pubnub presence:(NSDictionary *)message onChannel:(NSString *)channel{
-
-}
-
-- (void)pubnub:(CEPubnub *)pubnub hereNow:(NSDictionary *)message onChannel:(NSString *)channel
-{
- NSArray *uuids=[message objectForKey:@"uuids"];
- for (NSString *uuid in uuids) {
- if([uuid isEqualToString:_uuid])
- {
- NSLog(@"Receved UUID:%@",uuid);
- [CommonUtil LogPass:YES WithMessage:@"UUID unit test."];
- }else
- {
- [CommonUtil LogPass:NO WithMessage:@"UUID unit test."];
- }
-
- }
-}
-
-
-@end
@@ -1,13 +0,0 @@
-//
-// CommonUtil.h
-// PubnubTest
-//
-// Created by itshastra on 16/10/12.
-//
-//
-
-#import <Foundation/Foundation.h>
-
-@interface CommonUtil : NSObject
-+(void)LogPass:(BOOL)pass WithMessage:(id)message;
-@end
Oops, something went wrong.

0 comments on commit ff9dcbf

Please sign in to comment.