Skip to content

Commit

Permalink
[#189] WIP: Delete recording if less than min
Browse files Browse the repository at this point in the history
session length.
  • Loading branch information
karntrehan committed Oct 17, 2024
1 parent ca15b03 commit 478cd56
Showing 1 changed file with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public class PostHogReplayIntegration(
private val isSessionReplayEnabled: Boolean
get() = PostHog.isSessionReplayActive()

private var sessionStartTime = 0L
private var sessionEndTime = 0L


private fun addView(
view: View,
added: Boolean = true,
Expand Down Expand Up @@ -148,7 +152,11 @@ public class PostHogReplayIntegration(

executor.submit {
try {
generateSnapshot(WeakReference(decorView), WeakReference(window), timestamp)
generateSnapshot(
WeakReference(decorView),
WeakReference(window),
timestamp
)
} catch (e: Throwable) {
config.logger.log("Session Replay generateSnapshot failed: $e.")
}
Expand Down Expand Up @@ -229,10 +237,19 @@ public class PostHogReplayIntegration(
}
when (motionEvent.action.and(MotionEvent.ACTION_MASK)) {
MotionEvent.ACTION_DOWN -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart)
generateMouseInteractions(
timestamp,
motionEvent,
RRMouseInteraction.TouchStart
)
}

MotionEvent.ACTION_UP -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchEnd)
generateMouseInteractions(
timestamp,
motionEvent,
RRMouseInteraction.TouchEnd
)
}
}
} catch (e: Throwable) {
Expand Down Expand Up @@ -265,7 +282,8 @@ public class PostHogReplayIntegration(
x = absX,
y = absY,
)
val mouseInteraction = RRIncrementalMouseInteractionEvent(mouseInteractionData, timestamp)
val mouseInteraction =
RRIncrementalMouseInteractionEvent(mouseInteractionData, timestamp)
mouseInteractions.add(mouseInteraction)
}

Expand Down Expand Up @@ -312,6 +330,9 @@ public class PostHogReplayIntegration(

// workaround for react native that is started after the window is added
// Curtains.rootViews should be empty for normal apps yet

sessionStartTime = config.dateProvider.currentTimeMillis()

Curtains.rootViews.forEach { view ->
addView(view)
}
Expand All @@ -325,6 +346,13 @@ public class PostHogReplayIntegration(

override fun uninstall() {
try {
sessionEndTime = config.dateProvider.currentTimeMillis()

//TODO improve this
if (sessionEndTime - sessionStartTime <= config.sessionReplayConfig.minSessionDurationMs) {
//Delete existing session recording?
}

Curtains.onRootViewsChangedListeners -= onRootViewsChangedListener

decorViews.entries.forEach {
Expand Down Expand Up @@ -742,14 +770,17 @@ public class PostHogReplayIntegration(
style.verticalAlign = "center"
style.horizontalAlign = "center"
}

View.TEXT_ALIGNMENT_TEXT_END, View.TEXT_ALIGNMENT_VIEW_END -> {
style.verticalAlign = "center"
style.horizontalAlign = "right"
}

View.TEXT_ALIGNMENT_TEXT_START, View.TEXT_ALIGNMENT_VIEW_START -> {
style.verticalAlign = "center"
style.horizontalAlign = "left"
}

View.TEXT_ALIGNMENT_GRAVITY -> {
val horizontalAlignment =
when (view.gravity.and(Gravity.HORIZONTAL_GRAVITY_MASK)) {
Expand All @@ -769,6 +800,7 @@ public class PostHogReplayIntegration(
}
style.verticalAlign = verticalAlignment
}

else -> {
style.verticalAlign = "center"
style.horizontalAlign = "left"
Expand Down

0 comments on commit 478cd56

Please sign in to comment.