kidasov
8 years agoChannel Surfer
How to start task again?
I have a problem with task. I want to get data from the server. So I have a task:
In mainscene I create a task in main function
Also there is a function to start my task.
I get data (bunch of videos) from server like this:
And the problem happens in callback when I get first page with videos and want to get another one page by restarting task. But code in executeTask function never happens.
I highly appreciate any help or advice. Also feel so sorry for my bad english.
sub init()
m.top.functionName = "executeTask"
vimeoClientID = "clientId"
vimeoClientSecret = "clientSecret+"
blob = CreateObject("roByteArray")
blob.FromAsciiString(vimeoClientID + ":" + vimeoClientSecret)
m.base64Vimeo = blob.ToBase64String()
end sub
function executeTask()
url = m.top.url
print("In execute task function")
request = CreateObject("roURLTransfer")
request.SetCertificatesFile("common:/certs/ca-bundle.crt")
request.AddHeader("X-Roku-Reserved-Dev-Id", "")
request.AddHeader("Authorization","basic " + m.base64Vimeo)
request.InitClientCertificates()
request.SetURL(url)
m.top.response = request.getToString()
m.top.request = url
end function
In mainscene I create a task in main function
sub init()
m.requestTask = CreateObject("roSGNode", "RequestTask") [size=85][font=Helvetica Neue, Helvetica, Arial, sans-serif] [/font][/size]
end sub
Also there is a function to start my task.
sub makeURLRequest(props)
m.requestTask.setField("url", props.url)
m.requestTask.control = "RUN"
m.requestTask.observeField("response", props.callback)
end sub
I get data (bunch of videos) from server like this:
sub getVimeoChannelVideosPage(page, callback)
print("Making request for page: " + page.toStr())
makeURLRequest({
url: "https://api.vimeo.com/channels/" + m.channel.id + "/videos?page=" + page.toStr(),
callback: callback,
})
end sub
sub getVimeoChannelVideos(callback)
getVimeoChannelVideosPage(1, "onGetVimeoVideosPage")
end sub
And the problem happens in callback when I get first page with videos and want to get another one page by restarting task. But code in executeTask function never happens.
sub onGetVimeoVideosPage()
response = m.requestTask.response
json = parseJSON(response)
videos = json.data
nextPage = json.paging.next
if (nextPage <> invalid)
m.channel.currentPage += 1
print("Current page " + m.channel.currentPage.toStr())
getVimeoChannelVideosPage(m.channel.currentPage, "onGetVimeoVideosPage")
else
showScene(m.homeScene)
end if
end sub
I highly appreciate any help or advice. Also feel so sorry for my bad english.