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: 
cescamilla
Visitor

Make custom object globally available on the app

Hi Roku lovers, 

i'm trying to put a global object full of functions and attributes that allows the app to report videoplayer events and app events to Google Analytics, the app uses SceneGraph 
i've tried put the object into 'm.global' on 'main.brs' file, but the scope is not global, it only works on that file.
i've tried to create a notification port and listen to it, but when setting 'm.port' on player.ObserveField("position","m.port") in another file, the 'm.port' property is invalid, again a scope problem.

The custom object has the following structure:

function GA() as Object
return{  
          init : function (init_args) as Void
          //init code
         end function

         func_1 : function()

         end function
       'and many other functions to report events
      }

there is one method that will receive all the notifications "handleScenegraphEvent", notification in form of messages of node.ObserveField

i've tried putting the object into 'm' as follows in 'main.brs':


gareporter = GA()
gareporter.init("UAID123456","RokuEvent[size=100]")[/size]
m.reporter ={}
m.reporter = gareporter

and
m.addField("reporter","asocarray",true)
gareporter = GA()
gareporter.init("UAID123456","FusionRoku")
m.reporter = gareporter




while working on the same file the property 'm.reporter' is accesible, but when the code is coming from another file, the property is null.

i hope the question is clear enough to give me some hints.

Thanks for your help



          
~ Carlos ~
0 Kudos
13 REPLIES 13
EnTerr
Roku Guru

Re: Make custom object globally available on the app

To access the "global Noid" from main, you have to call roSGScreen.getGlobalNode(). For consistency, it's advisable in main() you manually assign that to m.global and continue using that `m.global`, as in other threads:
m.global = screen.getGlobalNode()

But guess what... even then you can't do what you want, because RSG Nodes do not support function type[/url:1jq54gt9]! Methods will be stripped, silently but deadly...
0 Kudos
cescamilla
Visitor

Re: Make custom object globally available on the app

Hey, thanks for the quick reply, i just find out that problem with function type, my second option is setting a global port to all fields i want to observe, can i use "m.global = screen.getGlobalNode" to pass the port all over the app?
~ Carlos ~
0 Kudos
EnTerr
Roku Guru

Re: Make custom object globally available on the app

"cescamilla" wrote:
Hey, thanks for the quick reply, i just find out that problem with function type, my second option is setting a global port to all fields i want to observe, can i use "m.global = screen.getGlobalNode" to pass the port all over the app?

You mean, do roSgNode fields support `roMessagePort` (or more generally, `Object`) type? No, they do not!
A list of what is supported is here a very particular set of skills.
0 Kudos
cescamilla
Visitor

Re: Make custom object globally available on the app

then it seems like a dead end for what i want to do 😞
~ Carlos ~
0 Kudos
belltown
Roku Guru

Re: Make custom object globally available on the app

If you want to do what you say you want to do: report video player events to Google Analytics, then define a Task Node to do the reporting. Include the Task Node in your scene that contains the Video Node, then whenever you have an event to log, set the event details in an interface field defined on the Task Node; in the Task Node, use roUrlTransfer to send the request to Google Analytics. 
0 Kudos
cescamilla
Visitor

Re: Make custom object globally available on the app

Thanks, will read about it and try it.
~ Carlos ~
0 Kudos
Veeta
Visitor

Re: Make custom object globally available on the app

https://github.com/veeta-tv/roku-gamp has recently added scene graph support just as belltown described
0 Kudos
cescamilla
Visitor

Re: Make custom object globally available on the app

@Veeta

Thanks for the reply, i'm playing with the code, but i have a question:

i see the reporting methods are used in 'main.brs', are they available too in the scenes where the video is played?
~ Carlos ~
0 Kudos
Veeta
Visitor

Re: Make custom object globally available on the app

See https://github.com/veeta-tv/roku-gamp/blob/master/roku-gamp/components/GampScene.xml. You don't call the functions directly, you assign fields on the Task node.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.