Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
venkatareddy
Visitor

roMessagePort: Trying to construct a message port on a non-plugin thread

I am getting error in Home.brs , when I calling the service .Getting error at the line  request.SetMessagePort(port)

Here is the error,

BRIGHTSCRIPT: ERROR: roUrlTransfer: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/Home/Home.brs(67)
BRIGHTSCRIPT: ERROR: roMessagePort: Trying to construct a message port on a non-plugin thread: pkg:/components/Home/Home.brs(68)

BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Suspending threads...
Thread selected:  1*   pkg:/components/Home/Home.brs(69)       request.SetMessagePort(port)

Current Function:
065:  Function getMenuItemsByGroup() 
066:      mplinkStatus = CreateObject("roDeviceInfo").GetLinkStatus()
067:      request = CreateObject("roUrlTransfer")
068:      port = CreateObject("roMessagePort")
069:*     request.SetMessagePort(port)
070:      request.SetRequest("GET")
071:      request.SetUrl("URL")
072:      if (request.AsyncGetToString())
073:        while (true)
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/components/Home/Home.brs(69)
069:     request.SetMessagePort(port)
Backtrace:
#1  Function getmenuitemsbygroup() As Dynamic
   file/line: pkg:/components/Home/Home.brs(69)
#0  Function init() As Dynamic
   file/line: pkg:/components/Home/Home.brs(28)
Local Variables:
global           Interface:ifGlobal
m                roAssociativeArray refcnt=3 count:4
mplinkstatus     Boolean val:true
request          Invalid
port             Invalid
msg              <uninitialized>
code             <uninitialized>
items            <uninitialized>
json             <uninitialized>
resultlist       <uninitialized>
result           <uninitialized>
resultitem       <uninitialized>
event            <uninitialized>
Threads:
ID    Location                                Source Code
 0    pkg:/source/main.brs(16)                screen.show()
 1*   pkg:/components/Home/Home.brs(69)       request.SetMessagePort(port)
  *selected

Brightscript Debugger> 
Thread detached

Thread detached

Please find the code,

Home.xml :

<?xml version="1.0" encoding="utf-8" ?> 
<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name="Home" extends="Panel" >
<interface>
<field id="rowListContent" type="node" onchange="rowListContentChanged" />
</interface> 
<script type="text/brightscript" uri="pkg:/components/Home/Home.brs"/>
<children>
  <RowList id="theRowList"/>
  <Poster id = "icon"  />  
</children>
</component>


Home.brs :

function init()
 menuList = getMenuItemsByGroup() 
    for each menu in menuList
        print "menu type is : ";menu.type
        carouselList = getCarouselItemsByType(menu.type)
    end for
end function

Function getMenuItemsByGroup() 
    mplinkStatus = CreateObject("roDeviceInfo").GetLinkStatus()
    request = CreateObject("roUrlTransfer")
    port = CreateObject("roMessagePort")
    request.SetMessagePort(port)
    request.SetRequest("GET")
    request.SetUrl("URL")
    if (request.AsyncGetToString())
      while (true)
          msg = wait(0, port)
          if (type(msg) = "roUrlEvent")
              code = msg.GetResponseCode()
              if (code = 200)              
                  items = CreateObject("roArray", 1, true)
                  json = ParseJSON(msg.GetString())
                  resultList = json.results
                  for each result in resultList
                     resultItem = {
                          title: result.title
                          type: result.name
                          noOfElements: result.pageSize
                          layoutType: result.layoutType
                      }
                      print "result item : ";resultItem
                      items.push(resultItem)
                  end for
                  return items
              endif
          else if (event = invalid)
              request.AsyncCancel()
          endif
      end while
    endif
    return invalid
End Function



Function getCarouselItemsByType(carouselType) as object
    mplinkStatus = CreateObject("roDeviceInfo").GetLinkStatus()
    print "link status is :";mplinkStatus 
    if (not mplinkStatus) then  
        ShowMessageDialog("Alert","No network connection")
        return invalid
    end if
    request = CreateObject("roUrlTransfer")
    print "request is :";request
    port = CreateObject("roMessagePort")
    print "port is :";port
    request.SetMessagePort(port)
    request.SetRequest("GET")
    request.SetUrl("URL")
    if (request.AsyncGetToString())
      while (true)
          msg = wait(0, port)
          if (type(msg) = "roUrlEvent")
              code = msg.GetResponseCode()
              if (code = 200) 
                  items = CreateObject("roArray", 1, true)
                  print "items is :";items
                  json = ParseJSON(msg.GetString())
                  resultList = json.results
                  for each result in resultList
                     print "result is: ";result
                     images = CreateObject("roArray", 1, true)
                     imageItems = result.images.values
                     
                     for each imageItem in imageItems
                          image ={
                            profile: imageItem.profile
                            type: imageItem.type
                            link: imageItem.link
                          }
                          print "image link is : "image.link;
                          images.push(image)
                      end for
                      print "images count ";images.Count()
                     resultItem = {
                          id: result._id
                          title: result.title
                          description: result.generalInfo.description
                          images: images
                      }
                      items.push(resultItem)
                  end for
                  return items
              endif
          else if (event = invalid)
              request.AsyncCancel()
          endif
      end while
    endif
  return invalid
End Function
0 Kudos
3 REPLIES 3
RokuNB
Roku Guru

Re: roMessagePort: Trying to construct a message port on a non-plugin thread

The second diagnostic is confusing even to me, i admit -
but what it means is that you cannot create roUrlTransfer or roMessagePort in the render thread.
See https://sdkdocs.roku.com/display/sdkdoc ... pt+Support
0 Kudos
oa24153
Binge Watcher

Re: roMessagePort: Trying to construct a message port on a non-plugin thread

So whats the solution? to solve this error?

0 Kudos
renojim
Community Streaming Expert

Re: roMessagePort: Trying to construct a message port on a non-plugin thread

The solution is right above you.  You can't use roUrlTransfer (and, I imagine, any kind of message port) in the render thread; you have to use it in the main loop or a task node.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos