Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
kevxcs
Level 7

Scene Graph roUrlTransfer

Can someone please shed some light on an issue I have ....

I know that roUrlTransfer can only be used in a task node, so I created one to turn a json response from a server into a node list, however when the code sets the url it throws an error saying that the roUrlTransfer object is invalid? Anyone have any idea why?

<component name="ViewContentTask" extends="Task">
<interface>
<field id="sourceid" type="string" alias="sourceid" alwaysNotify="true" onChange="LoadContent"/>
<field id="content" type="node" />
</interface>

<script type="text/brightscript">
<![CDATA[
Sub Init()
m.top.functionName = "LoadContent"
End Sub

Sub LoadContent()
url = "https://myurl.com?id="+m.top.sourceid
https = CreateObject("roUrlTransfer")
https.SetUrl(url)
https.SetCertificatesFile("common:/certs/ca-bundle.crt")
https.AddHeader("X-Roku-Reserved-Dev-Id", "")
https.InitClientCertificates()

response = https.GetToString()
content = ParseJson(response)

list = []
........ blah blah blah ........
m.top.content = ParseContent(list)
End Sub

Function ParseContent(list As Object)
........ blah blah blah ........
return stuff
End Function
]]>
</script>
</component>

Error message:

Current Function:
016: Sub LoadContent()
017: url = "https://myurl.com?id="+m.top.sourceid
018: print url
019: https = CreateObject("roUrlTransfer")
020:* https.SetUrl(url)
021: https.SetCertificatesFile("common:/certs/ca-bundle.crt")
022: https.AddHeader("X-Roku-Reserved-Dev-Id", "")
023: https.InitClientCertificates()
024:
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in .../components/tasks/ViewContentTask.xml(20)
020: https.SetUrl(url)
Backtrace:
#0 Function loadcontent() As Void
file/line: .../components/tasks/ViewContentTask.xml(20)
Local Variables:
global rotINTERFACE:ifGlobal
m roAssociativeArray refcnt=3 count:2
url roString (2.1 was String) refcnt=1 val:"https://myurl.com?id=00000155-07f6-df14-a955-27f78fd30"...
https Invalid
response <uninitialized>
content <uninitialized>

BrightScript Debugger>
0 Kudos
6 Replies
kevxcs
Level 7

Re: Scene Graph roUrlTransfer

An update to my previous post ... I'm finding that I can't use roUrlTransfer in a task node at all.

The app creates a scene, the scene then loads a group which contains a rowlist and runs a task to create the content for that rowlist by downloading a json and created a contentnode structure from it. I don't see an issue with the logic but the error says "BRIGHTSCRIPT: ERROR: roUrlTransfer: class PLUGIN|MARKUP on thread RENDER: .../components/tasks/ViewContentTask.xml(19)".

I thought the task ran in it's own thread?

This:
Function LoadContent()
m.LoadTask = CreateObject("roSGNode", "ViewContentTask")
m.LoadTask.observeField("content", "ViewContentChanged")
m.LoadTask.sourceid = m.top.sourceid
m.LoadTask.control = "RUN"
End Function
is how I'm creating the task so I'm really stuck here with how to get this to work.
0 Kudos
kevxcs
Level 7

Re: Scene Graph roUrlTransfer [SOLVED]

After an entire day of experimenting I have a solution, hopefully this will help anyone else that is looking to do this. I hope this makes sense ....

I wanted to pass a parameter to the group node that then passed that into the task so it could download specific content from the server and use it generate content for a rowlist. Specifiying the parameter as an interface field didn't work, it was always empty when the task ran regardless of what I did. Adding the onchange event to the field in the task and using that to trigger the download from the server failed with the error message in my previous post. Very confusing!

So what I've ended up doing is set up my task in a WAIT state and then use an onchange event of the interface field in the group node to set the interface field value in the task and then change the task state to RUN.

<interface>
<field id="sourceid" type="string" alias="sourceid" alwaysNotify="true" onChange="RunWaitingTask"/>
</interface>

<script type="text/brightscript">
<![CDATA[
Sub init()
m.top.setFocus(true)
m.LoadTask = CreateObject("roSGNode", "ViewContentTask")
m.LoadTask.observeField("content", "ViewContentChanged")
m.LoadTask.control = "WAIT"
End Sub

Sub ViewContentChanged()
print "content change"
End Sub

Sub RunWaitingTask()
m.LoadTask.sourceid = m.top.sourceid
m.LoadTask.control = "RUN"
End Sub
]]>
</script>
0 Kudos
Tyler_Smith
Level 7

Re: Scene Graph roUrlTransfer

Haha, I ran into this the first time wrote a url transfer task as well.
Same solution! Glad you sorted it out Smiley Happy
Tyler Smith
Senior Developer, REDspace
redspace.com
0 Kudos
TheEndless
Level 7

Re: Scene Graph roUrlTransfer

"kevxcs" wrote:
I thought the task ran in it's own thread?

As you've discovered, only the "functionName" runs in it's own thread, and only when the task is "RUN". "onChange" events always run in the render thread, even when triggered by a task thread.

Your solution looks like the right way to go about what you're trying to do, but "WAIT" isn't a valid value for Task.control, and doesn't actually accomplish anything, so you could get rid of that line.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
kevxcs
Level 7

Re: Scene Graph roUrlTransfer

Thanks for the comments guys Smiley Happy The transition to Scene Graph is quite confusing at times.

I'm sure I saw WAIT somewhere in an example, maybe I'm just going a little silly from frustration! Thanks for that, so I guess it's in a wait state by default until control is set to run. Slowly getting there although the little hair I have left will be gone by the end of the month.

Thanks again,
Kev
0 Kudos
anacron
Level 7

Re: Scene Graph roUrlTransfer

Do u have full source.zip/github included json format for my reference?..im still looking the solution...but i cannot fully understand how to implement to my source.
0 Kudos