Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .vscode/launch.json

This file was deleted.

12 changes: 8 additions & 4 deletions components/rowListContent.brs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
sub init()
m.global.http.request = { payload: {
m.http = createObject("roSGNode", "httpTask")
m.http.control = "RUN"
m.http.request = { payload: {
userId: 1,
title: "WOW, IT WORKED ^_^",
}, url: "https://jsonplaceholder.typicode.com/albums", requestType: "GET"}
m.global.http.observeFieldScoped("response", "useResponse")
}, url: "https://www.youtube.com/watch?v=1FL22N1EXDo", requestType: "GET" }
m.http.observeFieldScoped("response", "useResponse")
Comment on lines +4 to +8
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should request after we observe the field.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

end sub

sub useResponse()
?m.global.http.response
initialPlayerResponseRegEx = createObject("roRegex", "ytInitialPlayerResponse\s*=\s*({.+?})\s*;", "m")
matches = initialPlayerResponseRegEx.match(m.http.response.body)
?ParseJson(matches[1]).streamingData.adaptiveFormats[0].url
end sub
3 changes: 0 additions & 3 deletions components/rowListScene.brs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
sub init()
m.global.addField("http", "node", FALSE)
m.global.addField("ratio", "float", FALSE)
m.global.http = createObject("roSGNode", "httpTask")
m.global.http.control = "RUN"
m.global.ratio = 1
m.rowList = m.top.findNode("mainRowList")
m.rowList.content = createObject("roSGNode", "RowListContent")
Expand Down
30 changes: 14 additions & 16 deletions components/tasks/httpTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ function handleCalls() as Object
response = fire(msg.getData())
end if
else if msgType = "roUrlEvent"
if msg.getInt() = 1
if msg.getResponseCode() > 0
response = handleResponse(msg.getString(),msg,true)
else
response = handleResponse(msg.getFailureReason(),msg,false)
end if
if msg.getInt() = 1
if msg.getResponseCode() > 0
response = handleResponse(msg.getString(), msg, true)
else
response = handleResponse(msg.getFailureReason(), msg, false)
end if
m.top.response = response
return response
end if
m.top.response = response
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response can be uninitialized here.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we don't need it's return

return response
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we can handle only a single request? If yes then m.urlRequest AA is useless.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'll save the request's result in the response's AA and after resolving it we'll clear it's index

end if
end while
end function
Expand All @@ -31,7 +31,7 @@ function fire(request as Object) as Object
httpRequest = initiateHttpClient(request.url)
requestId = httpRequest.getIdentity().ToStr()
m.urlRequest[requestId] = {
Comment on lines 32 to 33
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better:

    m.urlRequest[httpRequest.getIdentity().ToStr()] = {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

request:httpRequest
request: httpRequest
}
if checkRequestType(request.requestType)
httpRequest.AsyncPostFromString(formatJson(request.payload))
Expand All @@ -42,15 +42,15 @@ end function

function handleResponse(responseString as String, message as Object, isOk as Boolean) as Object
if isOk
body = parseJson(responseString)
body = responseString
else
body = "An Error has Occurred!!"
end if
requestId = message.GetSourceIdentity().ToStr()
m.urlRequest[requestId] = invalid
requestId = message.GetSourceIdentity().ToStr()
m.urlRequest[requestId] = invalid
return {
requestId: requestId
body:body
body: body
}
end function

Expand All @@ -60,9 +60,7 @@ function initiateHttpClient(url as String) as Object
httpRequest.InitClientCertificates()
httpRequest.SetPort(m.port)
httpRequest.SetUrl(url)
httpRequest.RetainBodyOnError(true)
httpRequest.addHeader("Content-Type", "application/json")
httpRequest.addHeader("Accept", "application/json")
httpRequest.RetainBodyOnError(false)
return httpRequest
end function

Expand Down
1 change: 1 addition & 0 deletions components/tasks/httpTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<field id="request" type="assocarray" />
<field id="response" type="assocarray" />
</interface>
<children></children>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needed.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

</component>