Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
netbe committed Nov 28, 2024
1 parent ae81f4e commit 6440964
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
2 changes: 2 additions & 0 deletions wire-ios-sync-engine/Source/Calling/WireCallCenterV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,10 @@ extension WireCallCenterV3 {
func processCallEvent(_ callEvent: CallEvent, completionHandler: @escaping () -> Void) {
Self.logger.info("process call event")
if isReady {
Self.logger.info("ready handle event \(callEvent.conversationId) - currentTimestamp \(callEvent.currentTimestamp) - serverTimestamp \(callEvent.serverTimestamp)")
handleCallEvent(callEvent, completionHandler: completionHandler)
} else {
Self.logger.info("buffering handle event \(callEvent.conversationId) - currentTimestamp \(callEvent.currentTimestamp) - serverTimestamp \(callEvent.serverTimestamp)")
bufferedEvents.append((callEvent, completionHandler))
}
}
Expand Down
17 changes: 9 additions & 8 deletions wire-ios-sync-engine/Source/Notifications/VoIPPushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {

public weak var delegate: VoIPPushManagerDelegate?

private static let logger = Logger(subsystem: "VoIP Push", category: "VoipPushManager")
private static let logger = WireLogger.calling

// MARK: - Life cycle

Expand All @@ -55,7 +55,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
requiredPushTokenType: PushToken.TokenType,
pushTokenService: PushTokenServiceInterface
) {
Self.logger.trace("init")
Self.logger.debug("init VoIPPushManager")
self.requiredPushTokenType = requiredPushTokenType
self.pushTokenService = pushTokenService

Expand All @@ -73,7 +73,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
// MARK: - Methods

public func registerForVoIPPushes() {
Self.logger.trace("register for voIP pushes")
Self.logger.debug("register for voIP pushes")
registry.desiredPushTypes = [.voIP]
}

Expand All @@ -82,7 +82,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
didUpdate pushCredentials: PKPushCredentials,
for type: PKPushType
) {
Self.logger.trace("did update push credentials")
Self.logger.debug("did update push credentials")

// We're only interested in voIP tokens.
guard type == .voIP else { return }
Expand All @@ -97,7 +97,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
_ registry: PKPushRegistry,
didInvalidatePushTokenFor type: PKPushType
) {
Self.logger.trace("did invalidate push token")
Self.logger.debug("did invalidate push token")

// We're only interested in voIP tokens.
guard type == .voIP else { return }
Expand All @@ -114,7 +114,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
for type: PKPushType,
completion: @escaping () -> Void
) {
Self.logger.trace("did receive incoming push")
Self.logger.debug("did receive incoming push")

// We're only interested in voIP tokens.
guard type == .voIP else { return completion() }
Expand All @@ -138,7 +138,7 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
payload: [AnyHashable: Any],
completion: @escaping () -> Void
) {
Self.logger.trace("process NSE push, payload: \(payload)")
Self.logger.debug("process NSE push, payload: \(payload)")

guard
let accountIDString = payload["accountID"] as? String,
Expand Down Expand Up @@ -182,7 +182,8 @@ public final class VoIPPushManager: NSObject, PKPushRegistryDelegate {
payload: [AnyHashable: Any],
completion: @escaping () -> Void
) {
Self.logger.trace("process voIP push, payload: \(payload)")
// TODO: check this is dead code right?
Self.logger.debug("process voIP push, payload: \(payload)")

guard let delegate else {
Self.logger.info("no delegate, ignoring...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import WireRequestStrategy

@objcMembers
public final class CallingRequestStrategy: AbstractRequestStrategy, ZMSingleRequestTranscoder, ZMContextChangeTracker,
ZMContextChangeTrackerSource, ZMEventConsumer {
ZMContextChangeTrackerSource, ZMEventAsyncConsumer {



// MARK: - Private Properties

private static let logger = Logger(subsystem: "VoIP Push", category: "CallingRequestStrategy")
private static let logger = WireLogger.calling

private let messageSender: MessageSenderInterface
private let flowManager: FlowManagerType
Expand Down Expand Up @@ -176,7 +178,7 @@ public final class CallingRequestStrategy: AbstractRequestStrategy, ZMSingleRequ
}

guard response.httpStatus == 412 else {
Self.logger.warning("Expected 412 response: missing clients")
Self.logger.warn("Expected 412 response: missing clients")
return
}

Expand Down Expand Up @@ -234,17 +236,19 @@ public final class CallingRequestStrategy: AbstractRequestStrategy, ZMSingleRequ

// MARK: - Event Consumer

public func processEvents(_ events: [ZMUpdateEvent], liveEvents: Bool, prefetchResult: ZMFetchRequestBatchResult?) {
Self.logger.trace("process events: \(events)")
events.forEach(processEvent)
public func processEvents(_ events: [ZMUpdateEvent]) async {
Self.logger.debug("process events: \(events.count)")
for event in events {
await processEvent(event)
}
}

private func processEvent(_ event: ZMUpdateEvent) {
private func processEvent(_ event: ZMUpdateEvent) async {
let serverTimeDelta = managedObjectContext.serverTimeDelta
guard event.type.isOne(of: [.conversationOtrMessageAdd, .conversationMLSMessageAdd]) else { return }

if let genericMessage = GenericMessage(from: event), genericMessage.hasCalling {

Self.logger.debug("process call event", attributes: [.eventId: event.safeUUID])
guard
let payload = genericMessage.calling.content.data(using: .utf8, allowLossyConversion: false),

Expand All @@ -258,11 +262,12 @@ public final class CallingRequestStrategy: AbstractRequestStrategy, ZMSingleRequ
}

guard !callEventContent.isRemoteMute else {
Self.logger.debug("isRemoteMute", attributes: [.eventId: event.safeUUID])
callCenter?.isMuted = true
return
}

processCallEvent(
await processCallEvent(
callingConversationId: genericMessage.calling.qualifiedConversationID,
conversationUUID: conversationUUID,
senderUUID: senderUUID,
Expand All @@ -286,7 +291,7 @@ public final class CallingRequestStrategy: AbstractRequestStrategy, ZMSingleRequ
payload: Data,
currentTimestamp: TimeInterval,
eventTimestamp: Date
) {
) async {

let identifier = !callingConversationId.id
.isEmpty ? UUID(uuidString: callingConversationId.id)! : conversationUUID
Expand All @@ -311,10 +316,11 @@ public final class CallingRequestStrategy: AbstractRequestStrategy, ZMSingleRequ
clientId: clientId
)

callEventStatus.scheduledCallEventForProcessing()
callCenter?.processCallEvent(callEvent, completionHandler: { [weak self] in
self?.callEventStatus.finishedProcessingCallEvent()
})
await withCheckedContinuation { continuation in
callCenter?.processCallEvent(callEvent, completionHandler: {
continuation.resume()
})
}
}

}
Expand Down
10 changes: 4 additions & 6 deletions wire-ios-sync-engine/Source/UserSession/CallEventStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import Foundation

private let zmLog = ZMSLog(tag: "calling")

/// CallEventStatus keep track of call events which are waiting to be processed. this is important to know when
/// the app is launched via push notification since then we need keep the app running until we've processed all
/// call events.
Expand All @@ -34,15 +32,15 @@ public class CallEventStatus: NSObject, ZMTimerClient {
fileprivate var callEventsWaitingToBeProcessed: Int = 0 {
didSet {
if callEventsWaitingToBeProcessed == 0 {
zmLog.debug("CallEventStatus: all events processed, starting timer")
WireLogger.calling.debug("CallEventStatus: all events processed, starting timer")
eventProcessingTimer = ZMTimer(target: self, operationQueue: .main)
eventProcessingTimer?.fire(afterTimeInterval: eventProcessingTimoutInterval)
}
}
}

public func timerDidFire(_ timer: ZMTimer!) {
zmLog.debug("CallEventStatus: finished timer")
WireLogger.calling.debug("CallEventStatus: finished timer")
observers.forEach { $0() }
observers = []
eventProcessingTimer = nil
Expand All @@ -60,11 +58,11 @@ public class CallEventStatus: NSObject, ZMTimerClient {
@discardableResult
public func waitForCallEventProcessingToComplete(_ completionHandler: @escaping () -> Void) -> Bool {
guard callEventsWaitingToBeProcessed != 0 || eventProcessingTimer != nil else {
zmLog.debug("CallEventStatus: No active call events, completing")
WireLogger.calling.debug("CallEventStatus: No active call events, completing")
completionHandler()
return false
}
zmLog.debug("CallEventStatus: Active call events, waiting")
WireLogger.calling.debug("CallEventStatus: Active call events, waiting")
observers.append(completionHandler)
return true
}
Expand Down

0 comments on commit 6440964

Please sign in to comment.