Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Added overload to unsubscribe from a collection immediately #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[submodule "Vendor/PocketSocket"]
path = Vendor/PocketSocket
url = git://github.com/zwopple/PocketSocket.git
branch = develop
[submodule "Vendor/InflectorKit"]
path = Vendor/InflectorKit
url = git://github.com/mattt/InflectorKit.git
Expand Down
3 changes: 3 additions & 0 deletions Meteor/METDDPClient+AccountsPassword.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ NS_ASSUME_NONNULL_BEGIN

- (void)loginWithEmail:(NSString *)email password:(NSString *)password completionHandler:(nullable METLogInCompletionHandler)completionHandler;

/// @name Logging In with Parameters (e.g. Facebook Token, needs custom login handler on server side)
- (void)loginWithMethodName:(NSString *)methodName parameters:(nullable NSArray *)parameters completionHandler:(nullable METLogInCompletionHandler)completionHandler;

/// @name Signing Up with Password

- (void)signUpWithEmail:(NSString *)email password:(NSString *)password completionHandler:(nullable METLogInCompletionHandler)completionHandler;
Expand Down
1 change: 1 addition & 0 deletions Meteor/METDDPClient.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typedef void (^METLogOutCompletionHandler)(NSError * __nullable error);
- (METSubscription *)addSubscriptionWithName:(NSString *)name parameters:(nullable NSArray *)parameters;
- (METSubscription *)addSubscriptionWithName:(NSString *)name parameters:(nullable NSArray *)parameters completionHandler:(nullable METSubscriptionCompletionHandler)completionHandler;
- (void)removeSubscription:(METSubscription *)subscription;
- (void)removeSubscription:(METSubscription *)subscription immediately:(BOOL)immediately completionHandler:(nullable METSubscriptionCompletionHandler)completionHandler;

#pragma mark - Method Invocations
/// @name Defining Method Stubs
Expand Down
6 changes: 5 additions & 1 deletion Meteor/METDDPClient.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,11 @@ - (void)sendSubMessageForSubscription:(METSubscription *)subscription {
}

- (void)removeSubscription:(METSubscription *)subscription {
[_subscriptionManager removeSubscription:subscription];
[self removeSubscription:subscription immediately:NO completionHandler:nil];
}

- (void)removeSubscription:(METSubscription *)subscription immediately:(BOOL)immediately completionHandler:(nullable METSubscriptionCompletionHandler)completionHandler {
[_subscriptionManager removeSubscription:subscription immediately:immediately completionHandler:completionHandler];
}

- (void)sendUnsubMessageForSubscription:(METSubscription *)subscription {
Expand Down
2 changes: 1 addition & 1 deletion Meteor/METSubscriptionManager.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) NSTimeInterval defaultNotInUseTimeout;

- (METSubscription *)addSubscriptionWithName:(NSString *)name parameters:(nullable NSArray *)parameters completionHandler:(nullable METSubscriptionCompletionHandler)completionHandler;
- (void)removeSubscription:(METSubscription *)subscription;
- (void)removeSubscription:(METSubscription *)subscription immediately:(BOOL)immediately completionHandler:(nullable METSubscriptionCompletionHandler)completionHandler;

- (void)didReceiveReadyForSubscriptionWithID:(NSString *)subscriptionID;
- (void)didReceiveNosubForSubscriptionWithID:(NSString *)subscriptionID error:(NSError *)error;
Expand Down
47 changes: 32 additions & 15 deletions Meteor/METSubscriptionManager.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ @interface METSubscriptionManager ()

@end

NSString * const METSubscriptionManagerErrorDomain = @"com.meteor.SubscriptionManager.ErrorDomain";

