diff --git a/AEPAssurance/Source/Assurance.swift b/AEPAssurance/Source/Assurance.swift index f43edcd..d802585 100644 --- a/AEPAssurance/Source/Assurance.swift +++ b/AEPAssurance/Source/Assurance.swift @@ -192,7 +192,7 @@ public class Assurance: NSObject, Extension { // Read the environment query parameter from the deeplink url let environmentString = deeplinkURL?.params[AssuranceConstants.Deeplink.ENVIRONMENT_KEY] ?? "" - // invalidate the timer + // invalidate the timer invalidateTimer() // save the environment and sessionID @@ -283,6 +283,7 @@ public class Assurance: NSObject, Extension { /// Start the shutdown timer in the background queue without blocking the current thread. /// If the timer get fired, then it shuts down the assurance extension. private func startShutDownTimer() { + Log.debug(label: AssuranceConstants.LOG_TAG, "Assurance shutdown timer started. Waiting for 5 seconds to receive assurance session url."); let queue = DispatchQueue.init(label: "com.adobe.assurance.shutdowntimer", qos: .background) timer = createDispatchTimer(queue: queue, block: { self.shutDownAssurance() @@ -294,7 +295,11 @@ public class Assurance: NSObject, Extension { /// @see readyForEvent private func shutDownAssurance() { shouldProcessEvents = false + Log.debug(label: AssuranceConstants.LOG_TAG, "Timeout - Assurance extension did not receive session url. Shutting down from processing any further events.") invalidateTimer() + Log.debug(label: AssuranceConstants.LOG_TAG, "Clearing the queued events and purging Assurance shared state.") + self.assuranceSession?.clearQueueEvents() + clearState() } /// Invalidate the ongoing timer and cleans it from memory @@ -369,8 +374,8 @@ public class Assurance: NSObject, Extension { private func prepareSharedStateEvent(owner: String, eventName: String, stateContent: [String: Any], stateType: String) -> AssuranceEvent { var payload: [String: AnyCodable] = [:] payload[AssuranceConstants.ACPExtensionEventKey.NAME] = AnyCodable.init(eventName) - payload[AssuranceConstants.ACPExtensionEventKey.TYPE] = AnyCodable.init(EventType.hub.lowercased) - payload[AssuranceConstants.ACPExtensionEventKey.SOURCE] = AnyCodable.init(EventSource.sharedState.lowercased) + payload[AssuranceConstants.ACPExtensionEventKey.TYPE] = AnyCodable.init(EventType.hub.lowercased()) + payload[AssuranceConstants.ACPExtensionEventKey.SOURCE] = AnyCodable.init(EventSource.sharedState.lowercased()) payload[AssuranceConstants.ACPExtensionEventKey.DATA] = [AssuranceConstants.EventDataKey.SHARED_STATE_OWNER: owner] payload[AssuranceConstants.PayloadKey.METADATA] = [stateType: stateContent] return AssuranceEvent(type: AssuranceConstants.EventType.GENERIC, payload: payload) diff --git a/AEPAssurance/Source/AssuranceSession+EventHandler.swift b/AEPAssurance/Source/AssuranceSession+EventHandler.swift index 6aad88b..9c924f2 100644 --- a/AEPAssurance/Source/AssuranceSession+EventHandler.swift +++ b/AEPAssurance/Source/AssuranceSession+EventHandler.swift @@ -30,7 +30,7 @@ extension AssuranceSession { func handleOutBoundEvents() { outboundSource.setEventHandler(handler: { if self.socket.socketState != .open { - Log.trace(label: AssuranceConstants.LOG_TAG, "Queuing event before connection has been initialized(waiting for deep link to initialize connection with pin code entry)") + Log.trace(label: AssuranceConstants.LOG_TAG, "Assurance extension queuing event before socket connection is established.") return } @@ -61,7 +61,7 @@ extension AssuranceSession { } guard let controlType = event.commandType else { - Log.debug(label: AssuranceConstants.LOG_TAG, "A non control event is received event from assurance session. Ignoring to process event - \(event.description)") + Log.debug(label: AssuranceConstants.LOG_TAG, "A non control event is received from assurance session. Ignoring to process event - \(event.description)") return } @@ -80,9 +80,12 @@ extension AssuranceSession { // If the initial SDK events were cleared because of Assurance shutting down after 5 second timeout // then populate the griffon session with all the available shared state details (Both XDM and Regular) if self.didClearBootEvent { - for event in self.assuranceExtension.getAllExtensionStateData() { - self.outboundQueue.enqueue(newElement: event) + let stateEvents = self.assuranceExtension.getAllExtensionStateData() + Log.debug(label: AssuranceConstants.LOG_TAG, "Assurance extension cleared the initial queued events. Sharing the shared state data of \(stateEvents.count) registered extensions.") + for eachStateEvent in stateEvents { + self.outboundQueue.enqueue(newElement: eachStateEvent) } + self.outboundSource.add(data: 1) } return } diff --git a/AEPAssurance/Source/Socket/WebView/WebViewSocket.swift b/AEPAssurance/Source/Socket/WebView/WebViewSocket.swift index 0b3a480..52edf58 100644 --- a/AEPAssurance/Source/Socket/WebView/WebViewSocket.swift +++ b/AEPAssurance/Source/Socket/WebView/WebViewSocket.swift @@ -140,7 +140,7 @@ class WebViewSocket: NSObject, SocketConnectable, WKNavigationDelegate, WKScript // Called after page is loaded func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if navigation == self.loadNav { - Log.debug(label: AssuranceConstants.LOG_TAG, "WKWebView initialization complete with socket connection javascipt.") + Log.trace(label: AssuranceConstants.LOG_TAG, "WKWebView initialization complete with socket connection javascipt.") isWebViewLoaded = true } }