-
Notifications
You must be signed in to change notification settings - Fork 40
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
Changes from 1 commit
6944e09
6edda94
ce9aedd
e80df78
bb23437
b6296ea
9ce3872
dc32c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/// - source: An `String` indicates the event source the current listener is listening for | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@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:) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,9 @@ import Foundation | |
case callbackTimeout = 1 | ||
case callbackNil = 2 | ||
case none = 3 | ||
case serverError = 4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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