Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public api to register global listener #451

Merged
merged 8 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion AEPCore/Sources/core/MobileCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,23 @@ public final class MobileCore: NSObject {
/// - responseCallback: Callback to be invoked with `event`'s response `Event`
@objc(dispatch:responseCallback:)
public static func dispatch(event: Event, responseCallback: @escaping (Event?) -> Void) {
EventHub.shared.registerResponseListener(triggerEvent: event, timeout: 1) { event in
EventHub.shared.registerResponseListener(triggerEvent: event, timeout: 2) { event in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make this timeout configurable? or at least explain that it exists in the docs for the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will address this in a separate pr

responseCallback(event)
}

EventHub.shared.dispatch(event: event)
}

/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched
/// - Parameters:
/// - type: An `String` indicates the event type the current listener is listening for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An String indicates > A String indicating

/// - source: An `String` indicates the event source the current listener is listening for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched typd and source
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typd > type

@objc(registerEventListenerWithType:source:listener:)
public static func registerEventListener(type: String, source: String, listener: @escaping EventListener) {
EventHub.shared.registerEventListener(type: type, source: source, listener: listener)
}

/// Submits a generic event containing the provided IDFA with event type `generic.identity`.
/// - Parameter identifier: the advertising identifier string.
@objc(setAdvertisingIdentifier:)
Expand Down
4 changes: 4 additions & 0 deletions AEPCore/Sources/eventhub/AEPError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ import Foundation
case callbackTimeout = 1
case callbackNil = 2
case none = 3
case serverError = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these an artifact from some other work? I don't see them used anywhere in this PR.

case networkError = 5
case invalidRequest = 6
case invalidResponse = 7
case errorExtensionNotInitialized = 11
}
14 changes: 14 additions & 0 deletions AEPCore/Sources/eventhub/EventHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ final class EventHub {
responseEventListeners.append(responseListenerContainer!)
}

/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched
/// - Parameters:
/// - type: An `String` indicates the event type the current listener is listening for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same fixes needed for copy/pasted docs

/// - source: An `String` indicates the event source the current listener is listening for
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched typd and source
func registerEventListener(type: String, source: String, listener: @escaping EventListener) {
// use the event hub placeholder extension to hold all the listeners register from the public API
guard let eventHubExtension = registeredExtensions.first(where: { $1.sharedStateName == EventHubConstants.NAME })?.value else {
Log.warning(label: self.LOG_TAG, "Error registering event listener")
return
}
eventHubExtension.registerListener(type: type, source: source, listener: listener)
}

/// Creates a new `SharedState` for the extension with provided data, versioned at `event`
/// If `event` is nil, one of two behaviors will be observed:
/// 1. If this extension has not previously published a shared state, shared state will be versioned at 0
Expand Down
1 change: 1 addition & 0 deletions AEPCore/Sources/eventhub/EventSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class EventSource: NSObject {
public static let requestIdentity = "com.adobe.eventSource.requestIdentity"
public static let requestProfile = "com.adobe.eventSource.requestProfile"
public static let requestReset = "com.adobe.eventSource.requestReset"
public static let notification = "com.adobe.eventSource.notification"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR?

public static let responseContent = "com.adobe.eventSource.responseContent"
public static let responseIdentity = "com.adobe.eventSource.responseIdentity"
public static let responseProfile = "com.adobe.eventSource.responseProfile"
Expand Down
1 change: 1 addition & 0 deletions AEPCore/Sources/eventhub/EventType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class EventType: NSObject {
public static let userProfile = "com.adobe.eventType.userProfile"
public static let places = "com.adobe.eventType.places"
public static let offerDecisioning = "com.adobe.eventType.offerDecisioning"
public static let edge = "com.adobe.eventType.edge"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated?

public static let genericTrack = "com.adobe.eventType.generic.track"
public static let genericLifecycle = "com.adobe.eventType.generic.lifecycle"
public static let genericIdentity = "com.adobe.eventType.generic.identity"
Expand Down