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

feat: Add Session Custom Attributes #25

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion media/src/main/java/com/mparticle/media/MediaSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ class MediaSession protected constructor(builder: Builder) {
internal set
var sessionQoS = MediaQoS()

var mediaSessionAttributes: MutableMap<String, Any?> = mutableMapOf()

var attributes: MutableMap<String, Any?> = mutableMapOf()
get() = MediaEvent(this).getSessionAttributes()
get() { //Combine the inherent Session attributes and an custom mediaSessionAttributes
val mediaAttributes = MediaEvent(this).getSessionAttributes()
mediaAttributes.putAll(mediaSessionAttributes)
return mediaAttributes
}
private set

private var mparticleInstance: MParticle?
Expand Down
11 changes: 8 additions & 3 deletions media/src/test/java/com/mparticle/MediaSessionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,28 @@ class MediaSessionTest {
}
testSessionMediaContentAttributes()

val testAttributes = HashMap<String, Any?>()
testAttributes["CustomAttributeKey"] = "CustomAttributeValue"
mediaSession.mediaSessionAttributes = testAttributes

mediaSession.logMediaSessionStart()
attributes = mediaSession.attributes
assertEquals(6, attributes.size)
assertEquals(7, attributes.size)
assertNotNull(attributes[MediaAttributeKeys.MEDIA_SESSION_ID])
assertEquals(testAttributes["CustomAttributeKey"], attributes["CustomAttributeKey"])

mediaSession.logPlayheadPosition(10L)

attributes = mediaSession.attributes
assertEquals(7, attributes.size)
assertEquals(8, attributes.size)
assertEquals(10L, attributes[MediaAttributeKeys.PLAYHEAD_POSITION])

//make sure no other Media Sessions are started
afterLogApiInvoked(mediaSession) {}


attributes = mediaSession.attributes
assertEquals(7, attributes.size)
assertEquals(8, attributes.size)
assertNotNull(attributes[MediaAttributeKeys.PLAYHEAD_POSITION])
assertNotNull(attributes[MediaAttributeKeys.MEDIA_SESSION_ID])
}
Expand Down