I'm having a problem which I'd like to see if the community can help me solve. It has to do with a very important part of my company's Roku channels, mainly stat tracking or ad playback. Let me quickly walk you through the general setup and how things are supposed to work.
Each time we play a content video, the channel fires off to our ad server to see if there is a preroll ad to playback before the content video begins. So the channel parses through the XML response from our ad server and pulls out impression URLs as well as what we refer to as quartile stat urls. Impression URLs are fired at the beginning of playback, quartile stats are fired at the start, 25%, 50%, 75% and complete markers. There can be several URLs for each marker or just one. So what happens is the XML parser pushes the URLs into an array for each marker. That part is working properly and when I watch ad playback through the debug console I get 200 responses for each URL pinged.
However, for some reason the stats don't equal out. Now in a live environment this wouldn't be so important, as someone might not watch the entire ad. They may exit the app or something else might happen to interfere with playback. However, we're testing this on a staging app that only we have access to and each ad is played back for its entirety each time playback occurs while we're testing. Even worse is that what our start marker stats seem to be lower than our completes. So something is happening where not all URL pings are getting through even though the response shows successful in the debugger.
So now for the specifics of what is happening in the code. During playback we check for each marker, and once it is hit all the associated URL pings are fired off. This only happens the first time as we have a boolean setup to only enter the loop if not fired before. Previously we ran into the issue where our URL transfers were walking over each other. We fixed this by creating a function to track and handle unique instances of roUrlTransfer objects for each URL ping that occurs. Here is that function:
Sub PingURL(urlToCall as String, activeURLArray as Object, messagePort as Object)
'// Create a urlTransfer, store in the array of atcive transfers to keep a reference to it, and Activate it.
transfer = CreateObject("roUrlTransfer")
transfer.SetPort(messagePort)
transfer.SetUrl(urlToCall)
activeURLArray.push(transfer)
PrettyPrint("Starting PingURL() Call, uniqueid="+transfer.GetIdentity().ToStr()+": " + urlToCall) '// Custom function for creating a custom print block
transfer.AsyncGetToString()
End Sub
And here is the other side of it where we close things out in our event loop:
While True
'// Check the urlTransfer port for any updates on UrlTransfers
msg = wait(100, urlTransferPort)
'// URL Transfer Events
If Type(msg) = "roUrlEvent"
Print "--[roUrlEvent. uniqueid="+msg.GetSourceIdentity().ToStr()+" type="+ msg.GetInt().ToStr() + " responsecode="+msg.GetResponseCode().ToStr()+" statusText="+msg.GetFailureReason()+" targetIP="+msg.GetTargetIpAddress()+"]"
'//Loop over the array of all active roURLTransfers, looking for the mathc that this event was generated for.
For i=0 to m.activeUrlTransfers.Count()-1 step +1
If m.activeUrlTransfers[i].GetIdentity() = msg.GetSourceIdentity()
'// Check if the transfer has finished - it will have a value of 1 if it is finished
If msg.GetInt() = 1 Then
'//Remove the transfer from the array of active URLs.
'//Remove this entry from the array.
m.activeUrlTransfers.Delete(i)
Print "active URL complete, removing, active URLs now left: "+m.activeUrlTransfers.Count().ToStr() + ""
m.responseCount = m.responseCount + 1
'//Break out of loop - no more checking required
Exit For
End If
End If
End For
If m.responseCount = m.totalImpressionUrls
PrettyPrint( "" + m.responseCount.toStr() + " out of " + m.totalImpressionUrls.toStr() + " ping responses received successfully. Ad playback complete. " )
Exit While
End If
Else
End If
End While
Can anyone see any reason from the code above, or have any idea what might be blocking the pings to the URLs, if in fact I'm seeing all of the the correct things happening in the debugger, and the responses are coming back as they should? I appreciate the help in advance.