handle busy
This commit is contained in:
parent
e7a6ddb4f1
commit
da14539639
|
@ -57,6 +57,7 @@ public final class SessionCallManager: NSObject {
|
|||
self.provider.setDelegate(self, queue: nil)
|
||||
}
|
||||
|
||||
// MARK: Report calls
|
||||
public func reportOutgoingCall(_ call: SessionCall) {
|
||||
AssertIsOnMainThread()
|
||||
call.stateDidChange = {
|
||||
|
@ -122,6 +123,18 @@ public final class SessionCallManager: NSObject {
|
|||
callUpdate.supportsDTMF = false
|
||||
}
|
||||
|
||||
public func handleIncomingCallOfferInBusyState(offerMessage: CallMessage, using transaction: YapDatabaseReadWriteTransaction) {
|
||||
guard let caller = offerMessage.sender, let thread = TSContactThread.fetch(for: caller, using: transaction) else { return }
|
||||
let message = CallMessage()
|
||||
message.uuid = offerMessage.uuid
|
||||
message.kind = .endCall
|
||||
print("[Calls] Sending end call message.")
|
||||
MessageSender.sendNonDurably(message, in: thread, using: transaction).retainUntilComplete()
|
||||
if let tsMessage = TSIncomingMessage.find(withAuthorId: caller, timestamp: offerMessage.sentTimestamp!, transaction: transaction) {
|
||||
tsMessage.updateCall(withNewBody: NSLocalizedString("call_missing", comment: ""), transaction: transaction)
|
||||
}
|
||||
}
|
||||
|
||||
internal func showCallModal() {
|
||||
let callModal = CallModal() { [weak self] in
|
||||
self?.showCallVC()
|
||||
|
|
|
@ -22,8 +22,13 @@ extension AppDelegate {
|
|||
|
||||
@objc func setUpCallHandling() {
|
||||
// Pre offer messages
|
||||
MessageReceiver.handlePreOfferCallMessage = { message in
|
||||
MessageReceiver.handlePreOfferCallMessage = { (message, transaction) in
|
||||
guard CurrentAppContext().isMainApp else { return }
|
||||
let callManager = AppEnvironment.shared.callManager
|
||||
guard callManager.currentCall == nil else {
|
||||
callManager.handleIncomingCallOfferInBusyState(offerMessage: message, using: transaction)
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if let caller = message.sender, let uuid = message.uuid {
|
||||
let call = SessionCall(for: caller, uuid: uuid, mode: .answer)
|
||||
|
|
|
@ -264,23 +264,9 @@ extension MessageReceiver {
|
|||
// MARK: - Call Messages
|
||||
|
||||
public static func handleCallMessage(_ message: CallMessage, using transaction: Any) {
|
||||
func getWebRTCSession() -> WebRTCSession {
|
||||
let result: WebRTCSession
|
||||
if let current = WebRTCSession.current {
|
||||
result = current
|
||||
} else {
|
||||
WebRTCSession.current = WebRTCSession(for: message.sender!, with: message.uuid!)
|
||||
result = WebRTCSession.current!
|
||||
}
|
||||
return result
|
||||
}
|
||||
switch message.kind! {
|
||||
case .preOffer:
|
||||
print("[Calls] Received pre-offer message.")
|
||||
if getWebRTCSession().uuid != message.uuid! {
|
||||
// TODO: Call in progress, put the new call on hold/reject
|
||||
return
|
||||
}
|
||||
let storage = SNMessagingKitConfiguration.shared.storage
|
||||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
if let threadID = storage.getOrCreateThread(for: message.sender!, groupPublicKey: message.groupPublicKey, openGroupID: nil, using: transaction),
|
||||
|
@ -288,7 +274,7 @@ extension MessageReceiver {
|
|||
let tsMessage = TSIncomingMessage.from(message, associatedWith: thread)
|
||||
tsMessage.save(with: transaction)
|
||||
}
|
||||
handlePreOfferCallMessage?(message)
|
||||
handlePreOfferCallMessage?(message, transaction)
|
||||
case .offer:
|
||||
print("[Calls] Received offer message.")
|
||||
if WebRTCSession.current?.uuid != message.uuid! {
|
||||
|
@ -298,13 +284,13 @@ extension MessageReceiver {
|
|||
handleOfferCallMessage?(message)
|
||||
case .answer:
|
||||
print("[Calls] Received answer message.")
|
||||
guard WebRTCSession.current?.uuid == message.uuid! else { return }
|
||||
guard let currentWebRTCSession = WebRTCSession.current, currentWebRTCSession.uuid == message.uuid! else { return }
|
||||
let sdp = RTCSessionDescription(type: .answer, sdp: message.sdps![0])
|
||||
getWebRTCSession().handleRemoteSDP(sdp, from: message.sender!)
|
||||
currentWebRTCSession.handleRemoteSDP(sdp, from: message.sender!)
|
||||
handleAnswerCallMessage?(message)
|
||||
case .provisionalAnswer: break // TODO: Implement
|
||||
case let .iceCandidates(sdpMLineIndexes, sdpMids):
|
||||
guard WebRTCSession.current?.uuid == message.uuid! else { return }
|
||||
guard let currentWebRTCSession = WebRTCSession.current, currentWebRTCSession.uuid == message.uuid! else { return }
|
||||
var candidates: [RTCIceCandidate] = []
|
||||
let sdps = message.sdps!
|
||||
for i in 0..<sdps.count {
|
||||
|
@ -314,7 +300,7 @@ extension MessageReceiver {
|
|||
let candidate = RTCIceCandidate(sdp: sdp, sdpMLineIndex: Int32(sdpMLineIndex), sdpMid: sdpMid)
|
||||
candidates.append(candidate)
|
||||
}
|
||||
getWebRTCSession().handleICECandidates(candidates)
|
||||
currentWebRTCSession.handleICECandidates(candidates)
|
||||
case .endCall:
|
||||
print("[Calls] Received end call message.")
|
||||
guard WebRTCSession.current?.uuid == message.uuid! else { return }
|
||||
|
|
|
@ -2,7 +2,7 @@ import SessionUtilitiesKit
|
|||
|
||||
public enum MessageReceiver {
|
||||
private static var lastEncryptionKeyPairRequest: [String:Date] = [:]
|
||||
public static var handlePreOfferCallMessage: ((CallMessage) -> Void)?
|
||||
public static var handlePreOfferCallMessage: ((CallMessage, YapDatabaseReadWriteTransaction) -> Void)?
|
||||
public static var handleOfferCallMessage: ((CallMessage) -> Void)?
|
||||
public static var handleAnswerCallMessage: ((CallMessage) -> Void)?
|
||||
public static var handleEndCallMessage: ((CallMessage) -> Void)?
|
||||
|
|
Loading…
Reference in New Issue