29
loading...
This website collects cookies to deliver better user experience
if ([error.domain isEqualToString:PTDiffusionSessionErrorDomain]) {
[self.session close];
self.session = nil;
[self connectToURL:self->_url withCompletionHandler:nil];
}
} else {
NSLog(@"Ping successful (%dms)", (int) round(details.roundTripTime * 1000));
}
}];
} else {
NSLog(No session detected. Aborting");
}
_currentAttempt += 1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[attempt start];
});
// if a connection attempt was made in the past of this session, _lastConnectionAttempt has a value set)
if (_lastConnectionAttempt) {
NSTimeInterval elapsedSinceLastConnection = [[NSDate date] timeIntervalSinceDate:_lastConnectionAttempt];
if (elapsedSinceLastConnection > delay * 2) {
_currentAttempt = 0;
delay = MIN(_currentAttempt * _delayIncrementation, _maxDelay);
}
}
_lastConnectionAttempt = [NSDate date];
_currentAttempt += 1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[attempt start];
});