@implementation METSubscriptionManager {
dispatch_queue_t _queue;
NSMutableDictionary *_subscriptionsByID;
Expand Down Expand Up @@ -97,7 +99,7 @@ - (METSubscription *)existingSubscriptionWithName:(NSString *)name parameters:(N
return existingSubscription;
}

- (void)removeSubscription:(METSubscription *)subscription {
- (void)removeSubscription:(METSubscription *)subscription immediately:(BOOL)immediately completionHandler:(nullable METSubscriptionCompletionHandler)completionHandler {
NSParameterAssert(subscription);

dispatch_async(_queue, ^{
Expand All @@ -106,25 +108,40 @@ - (void)removeSubscription:(METSubscription *)subscription {
if (!subscription.inUse) {
[self removeSubscriptionToBeRevivedAfterConnect:subscription];

if (subscription.reuseTimer == nil) {
subscription.reuseTimer = [[METTimer alloc] initWithQueue:_queue block:^{
// Subscription was reused before timeout
if (subscription.inUse) {
return;
}

[_subscriptionsByID removeObjectForKey:subscription.identifier];

if (_client.connected) {
[_client sendUnsubMessageForSubscription:subscription];
}
}];
if (immediately) {
[self removeSubscription:subscription completionHandler:completionHandler];
} else {
if (subscription.reuseTimer == nil) {
subscription.reuseTimer = [[METTimer alloc] initWithQueue:_queue block:^{
// Subscription was reused before timeout
if (subscription.inUse) {
return;
}
[self removeSubscription:subscription completionHandler:completionHandler];
}];
}
[subscription.reuseTimer startWithTimeInterval:subscription.notInUseTimeout];
}
[subscription.reuseTimer startWithTimeInterval:subscription.notInUseTimeout];
}
});
}

- (void)removeSubscription:(METSubscription *)subscription completionHandler:(METSubscriptionCompletionHandler)completionHandler {
[_subscriptionsByID removeObjectForKey:subscription.identifier];

NSError *error = nil;

if (_client.connected) {
[_client sendUnsubMessageForSubscription:subscription];
} else {
error = [NSError errorWithDomain:METSubscriptionManagerErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: @"Client is not connected"}];
}

if (completionHandler) {
completionHandler(error);
}
}

- (void)didReceiveReadyForSubscriptionWithID:(NSString *)subscriptionID {
NSParameterAssert(subscriptionID);

Expand Down
2 changes: 1 addition & 1 deletion Vendor/PocketSocket
Submodule PocketSocket updated 37 files
+3 −0 .gitignore
+1 −1 PSAutobahnClientTests/PSAutobahnClientTests-Info.plist
+14 −5 PSAutobahnClientTests/PSAutobahnClientTests.m
+1 −1 PSAutobahnClientTests/PSAutobahnClientWebSocketOperation.h
+1 −1 PSAutobahnClientTests/PSAutobahnClientWebSocketOperation.m
+17 −0 PSAutobahnServerTests/AppDelegate.h
+55 −0 PSAutobahnServerTests/AppDelegate.m
+38 −0 PSAutobahnServerTests/Assets.xcassets/AppIcon.appiconset/Contents.json
+27 −0 PSAutobahnServerTests/Base.lproj/LaunchScreen.storyboard
+25 −0 PSAutobahnServerTests/Base.lproj/Main.storyboard
+40 −0 PSAutobahnServerTests/Info.plist
+15 −0 PSAutobahnServerTests/ViewController.h
+27 −0 PSAutobahnServerTests/ViewController.m
+16 −0 PSAutobahnServerTests/main.m
+23 −8 PocketSocket.podspec
+281 −7 PocketSocket.xcodeproj/project.pbxproj
+80 −0 PocketSocket.xcodeproj/xcshareddata/xcschemes/PocketSocket-Mac.xcscheme
+99 −0 PocketSocket.xcodeproj/xcshareddata/xcschemes/PocketSocket.xcscheme
+12 −3 PocketSocket/PSWebSocket.h
+232 −138 PocketSocket/PSWebSocket.m
+1 −1 PocketSocket/PSWebSocketBuffer.h
+1 −1 PocketSocket/PSWebSocketBuffer.m
+1 −1 PocketSocket/PSWebSocketDeflater.h
+1 −1 PocketSocket/PSWebSocketDeflater.m
+3 −2 PocketSocket/PSWebSocketDriver.h
+115 −70 PocketSocket/PSWebSocketDriver.m
+1 −1 PocketSocket/PSWebSocketInflater.h
+2 −2 PocketSocket/PSWebSocketInflater.m
+52 −2 PocketSocket/PSWebSocketInternal.h
+1 −1 PocketSocket/PSWebSocketNetworkThread.h
+2 −2 PocketSocket/PSWebSocketNetworkThread.m
+7 −2 PocketSocket/PSWebSocketServer.h
+103 −30 PocketSocket/PSWebSocketServer.m
+5 −1 PocketSocket/PSWebSocketTypes.h
+2 −2 PocketSocket/PSWebSocketUTF8Decoder.h
+1 −1 PocketSocket/PSWebSocketUTF8Decoder.m
+10 −6 README.md
2 changes: 1 addition & 1 deletion Vendor/SimpleKeychain
2 changes: 1 addition & 1 deletion Vendor/ocmock
Submodule ocmock updated 130 files