Private
Public Access
1
0

Adds websocket updates via the /updates endpoint

This commit is contained in:
James Magahern
2023-01-17 16:16:23 -08:00
parent 56ae7982c6
commit 2f5d50188b
9 changed files with 181 additions and 53 deletions

View File

@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import <CocoaHTTPServer/HTTPMessage.h>
#import <CocoaHTTPServer/HTTPResponse.h>
#import <CocoaHTTPServer/HTTPErrorResponse.h>
@@ -20,6 +21,7 @@ typedef void (^MBIMBridgeOperationCompletionBlock)(NSObject<HTTPResponse> * _Nul
@property (class, nonatomic, readonly) NSString *endpointName;
@property (class, nonatomic, readonly) BOOL requiresAuthentication; // default YES
@property (nonatomic, strong) HTTPMessage *request;
@property (nonatomic, strong) NSData *requestBodyData;
@property (nonatomic, readonly) NSURL *requestURL;
@property (nonatomic, readonly) MBIMBridgeOperationCompletionBlock serverCompletionBlock;

View File

@@ -7,6 +7,7 @@
//
#import "MBIMBridgeOperation.h"
#import "MBIMURLUtilities.h"
@interface MBIMBridgeOperation (/*INTERNAL*/)
@property (nonatomic, strong) NSURL *requestURL;
@@ -79,18 +80,7 @@
- (NSString *)valueForQueryItemWithName:(NSString *)queryItemName
{
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:self.requestURL
resolvingAgainstBaseURL:NO];
NSString *value = nil;
for (NSURLQueryItem *queryItem in [urlComponents queryItems]) {
if ([[queryItem name] isEqualToString:queryItemName]) {
value = [queryItem value];
break;
}
}
return value;
return [[self requestURL] valueForQueryItemWithName:queryItemName];
}
@end

View File

@@ -40,13 +40,13 @@
weakSelf.serverCompletionBlock(response);
};
[[MBIMUpdateQueue sharedInstance] addConsumer:_updateConsumer withLastSyncedMessageSeq:messageSeq];
[[MBIMUpdateQueue sharedInstance] addPollingConsumer:_updateConsumer withLastSyncedMessageSeq:messageSeq];
}
- (void)cancel
{
[super cancel];
[[MBIMUpdateQueue sharedInstance] removeConsumer:_updateConsumer];
[[MBIMUpdateQueue sharedInstance] removePollingConsumer:_updateConsumer];
}
- (NSObject<HTTPResponse> *)cancelAndReturnTimeoutResponse

View File

@@ -0,0 +1,17 @@
//
// MBIMURLUtilities.h
// kordophoned
//
// Created by James Magahern on 1/17/23.
// Copyright © 2023 James Magahern. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSURL (MBIMURLUtilities)
- (nullable NSString *)valueForQueryItemWithName:(NSString *)queryItemName;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,28 @@
//
// MBIMURLUtilities.m
// kordophoned
//
// Created by James Magahern on 1/17/23.
// Copyright © 2023 James Magahern. All rights reserved.
//
#import "MBIMURLUtilities.h"
@implementation NSURL (MBIMURLUtilities)
- (nullable NSString *)valueForQueryItemWithName:(NSString *)queryItemName
{
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:self resolvingAgainstBaseURL:NO];
NSString *value = nil;
for (NSURLQueryItem *queryItem in [urlComponents queryItems]) {
if ([[queryItem name] isEqualToString:queryItemName]) {
value = [queryItem value];
break;
}
}
return value;
}
@end