Skip to content

Commit

Permalink
Merge pull request #50 from newrelic/fix/playlist_next_crash
Browse files Browse the repository at this point in the history
Playlist Next Crash
  • Loading branch information
asllop authored Oct 4, 2022
2 parents 8ea81f6 + 0a1eb7c commit 7e019a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG
All notable changes to this project will be documented in this file.

## [3.1.1] - 2022/10/04
### Fix
- Crash happening when using a playlist.

## [3.1.0] - 2022/09/01
### Add
- Attribute `domain` to all HTTP events and metrics.
Expand Down
41 changes: 21 additions & 20 deletions components/NewRelicAgent/NRAgent.brs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ function nrSendVideoEvent(actionName as String, attr = invalid) as Void
ev.Append(attr)
end if
nrRecordEvent(ev)
'Backup attributes (cloning it)
m.nrBackupAttributes = {}
m.nrBackupAttributes.Append(ev)
'Backup attributes
'Exclude *_BUFFER_* actions due to a problem with these events when skipping in a playlist: attributes are not reliable, can be mixed with next video attributes or just wrong.
if actionName <> "CONTENT_BUFFER_START" and actionName <> "CONTENT_BUFFER_END"
m.nrBackupAttributes = {}
m.nrBackupAttributes.Append(ev)
end if
end function

function nrSendHttpRequest(attr as Object) as Void
Expand Down Expand Up @@ -949,30 +952,29 @@ end function
function nrSendBackupVideoEvent(actionName as String, attr = invalid) as Void
'Use attributes in the backup (m.nrBackupAttributes) and recalculate some of them.
ev = m.nrBackupAttributes

nrLog(["nrSendBackupVideoEvent: Using this event as a backup for attributes: ", ev])

'- Set correct actionName
backupActionName = ev["actionName"]
ev["actionName"] = actionName
'- Set current timestamp
backupTimestamp = ev["timestamp"]
ev["timestamp"] = FormatJson(nrTimestamp())
'- Recalculate playhead, adding timestamp offset, except if last action is PAUSE
if not isAction("PAUSE", backupActionName)
lint& = ParseJson(ev["timestamp"]) - ParseJson(backupTimestamp)
offsetTime = lint&
nrLog(["Offset time = ", offsetTime])
if ev["contentPlayhead"] <> invalid then ev["contentPlayhead"] = ev["contentPlayhead"] + offsetTime
if ev["adPlayhead"] <> invalid then ev["adPlayhead"] = ev["adPlayhead"] + offsetTime
end if
'- Regen memory level
'- Recalculate playhead, adding timestamp offset
lint& = ParseJson(ev["timestamp"]) - ParseJson(backupTimestamp)
offsetTime = lint&
nrLog(["Offset time = ", offsetTime])
if ev["contentPlayhead"] <> invalid then ev["contentPlayhead"] = ev["contentPlayhead"] + offsetTime
if ev["adPlayhead"] <> invalid then ev["adPlayhead"] = ev["adPlayhead"] + offsetTime
'- Regenerate memory level
dev = CreateObject("roDeviceInfo")
ev["memoryLevel"] = dev.GetGeneralMemoryLevel()
'- Regen is muted
if m.nrVideoObject <> invalid
if ev["contentIsMuted"] <> invalid then ev["contentIsMuted"] = m.nrVideoObject.mute
if ev["adIsMuted"] <> invalid then ev["adIsMuted"] = m.nrVideoObject.mute
end if
'- Regen HDMI connected
'- Regenerate HDMI connected
hdmi = CreateObject("roHdmiStatus")
ev["hdmiIsConnected"] = hdmi.IsConnected()
'- Recalculate all timeSinceXXX, adding timestamp offset
Expand All @@ -991,8 +993,7 @@ function nrSendBackupVideoEvent(actionName as String, attr = invalid) as Void

'PROBLEMS:
'- Custom attributes remains the same, could be problematic depending on the app

nrLog(["nrSendBackupVideoEvent => ", ev])
'- Playhead calculation is estimative.

nrRecordEvent(ev)

Expand Down Expand Up @@ -1123,9 +1124,6 @@ function nrSendRAFEvent(actionName as String, ctx as Dynamic, attr = invalid) as
ev.Append(attr)
end if
nrRecordEvent(ev)
'Backup attributes (cloning it)
m.nrBackupAttributes = {}
m.nrBackupAttributes.Append(ev)
end function

function nrResetRAFState() as Void
Expand Down Expand Up @@ -1407,7 +1405,10 @@ function nrIndexObserver() as Void
return
end if

'- Use nrSendBackupVideoEvent to send the END using previous video attributes
'- Use nrSendBackupVideoEvent to send the END using previous video attributes.
' We do this because of how Roku handles playlists: when the next video starts, no "finished" event is sent for the previous,
' instead a buffering cycle happens, followed by an index change. The video attributes are mixed during this process, some belong
' to the next video, some to the previous. In order to send an END that belongs to the ending video, we have to make this trick.
nrSendBackupVideoEnd()
'- Send REQUEST and START using normal send, with current video attributes
m.nrVideoCounter = m.nrVideoCounter + 1
Expand Down
2 changes: 1 addition & 1 deletion components/NewRelicAgent/NRAgent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<interface>
<!-- Properties -->
<field id="version" type="string" value="3.1.0"/>
<field id="version" type="string" value="3.1.1"/>
<field id="patternGen" type="node"/>
<!-- Public Methods (wrapped) -->
<function name="NewRelicInit"/>
Expand Down

0 comments on commit 7e019a7

Please sign in to comment.