-
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
Conversation
- Handle tracker requests by creating a new session and then map the given tracker id to the returned session id - TODO: Handle track requests to call corresponding tracker APIs - Listen for configuration / privacy changes and update media states
Marking WIP until MediaService is available and further functionality can be added. Opening PR for now to get some early feedback. |
Codecov Report
@@ Coverage Diff @@
## dev #8 +/- ##
==========================================
+ Coverage 93.84% 94.38% +0.54%
==========================================
Files 13 15 +2
Lines 1363 1459 +96
==========================================
+ Hits 1279 1377 +98
+ Misses 84 82 -2 |
AEPMedia/Sources/Media.swift
Outdated
/// Parameters: | ||
/// - event: The `Event` for which shared state is to be retrieved. | ||
/// - dependencies: An array of names of event's dependencies. | ||
private func updateMediaState(forEvent event: Event, dependencies: [String]) { |
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.
Let us remove the method from this class. We will let MediaService maintain MediaState updates.
AEPMedia/Sources/Media.swift
Outdated
/// - Parameter: | ||
/// - event: The configuration response event | ||
private func handleConfigurationResponseEvent(_ event: Event) { | ||
updateMediaState(forEvent: event, dependencies: dependencies) |
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 also listen for EventHub SharedState update and pass it to MediaService ?
AEPMedia/Sources/Media.swift
Outdated
|
||
let trackerConfig = trackerRequestData[MediaConstants.Tracker.EVENT_PARAM] as? [String: Any] ?? [:] | ||
|
||
mediaState.setTrackerConfig(with: trackerConfig) |
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.
Tracker config is not stored in media state. We pass it to init method when creating a tracker.
It should be something like
trackerMapping[trackerId] = MediaTracker(config: trackerConfig, hitProcessor: mediaService)
AEPMedia/Sources/Media.swift
Outdated
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 sessionIdToTrackerIdMapping: [String: String] = [:] |
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.
We don't map sessionId to trackerId.
instead
let trackerMapping: [String: MediaEventTracking]
AEPMedia/Sources/Media.swift
Outdated
//TOO | ||
// TODO: revisit when media service implemented | ||
|
||
updateMediaState(forEvent: event, dependencies: dependencies) |
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.
We don't need to do it for every trackRequest.
AEPMedia/Sources/Media.swift
Outdated
#if DEBUG | ||
var sessionIdToTrackerIdMapping: [String: String] = [:] | ||
var mediaState: MediaState | ||
var trackerCalled = false |
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.
We don't need this variable.
AEPMedia/Sources/MediaState.swift
Outdated
|
||
class MediaState { | ||
//TODO: implementation of this class. | ||
private let LOG_TAG = "MediaState" | ||
private(set) var privacyStatus: PrivacyStatus = .unknown | ||
private var trackerConfig: [String: Any]? |
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.
We can remove this one.
AEPMedia/Sources/MediaState.swift
Outdated
private(set) var blob: String? | ||
private(set) var visitorCustomerIDs: [[String: Any]]? | ||
|
||
private(set) var dispatchQueue: DispatchQueue = DispatchQueue(label: MediaConstants.FRIENDLY_NAME) |
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.
We really don't need a dispatchQueue just for updating variables.
*/ | ||
import Foundation | ||
|
||
class MediaCollectionEventTracking: MediaEventTracking { |
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.
We don't need this class.
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.
Changes requested
…implement-media-extension
- add stubs for MediaCoreTracker and MediaService - add FakeMediaCoreTracker for tests - remove references to sessionId
…implement-media-extension
…implement-media-extension
AEPMedia/Sources/Media.swift
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
we should avoid forced unwrapping mediaService.
AEPMedia/Sources/Media.swift
Outdated
} | ||
|
||
guard let trackerId = eventData[MediaConstants.Tracker.ID] as? String, trackerId.count > 0 else { | ||
Log.debug(label: LOG_TAG, "\(#function) - Tracker ID is nil, unable to create tracker.") |
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.
nit: "Tracker ID is invalid, unable to create internal tracker."
AEPMedia/Sources/Media.swift
Outdated
} | ||
|
||
Log.debug(label: LOG_TAG, "\(#function) - tracking media for tracker id: \(trackerId).") | ||
_ = trackMedia(trackerId: trackerId, eventData: eventData) |
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.
we can simply call trackMedia right?
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.
i'll make trackMedia's result discardable
AEPMedia/Sources/Media.swift
Outdated
} | ||
|
||
private func trackMedia(trackerId: String, eventData: [String: Any]) -> Bool { | ||
if let tracker = trackers[trackerId] { |
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.
nit: I think guard let would be cleaner
|
||
enum MediaConstants { | ||
static let EXTENSION_NAME = "com.adobe.module.media" | ||
static let FRIENDLY_NAME = "Media Analytics" | ||
static let EXTENSION_VERSION = "0.0.1" | ||
static let DATASTORE_NAME = EXTENSION_NAME | ||
static let DEFAULT_PRIVACY_STATUS = PrivacyStatus.unknown |
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 have this in MediaState, since it is managed and handled there only.
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.
yup good point. removed the constant and declared it within media state.
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.
And we can get rid of core import as well then.
AEPMedia/Sources/Media.swift
Outdated
public var name = MediaConstants.EXTENSION_NAME | ||
public var friendlyName = MediaConstants.FRIENDLY_NAME | ||
public static var extensionVersion = MediaConstants.EXTENSION_VERSION | ||
public var metadata: [String: String]? | ||
#if DEBUG | ||
var trackers: [String: MediaEventTracker] |
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?
AEPMedia/Sources/Media.swift
Outdated
public var name = MediaConstants.EXTENSION_NAME | ||
public var friendlyName = MediaConstants.FRIENDLY_NAME | ||
public static var extensionVersion = MediaConstants.EXTENSION_VERSION | ||
public var metadata: [String: String]? | ||
#if DEBUG | ||
var trackers: [String: MediaEventTracker] | ||
var mediaState: MediaState |
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 remove mediaState from the extension and let MediaService maintain it?
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.
yes, i'll update
AEPMedia/Sources/Media.swift
Outdated
|
||
/// Handler for media tracker creation events | ||
if mediaState.getPrivacyStatus() == .optedOut { |
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.
We should directly read privacy status from EventData instead of reading it from Media state
AEPMedia/Sources/Media.swift
Outdated
#if DEBUG | ||
var trackers: [String: MediaEventTracker] | ||
var mediaState: MediaState | ||
var mediaService: 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 make MediaService non optional?
AEPMedia/Sources/Media.swift
Outdated
return | ||
} | ||
|
||
guard let trackerId = eventData[MediaConstants.Tracker.ID] as? String, trackerId.count > 0 else { |
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.
nit: !trackerId.empty
AEPMedia/Sources/Media.swift
Outdated
Log.debug(label: LOG_TAG, "\(#function) - Privacy status is opted-out. Clearing persisted media sessions.") | ||
// clear tracked sessions and end all running sessions within the media service | ||
trackers.removeAll() | ||
mediaService?.abortAllSessions() |
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.
MediaService can internally call abortAllSessions in response to updateState.
Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: