mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
WebSocket reconnect. Casting issues.
This commit is contained in:
parent
1e3dd3d946
commit
bf9084a7c8
8 changed files with 38 additions and 18 deletions
|
@ -45,7 +45,6 @@ typedef void(^ABReloadRequestCompletionBlock)(NSArray *contacts);
|
|||
- (NSArray*)textSecureContacts;
|
||||
|
||||
- (BOOL)isContactRegisteredWithRedPhone:(Contact*)contact;
|
||||
- (BOOL)isContactRegisteredWithTextSecure:(Contact*)contact;
|
||||
|
||||
-(void)doAfterEnvironmentInitSetup;
|
||||
|
||||
|
|
|
@ -29,5 +29,8 @@
|
|||
return self.attachements?(self.attachements.count>0):false;
|
||||
}
|
||||
|
||||
- (NSString *)description{
|
||||
return self.body;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
@synchronized(self){
|
||||
TSStorageManager *storageManager = [TSStorageManager sharedManager];
|
||||
NSString *recipientId = secureMessage.source;
|
||||
int deviceId = secureMessage.sourceDevice;
|
||||
int deviceId = (int) secureMessage.sourceDevice;
|
||||
|
||||
if (![storageManager containsSession:recipientId deviceId:deviceId]) {
|
||||
// Deal with failure
|
||||
|
@ -127,7 +127,7 @@
|
|||
@synchronized(self){
|
||||
TSStorageManager *storageManager = [TSStorageManager sharedManager];
|
||||
NSString *recipientId = preKeyMessage.source;
|
||||
int deviceId = preKeyMessage.sourceDevice;
|
||||
int deviceId = (int)preKeyMessage.sourceDevice;
|
||||
|
||||
PushMessageContent *content;
|
||||
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
#import "Cryptography.h"
|
||||
#import "IncomingPushMessageSignal.pb.h"
|
||||
|
||||
#define kWebSocketHeartBeat 15
|
||||
#define kWebSocketHeartBeat 15
|
||||
#define kWebSocketReconnectTry 5
|
||||
|
||||
NSString * const SocketOpenedNotification = @"SocketOpenedNotification";
|
||||
NSString * const SocketClosedNotification = @"SocketClosedNotification";
|
||||
NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
|
||||
|
||||
@interface TSSocketManager ()
|
||||
@property (nonatomic, retain) NSTimer *timer;
|
||||
@property (nonatomic, retain) NSTimer *pingTimer;
|
||||
@property (nonatomic, retain) NSTimer *reconnectTimer;
|
||||
|
||||
@property (nonatomic, retain) SRWebSocket *websocket;
|
||||
@property (nonatomic) NSUInteger status;
|
||||
@end
|
||||
|
@ -94,14 +97,18 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
|
|||
#pragma mark - Delegate methods
|
||||
|
||||
- (void) webSocketDidOpen:(SRWebSocket *)webSocket {
|
||||
self.timer = [NSTimer scheduledTimerWithTimeInterval:kWebSocketHeartBeat target:self selector:@selector(webSocketHeartBeat) userInfo:nil repeats:YES];
|
||||
self.status = kSocketStatusOpen;
|
||||
self.pingTimer = [NSTimer scheduledTimerWithTimeInterval:kWebSocketHeartBeat target:self selector:@selector(webSocketHeartBeat) userInfo:nil repeats:YES];
|
||||
self.status = kSocketStatusOpen;
|
||||
|
||||
[self.reconnectTimer invalidate];
|
||||
self.reconnectTimer = nil;
|
||||
}
|
||||
|
||||
- (void) webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error {
|
||||
DDLogError(@"Error connecting to socket %@", error);
|
||||
[self.timer invalidate];
|
||||
[self.pingTimer invalidate];
|
||||
self.status = kSocketStatusClosed;
|
||||
[self scheduleRetry];
|
||||
}
|
||||
|
||||
- (void) webSocket:(SRWebSocket *)webSocket didReceiveMessage:(NSData*)data {
|
||||
|
@ -161,8 +168,9 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
|
|||
|
||||
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean {
|
||||
DDLogVerbose(@"WebSocket did close");
|
||||
[self.timer invalidate];
|
||||
[self.pingTimer invalidate];
|
||||
self.status = kSocketStatusClosed;
|
||||
[self scheduleRetry];
|
||||
}
|
||||
|
||||
- (void)webSocketHeartBeat {
|
||||
|
@ -173,6 +181,12 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
|
|||
return [NSString stringWithFormat:@"?login=%@&password=%@", [[TSAccountManager registeredNumber] stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"],[TSStorageManager serverAuthToken]];
|
||||
}
|
||||
|
||||
- (void)scheduleRetry{
|
||||
if (!self.reconnectTimer || ![self.reconnectTimer isValid]) {
|
||||
self.reconnectTimer = [NSTimer scheduledTimerWithTimeInterval:kWebSocketReconnectTry target:[self class] selector:@selector(becomeActive) userInfo:nil repeats:YES];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark UI Delegates
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
@implementation NSDate (millisecondTimeStamp)
|
||||
|
||||
+ (uint64_t)ows_millisecondTimeStamp{
|
||||
uint64_t milliseconds = std::chrono::system_clock::now().time_since_epoch()/std::chrono::milliseconds(1);
|
||||
uint64_t milliseconds = (uint64_t) (std::chrono::system_clock::now().time_since_epoch()/std::chrono::milliseconds(1));
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
|
|
|
@ -172,12 +172,12 @@ typedef enum : NSUInteger {
|
|||
|
||||
- (id<JSQMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView messageDataForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return [TSMessageAdapter messageViewDataWithInteraction:[self messageAtIndexPath:indexPath] inThread:_thread];
|
||||
return [self messageAtIndexPath:indexPath];
|
||||
}
|
||||
|
||||
- (id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
id<JSQMessageData> message = [TSMessageAdapter messageViewDataWithInteraction:[self messageAtIndexPath:indexPath] inThread:_thread];
|
||||
id<JSQMessageData> message = [self messageAtIndexPath:indexPath];
|
||||
|
||||
if ([message.senderId isEqualToString:self.senderId]) {
|
||||
return self.outgoingBubbleImageData;
|
||||
|
@ -198,7 +198,7 @@ typedef enum : NSUInteger {
|
|||
/**
|
||||
* Override point for customizing cells
|
||||
*/
|
||||
id<JSQMessageData> msg = [TSMessageAdapter messageViewDataWithInteraction:[self messageAtIndexPath:indexPath] inThread:_thread];
|
||||
id<JSQMessageData> msg = [self messageAtIndexPath:indexPath];
|
||||
|
||||
|
||||
JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
|
||||
|
@ -247,8 +247,8 @@ typedef enum : NSUInteger {
|
|||
showDate = YES;
|
||||
}
|
||||
else {
|
||||
TSInteraction *currentMessage = [self messageAtIndexPath:indexPath];
|
||||
TSInteraction *previousMessage = [self messageAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row-1 inSection:indexPath.section]];
|
||||
TSMessageAdapter *currentMessage = [self messageAtIndexPath:indexPath];
|
||||
TSMessageAdapter *previousMessage = [self messageAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row-1 inSection:indexPath.section]];
|
||||
|
||||
NSTimeInterval timeDifference = [currentMessage.date timeIntervalSinceDate:previousMessage.date];
|
||||
if (timeDifference > kTSMessageSentDateShowTimeInterval) {
|
||||
|
@ -433,7 +433,7 @@ typedef enum : NSUInteger {
|
|||
return numberOfMessages;
|
||||
}
|
||||
|
||||
- (TSInteraction*)messageAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (TSMessageAdapter*)messageAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
__block TSInteraction *message = nil;
|
||||
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
|
@ -450,7 +450,7 @@ typedef enum : NSUInteger {
|
|||
message = [viewTransaction objectAtRow:row inSection:section withMappings:self.messageMappings];
|
||||
NSParameterAssert(message != nil);
|
||||
}];
|
||||
return message;
|
||||
return [TSMessageAdapter messageViewDataWithInteraction:message inThread:self.thread];
|
||||
}
|
||||
|
||||
#pragma mark Accessory View
|
||||
|
|
|
@ -10,4 +10,6 @@
|
|||
|
||||
@interface SettingsTableViewController : UITableViewController
|
||||
|
||||
@property IBOutlet UILabel *registeredNumber;
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#import "DJWActionSheet.h"
|
||||
#import "SettingsTableViewCell.h"
|
||||
|
||||
#import "TSAccountManager.h"
|
||||
|
||||
#define kProfileCellHeight 87.0f
|
||||
#define kStandardCellHeight 60.0f
|
||||
|
||||
|
@ -38,7 +40,7 @@ typedef enum {
|
|||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
|
||||
self.registeredNumber.text = [TSAccountManager registeredNumber];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
|
|
Loading…
Reference in a new issue