Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature close on timeout #299

Open
wants to merge 11 commits into
base: feature-dev
Choose a base branch
from
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xcodeproj 'SignalR.Client.ObjC/SignalR.Client.ObjC'
project 'SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj'
workspace 'SignalR.Client.ObjC'

target "SignalR.Client.iOS" do
Expand All @@ -23,4 +23,4 @@ target :"SignalR.Client.OSX" do
target :"SignalR.Client.OSXTests" do
pod 'OCMock'
end
end
end
10 changes: 9 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ DEPENDENCIES:
- OCMock
- SocketRocket (= 0.4.2)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- AFNetworking
- OCMock
- SocketRocket

SPEC CHECKSUMS:
AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60
OCMock: 18c9b7e67d4c2770e95bb77a9cc1ae0c91fe3835
SocketRocket: ffe08119b00ef982f6c37052a4705a057c8494ad

COCOAPODS: 0.39.0
PODFILE CHECKSUM: b3a3a58c75f13f9a520b6c950906fdd364953a26

COCOAPODS: 1.5.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
122 changes: 101 additions & 21 deletions SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
39302A211C69768D0061C6B5 /* SRServerSentEventsTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 3920786115AF13F6009B959E /* SRServerSentEventsTransport.m */; };
39302A221C69768D0061C6B5 /* SRWebSocketTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 39AF0D7D17138E3800E13E6E /* SRWebSocketTransport.m */; };
39302A231C6976A30061C6B5 /* SRSubscription.m in Sources */ = {isa = PBXBuildFile; fileRef = 3920783615AF13F6009B959E /* SRSubscription.m */; };
39302A271C6977800061C6B5 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 39302A251C6977800061C6B5 /* Info.plist */; };
39302A281C6977800061C6B5 /* SignalR.h in Headers */ = {isa = PBXBuildFile; fileRef = 39302A261C6977800061C6B5 /* SignalR.h */; };
39302A381C6978AC0061C6B5 /* SignalR.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39302A2E1C6978AB0061C6B5 /* SignalR.framework */; };
39302A451C6979E10061C6B5 /* SRHubConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 3920782715AF13F6009B959E /* SRHubConnection.m */; };
Expand Down Expand Up @@ -522,12 +521,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 39302A051C6974C20061C6B5 /* Build configuration list for PBXNativeTarget "SignalR.Client.OSX" */;
buildPhases = (
759DD48E5A906D4D2714F305 /* [CP] Check Pods Manifest.lock */,
BE773CA6D603623DBCDFD6AF /* Check Pods Manifest.lock */,
393029EF1C6974C10061C6B5 /* Sources */,
393029F01C6974C10061C6B5 /* Frameworks */,
393029F11C6974C10061C6B5 /* Headers */,
393029F21C6974C10061C6B5 /* Resources */,
7C5BAF419D1DB75581A41B87 /* Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -542,12 +541,13 @@
isa = PBXNativeTarget;
buildConfigurationList = 39302A081C6974C20061C6B5 /* Build configuration list for PBXNativeTarget "SignalR.Client.OSXTests" */;
buildPhases = (
29F8A99392528EEAD6A859C3 /* [CP] Check Pods Manifest.lock */,
537C4819A81E84FE2982C1CF /* Check Pods Manifest.lock */,
393029F91C6974C20061C6B5 /* Sources */,
393029FA1C6974C20061C6B5 /* Frameworks */,
393029FB1C6974C20061C6B5 /* Resources */,
67E90B84652BAD667E4611D1 /* Embed Pods Frameworks */,
0B029DDB5BC07F36BE28C47C /* Copy Pods Resources */,
ED3F4313A751EA87E66F745B /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -563,12 +563,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 39302A3F1C6978AC0061C6B5 /* Build configuration list for PBXNativeTarget "SignalR.Client.iOS" */;
buildPhases = (
A48F4A4D58939ECEEB8E687E /* [CP] Check Pods Manifest.lock */,
42E081C85DE4F4916D0F3D75 /* Check Pods Manifest.lock */,
39302A291C6978AB0061C6B5 /* Sources */,
39302A2A1C6978AB0061C6B5 /* Frameworks */,
39302A2B1C6978AB0061C6B5 /* Headers */,
39302A2C1C6978AB0061C6B5 /* Resources */,
796268F885EFEC8F1356854A /* Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -583,12 +583,13 @@
isa = PBXNativeTarget;
buildConfigurationList = 39302A421C6978AC0061C6B5 /* Build configuration list for PBXNativeTarget "SignalR.Client.iOSTests" */;
buildPhases = (
EF8CD3D9CD825628C4319223 /* [CP] Check Pods Manifest.lock */,
21C56E6B6FDFA0220435E7AD /* Check Pods Manifest.lock */,
39302A331C6978AC0061C6B5 /* Sources */,
39302A341C6978AC0061C6B5 /* Frameworks */,
39302A351C6978AC0061C6B5 /* Resources */,
2AC719B5534D658A6E1038BA /* Embed Pods Frameworks */,
1A11AFB25C13B6568AF7E084 /* Copy Pods Resources */,
239C11727851DAB652DA48A3 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -648,7 +649,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
39302A271C6977800061C6B5 /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -676,49 +676,67 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0B029DDB5BC07F36BE28C47C /* Copy Pods Resources */ = {
21C56E6B6FDFA0220435E7AD /* Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests-resources.sh\"\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
1A11AFB25C13B6568AF7E084 /* Copy Pods Resources */ = {
239C11727851DAB652DA48A3 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
"${BUILT_PRODUCTS_DIR}/SocketRocket-iOS/SocketRocket.framework",
"${BUILT_PRODUCTS_DIR}/OCMock-iOS/OCMock.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
name = "Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SocketRocket.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests-resources.sh\"\n";
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
21C56E6B6FDFA0220435E7AD /* Check Pods Manifest.lock */ = {
29F8A99392528EEAD6A859C3 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
name = "Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
2AC719B5534D658A6E1038BA /* Embed Pods Frameworks */ = {
Expand Down Expand Up @@ -781,34 +799,48 @@
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
796268F885EFEC8F1356854A /* Copy Pods Resources */ = {
759DD48E5A906D4D2714F305 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
name = "Copy Pods Resources";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-SignalR.Client.OSX-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.iOS/Pods-SignalR.Client.iOS-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
7C5BAF419D1DB75581A41B87 /* Copy Pods Resources */ = {
A48F4A4D58939ECEEB8E687E /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
name = "Copy Pods Resources";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-SignalR.Client.iOS-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.OSX/Pods-SignalR.Client.OSX-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
BE773CA6D603623DBCDFD6AF /* Check Pods Manifest.lock */ = {
Expand All @@ -826,6 +858,54 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
ED3F4313A751EA87E66F745B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AFNetworking-93a4f461/AFNetworking.framework",
"${BUILT_PRODUCTS_DIR}/SocketRocket-macOS/SocketRocket.framework",
"${BUILT_PRODUCTS_DIR}/OCMock-macOS/OCMock.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SocketRocket.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests/Pods-SignalR.Client.OSX-SignalR.Client.OSXTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
EF8CD3D9CD825628C4319223 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-SignalR.Client.iOS-SignalR.Client.iOSTests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
34 changes: 33 additions & 1 deletion SignalR.Client/SRConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ @interface SRConnection ()
@property (strong, nonatomic, readwrite) NSString *connectionData;
@property (strong, nonatomic, readwrite) SRHeartbeatMonitor *monitor;

@property (strong, nonatomic, readwrite) id <SRClientTransportInterface> transport;
@property (strong, nonatomic, readwrite) NSDate* lastActive;
@property (strong, nonatomic, readwrite) NSNumber* reconnectWindow;

- (void)negotiate:(id <SRClientTransportInterface>)transport;
- (void)verifyProtocolVersion:(NSString *)versionString;
- (NSString *)createUserAgentString:(NSString *)client;
Expand All @@ -67,6 +71,9 @@ @implementation SRConnection
@synthesize transport = _transport;
@synthesize credentials = _credentials;
@synthesize headers = _headers;
@synthesize lastActive = _lastActive;
@synthesize reconnectWindow = _reconnectWindow;


#pragma mark -
#pragma mark Initialization
Expand Down Expand Up @@ -146,7 +153,10 @@ - (void)negotiate:(id<SRClientTransportInterface>)transport {

// If we have a keep alive
if (negotiationResponse.keepAliveTimeout != nil) {
_keepAliveData = [[SRKeepAliveData alloc] initWithTimeout:negotiationResponse.keepAliveTimeout];
strongSelf.keepAliveData = [[SRKeepAliveData alloc] initWithTimeout:negotiationResponse.keepAliveTimeout];
strongSelf.reconnectWindow = @([strongSelf.disconnectTimeout floatValue] + [strongSelf.keepAliveData.timeout floatValue]);
} else {
strongSelf.reconnectWindow = strongSelf.disconnectTimeout;
}

[strongSelf startTransport];
Expand Down Expand Up @@ -416,6 +426,28 @@ - (void)updateLastKeepAlive {
}
}

-(void)markActive{
if([self verifyLastActive]){
_lastActive = [NSDate date];
}
}

- (BOOL) verifyLastActive {
if (_lastActive == nil || _reconnectWindow == nil){
//todo figure out what really should go here
_lastActive = [NSDate date];
return YES;
}
NSTimeInterval timeElapsed = [[NSDate date] timeIntervalSinceDate: _lastActive];//number of seconds
if (timeElapsed > [_reconnectWindow floatValue]){
SRLogConnectionDebug(@"There has not been an active server connection for an extended period of time. Stopping connection.");
[self stop:_defaultAbortTimeout];
return NO;
}
return YES;
}


- (void)prepareRequest:(NSMutableURLRequest *)request {
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
[request addValue:[self createUserAgentString:NSLocalizedString(@"SignalR.Client.iOS",@"")] forHTTPHeaderField:@"User-Agent"];
Expand Down
2 changes: 2 additions & 0 deletions SignalR.Client/SRConnectionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
///-------------------------------

- (NSString *)onSending;//TODO: this just encapsulates connectionData. can we pull this into a getUrl like js client does?
- (BOOL) verifyLastActive;
- (void) markActive;

///-------------------------------
/// @name Connection Management
Expand Down
1 change: 1 addition & 0 deletions SignalR.Client/SRHeartbeatMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@property (assign, nonatomic, readonly, getter = hasBeenWarned) BOOL beenWarned;
@property (assign, nonatomic, readonly) BOOL timedOut;
@property (assign, nonatomic, readonly) BOOL monitorKeepAlive;

- (instancetype)initWithConnection:(id <SRConnectionInterface>)connection;
- (void)start;
Expand Down
Loading