diff --git a/SessionMessagingKit/Calls/WebRTCSession.swift b/SessionMessagingKit/Calls/WebRTCSession.swift index c2312cebc..ffe6b894a 100644 --- a/SessionMessagingKit/Calls/WebRTCSession.swift +++ b/SessionMessagingKit/Calls/WebRTCSession.swift @@ -139,7 +139,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { if let error = error { seal.reject(error) } else { - guard let self = self, let sdp = sdp else { preconditionFailure() } + guard let self = self, let sdp = self.correctSessionDescription(sdp: sdp) else { preconditionFailure() } self.peerConnection.setLocalDescription(sdp) { error in if let error = error { print("Couldn't initiate call due to error: \(error).") @@ -171,7 +171,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { if let error = error { seal.reject(error) } else { - guard let self = self, let sdp = sdp else { preconditionFailure() } + guard let self = self, let sdp = self.correctSessionDescription(sdp: sdp) else { preconditionFailure() } self.peerConnection.setLocalDescription(sdp) { error in if let error = error { print("Couldn't accept call due to error: \(error).") @@ -244,6 +244,13 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { return RTCMediaConstraints(mandatoryConstraints: mandatory, optionalConstraints: optional) } + private func correctSessionDescription(sdp: RTCSessionDescription?) -> RTCSessionDescription? { + guard let sdp = sdp else { return nil } + let cbrSdp = sdp.description.replace(regex: "(a=fmtp:111 ((?!cbr=).)*)\r?\n", with: "$1;cbr=1\r\n") + let finalSdp = cbrSdp.replace(regex: ".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", with: "") + return RTCSessionDescription(type: sdp.type, sdp: finalSdp) + } + // MARK: Peer connection delegate public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCSignalingState) { print("[Calls] Signaling state changed to: \(state).") diff --git a/SessionUtilitiesKit/General/NSRegularExpression+SSK.swift b/SessionUtilitiesKit/General/NSRegularExpression+SSK.swift index c8eb33d21..891526aff 100644 --- a/SessionUtilitiesKit/General/NSRegularExpression+SSK.swift +++ b/SessionUtilitiesKit/General/NSRegularExpression+SSK.swift @@ -81,6 +81,12 @@ extension String { public var completeNSRange: NSRange { NSRange(completeRange, in: self) } + + public func replace(regex: String, with template: String) -> String { + let regex = try! NSRegularExpression(pattern: regex, options: .caseInsensitive) + let range = self.completeNSRange + return regex.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: template) + } } extension NSTextCheckingResult {