Skip to content
Open
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
40 changes: 34 additions & 6 deletions src/mux-analytics.brs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function _getConnectionType(deviceInfo as Object)
return "wifi"
end if
if connectionType = "WiredConnection"
return "ethernet"
return "wired"
end if

return "other"
Expand Down Expand Up @@ -487,6 +487,9 @@ function muxAnalytics() as Object
' Flag to track heartbeat timer state to avoid rendezvous
m._Flag_heartbeatTimerRunning = false

' Network monitoring
m._lastConnectionType = Invalid

' kick off analytics
date = m._getDateTime()
m._startTimestamp = 0# + date.AsSeconds() * 1000.0# + date.GetMilliseconds()
Expand All @@ -497,17 +500,33 @@ function muxAnalytics() as Object

prototype.beaconIntervalHandler = sub(beaconIntervalEvent)
data = beaconIntervalEvent.getData()
m.updateSessionPropertiesConnectionType()
m._checkNetworkChange()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use EnableLinkStatusEvent and/or EnableInternetStatusEvent for this instead of just checking on the beacon interval?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest something like this if it would work, as well, so we don't have a rendezvous every time we check the beacon interval. I know with the other performance improvements we've helped, but it would be good to not add back in rendezvous if we don't have to

m.LIGHT_THE_BEACONS()
end sub

prototype.updateSessionPropertiesConnectionType = sub()
connectionType = _getConnectionType(m.deviceInfo)
if connectionType <> Invalid
m._sessionProperties.viewer_connection_type = connectionType
prototype._checkNetworkChange = sub()
currentConnectionType = _getConnectionType(m.deviceInfo)
' Check if connection type has changed
if currentConnectionType <> m._lastConnectionType
m._fireNetworkChangeEvent(currentConnectionType)
m._lastConnectionType = currentConnectionType
' Update session properties with new connection type
if m._sessionProperties <> Invalid
m._sessionProperties.viewer_connection_type = currentConnectionType
end if
end if
end sub

prototype._fireNetworkChangeEvent = sub(connectionType as Dynamic)
props = {}
if connectionType = Invalid
props.viewer_connection_type = Invalid
else
props.viewer_connection_type = connectionType
end if
m._addEventToQueue(m._createEvent("networkchange", props))
end sub

prototype.heartbeatIntervalHandler = sub(heartbeatIntervalEvent)
data = heartbeatIntervalEvent.getData()
if m._Flag_isPaused <> true
Expand Down Expand Up @@ -1219,6 +1238,9 @@ function muxAnalytics() as Object
' m._playerPlayheadTime = m.video.position
' end if

' Check for network changes as a backup polling mechanism
m._checkNetworkChange()

m._setBufferingMetrics()
m._updateContentPlaybackTime()

Expand Down Expand Up @@ -1441,6 +1463,11 @@ function muxAnalytics() as Object
props.ad_playing_time_ms_cumulative = m._totalAdWatchTime
m._addEventToQueue(m._createEvent("playbackmodechange", props))

' Fire initial networkchange event
initialConnectionType = _getConnectionType(m.deviceInfo)
m._lastConnectionType = initialConnectionType
m._fireNetworkChangeEvent(initialConnectionType)

m._addEventToQueue(m._createEvent("viewstart"))

m._inView = true
Expand Down Expand Up @@ -1498,6 +1525,7 @@ function muxAnalytics() as Object
m._viewAverageRequestThroughput = Invalid
m._viewRequestCount = Invalid
m._segmentRequestFailedCount = Invalid
m._lastConnectionType = Invalid
end if
end sub

Expand Down