Skip to content

Commit

Permalink
Analytics: track call start and call end
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Dec 31, 2021
1 parent 9d47100 commit 1c2653f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ class WebRtcCall(
}
}

fun durationMillis(): Int {
return timer.elapsedTime().toInt()
}

fun formattedDuration(): String {
return formatDuration(
Duration.ofMillis(timer.elapsedTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import androidx.lifecycle.LifecycleOwner
import im.vector.app.ActiveSessionDataSource
import im.vector.app.BuildConfig
import im.vector.app.core.services.CallService
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.plan.CallEnded
import im.vector.app.features.analytics.plan.CallStarted
import im.vector.app.features.call.VectorCallActivity
import im.vector.app.features.call.audio.CallAudioManager
import im.vector.app.features.call.lookup.CallProtocolsChecker
Expand Down Expand Up @@ -68,7 +71,8 @@ private val loggerTag = LoggerTag("WebRtcCallManager", LoggerTag.VOIP)
@Singleton
class WebRtcCallManager @Inject constructor(
private val context: Context,
private val activeSessionDataSource: ActiveSessionDataSource
private val activeSessionDataSource: ActiveSessionDataSource,
private val analyticsTracker: AnalyticsTracker
) : CallListener,
DefaultLifecycleObserver {

Expand Down Expand Up @@ -237,6 +241,7 @@ class WebRtcCallManager @Inject constructor(
val currentCall = getCurrentCall().takeIf { it != call }
currentCall?.updateRemoteOnHold(onHold = true)
audioManager.setMode(if (call.mxCall.isVideoCall) CallAudioManager.Mode.VIDEO_CALL else CallAudioManager.Mode.AUDIO_CALL)
call.trackCallStarted()
this.currentCall.setAndNotify(call)
}

Expand All @@ -245,6 +250,7 @@ class WebRtcCallManager @Inject constructor(
val webRtcCall = callsByCallId.remove(callId) ?: return Unit.also {
Timber.tag(loggerTag.value).v("On call ended for unknown call $callId")
}
webRtcCall.trackCallEnded()
CallService.onCallTerminated(context, callId, endCallReason, rejected)
callsByRoomId[webRtcCall.signalingRoomId]?.remove(webRtcCall)
callsByRoomId[webRtcCall.nativeRoomId]?.remove(webRtcCall)
Expand Down Expand Up @@ -443,4 +449,28 @@ class WebRtcCallManager @Inject constructor(
}
call.onCallAssertedIdentityReceived(callAssertedIdentityContent)
}

/**
* Analytics
*/
private fun WebRtcCall.trackCallStarted() {
analyticsTracker.capture(
CallStarted(
isVideo = mxCall.isVideoCall,
numParticipants = 2,
placed = mxCall.isOutgoing
)
)
}

private fun WebRtcCall.trackCallEnded() {
analyticsTracker.capture(
CallEnded(
durationMs = durationMillis(),
isVideo = mxCall.isVideoCall,
numParticipants = 2,
placed = mxCall.isOutgoing
)
)
}
}

0 comments on commit 1c2653f

Please sign in to comment.