<component name = "haamroContent" extends = "Task" >
<interface>
<field id = "HTTPurl" type = "string" />
<field id = "HTTPcontent" type = "string" />
</interface>
<script type = "text/brightscript" >
<![CDATA[
sub init()
m.top.functionName = "getData"
end sub
function getData()
url = m.top.HTTPurl
http = createObject("roUrlTransfer")
http.RetainBodyOnError(true)
port = createObject("roMessagePort")
http.setPort(port)
http.setCertificatesFile("common:/certs/ca-bundle.crt")
http.InitClientCertificates()
http.enablehostverification(false)
http.enablepeerverification(false)
http.setUrl(url)
if http.AsyncGetToString() Then
msg = wait(10000, port)
if (type(msg) = "roUrlEvent")
'HTTP response code can be <0 for Roku-defined errors
if (msg.getresponsecode() > 0 and msg.getresponsecode() < 400)
m.top.HTTPcontent = msg.getstring()
else
? "feed load failed: "; msg.getfailurereason();" "; msg.getresponsecode();" "; m.top.HTTPurl
m.top.HTTPcontent = ""
end if
http.asynccancel()
else if (msg = invalid)
? "feed load failed."
m.top.HTTPcontent =""
http.asynccancel()
end if
end if
end function
]]>
</script>
</component>
function getHTMLContent(webpage as string)
m.haamro = createObject("RoSGNode", "haamroContent")
m.haamro.HTTPurl=webpage
m.haamro.functionName="getdata"
m.haamro.ObserveField("HTTPcontent","gotContent")
m.haamro.control = "RUN"
end function
sub gotContent()
m.top.content = m.haamro.HTTPcontent '<================== callback triggered // content is set on Scene (myfunction.xml) where I will be using my function
print m.top.content <--- this is working and prints the output
end sub
function GrabWOD(webpage as string) <==== This is the function I am trying to call from other functions
getHTMLcontent(webpage) <-- calling my getHTMLcontent function, which triggers gotContent
html=m.top.content <-- isn't m.top.content now set ??
print html <-- not working
return html <-- not working
end function
html=m.top.content <-- isn't m.top.content now set ??
m.haamro.ObserveField("HTTPcontent","newDifferentFunction")
...
sub newDifferentFunction()
m.top.content = m.haamro.HTTPcontent
' or '
html = m.haamro.HTTPcontent
print html
end sub
function getHTMLContent(webpage as string)
m.haamro = createObject("RoSGNode", "haamroContent")
m.haamro.HTTPurl=webpage
m.haamro.functionName="getdata"
m.haamro.ObserveField("HTTPcontent","gotContent")
m.haamro.control = "RUN"
end function
sub gotContent()
m.top.content = m.haamro.HTTPcontent
print m.top.content '<--- this is working and prints the output'
end sub
function GrabWOD(webpage as string)
m.haamro.HTTPurl=webpage
m.haamro.ObserveField("HTTPcontent","newDifferentFunction")
m.haamro.control = "RUN"
' This function can never see the response from the task, it has to use the observeField callback to get it'
end function
sub newDifferentFunction()
m.top.content = m.haamro.HTTPcontent
' or '
html = m.haamro.HTTPcontent
print html
end sub
function show_web_content (webpage)
......
return webcontent
end function
function getHTMLContent(webpage as string) <=== HTTPcontent is not set yet so I cannot return its value from this function
m.haamro = createObject("RoSGNode", "haamroContent")
m.haamro.HTTPurl=webpage
m.haamro.functionName="getdata"
m.haamro.ObserveField("HTTPcontent","gotContent")
m.haamro.control = "RUN"
end function
function gotContent() <=== this function is called from above, so not sure how do I return the value from this function to the main function that is making HTTP Request.
m.top.content = m.haamro.HTTPcontent
print m.top.content
end function
Please delete this, replied here instead of another post by error.
We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.
Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality.
In the meantime, for additional assistance, visit our Support Site.
We're sorry for this disruption — we’re excited to share what’s next!