-
Notifications
You must be signed in to change notification settings - Fork 12
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
Implement media extension #8
Changes from 1 commit
d29d482
7e7212d
1359721
651c2a3
9a3fa1a
ad21613
103323c
ab8043a
6281f79
afbbcc7
5ba7c96
9e35c81
8a60db9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,19 +17,17 @@ import AEPServices | |
public class Media: NSObject, Extension { | ||
private let LOG_TAG = "Media" | ||
|
||
// MARK: Extension | ||
public var runtime: ExtensionRuntime | ||
public var name = MediaConstants.EXTENSION_NAME | ||
public var friendlyName = MediaConstants.FRIENDLY_NAME | ||
public static var extensionVersion = MediaConstants.EXTENSION_VERSION | ||
public var metadata: [String: String]? | ||
let dependencies: [String] = [MediaConstants.Configuration.SHARED_STATE_NAME, MediaConstants.Identity.SHARED_STATE_NAME, MediaConstants.Analytics.SHARED_STATE_NAME] | ||
#if DEBUG | ||
var trackers: [String: MediaEventTracker] = [:] | ||
var trackers: [String: MediaEventTracker] | ||
var mediaState: MediaState | ||
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. Can we remove mediaState from the extension and let MediaService maintain it? 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. yes, i'll update |
||
var mediaService: MediaService? | ||
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. Can we make MediaService non optional? |
||
#else | ||
private var trackers: [String: MediaCoreTracker] = [:] | ||
private var trackers: [String: MediaEventTracker] | ||
private var mediaState: MediaState | ||
private var mediaService: MediaService? | ||
#endif | ||
|
@@ -40,6 +38,7 @@ public class Media: NSObject, Extension { | |
self.runtime = runtime | ||
self.mediaState = MediaState() | ||
self.mediaService = MediaService(mediaState: mediaState) | ||
self.trackers = [:] | ||
} | ||
|
||
/// Invoked when the Media extension has been registered by the `EventHub` | ||
|
@@ -65,18 +64,14 @@ public class Media: NSObject, Extension { | |
/// - Parameter: | ||
/// - event: The configuration response event | ||
private func handleSharedStateUpdate(_ event: Event) { | ||
mediaService?.updateMediaState(event: event) | ||
mediaService?.updateMediaState(event: event, getSharedState: runtime.getSharedState(extensionName:event:barrier:)) | ||
} | ||
|
||
/// Processes Configuration Response content events to retrieve the configuration data and privacy status settings. | ||
/// - Parameter: | ||
/// - event: The configuration response event | ||
private func handleConfigurationResponseEvent(_ event: Event) { | ||
var sharedStates = [String: [String: Any]?]() | ||
for extensionName in dependencies { | ||
sharedStates[extensionName] = runtime.getSharedState(extensionName: extensionName, event: event, barrier: true)?.value | ||
} | ||
mediaState.update(dataMap: sharedStates) | ||
handleSharedStateUpdate(event) | ||
|
||
if mediaState.getPrivacyStatus() == .optedOut { | ||
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. We should directly read privacy status from EventData instead of reading it from Media state |
||
handleOptOut(event: event) | ||
|
@@ -99,6 +94,7 @@ public class Media: NSObject, Extension { | |
|
||
let trackerConfig = eventData[MediaConstants.Tracker.EVENT_PARAM] as? [String: Any] ?? [:] | ||
|
||
Log.debug(label: LOG_TAG, "\(#function) - Creating tracker with tracker id: \(trackerId).") | ||
trackers[trackerId] = MediaEventTracker(hitProcessor: mediaService!, config: trackerConfig) | ||
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. we should avoid forced unwrapping mediaService. |
||
} | ||
|
||
|
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.
Can we use MediaEventTrackable protocol instead of MediaEventTracker?