diff --git a/Session/Calls/Call Management/SessionCall.swift b/Session/Calls/Call Management/SessionCall.swift index e5f438c3b..7c71c98da 100644 --- a/Session/Calls/Call Management/SessionCall.swift +++ b/Session/Calls/Call Management/SessionCall.swift @@ -256,10 +256,25 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { interactionId: interaction?.id, in: thread ) + .retry(5) // Start the timeout timer for the call .handleEvents(receiveOutput: { [weak self] _ in self?.setupTimeoutTimer() }) - .flatMap { _ in webRTCSession.sendOffer(to: thread) } - .sinkUntilComplete() + .flatMap { _ in + webRTCSession + .sendOffer(to: thread) + .retry(5) + } + .sinkUntilComplete( + receiveCompletion: { [weak self] result in + switch result { + case .finished: + SNLog("[Calls] Offer message sent") + case .failure(let error): + SNLog("[Calls] Error initializing call after 5 retries: \(error), ending call...") + self?.handleCallInitializationFailed() + } + } + ) } func answerSessionCall() { @@ -292,6 +307,11 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { hasEnded = true } + func handleCallInitializationFailed() { + self.endSessionCall() + Singleton.callManager.reportCurrentCallEnded(reason: nil) + } + // MARK: - Call Message Handling public func updateCallMessage(mode: EndCallMode, using dependencies: Dependencies) { diff --git a/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift b/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift index ddbe690b1..5bac29a03 100644 --- a/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift +++ b/Session/Calls/WebRTC/WebRTCSession+MessageHandling.swift @@ -22,7 +22,9 @@ extension WebRTCSession { else { guard sdp.type == .offer else { return } - self?.sendAnswer(to: sessionId).sinkUntilComplete() + self?.sendAnswer(to: sessionId) + .retry(5) + .sinkUntilComplete() } }) } diff --git a/Session/Calls/WebRTC/WebRTCSession.swift b/Session/Calls/WebRTC/WebRTCSession.swift index 4281998e0..b766b862c 100644 --- a/Session/Calls/WebRTC/WebRTCSession.swift +++ b/Session/Calls/WebRTC/WebRTCSession.swift @@ -375,6 +375,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { MessageSender .sendImmediate(data: preparedSendData, using: dependencies) .subscribe(on: DispatchQueue.global(qos: .userInitiated)) + .retry(5) .sinkUntilComplete() }