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: 
ioan
Roku Guru

What it the best way to share source with global functions between projects?

Do I have to copy the brs file with global functions in each project folder or there is a way to share it between multiple projects?
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
13 REPLIES 13
belltown
Roku Guru

Re: What it the best way to share source with global functions between projects?

What's a project?
0 Kudos
ioan
Roku Guru

Re: What it the best way to share source with global functions between projects?

"belltown" wrote:
What's a project?

All the files that make a channel... How do you call them all? Channel?
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
belltown
Roku Guru

Re: What it the best way to share source with global functions between projects?

Do you want to share code between multiple channels (i.e.share the same files between your Pro channel and your Basic channel)?

Or, do you want to share code within a single channel among multiple components within that channel?
0 Kudos
ioan
Roku Guru

Re: What it the best way to share source with global functions between projects?

"belltown" wrote:
Do you want to share code between multiple channels (i.e.share the same files between your Pro channel and your Basic channel)?

Or, do you want to share code within a single channel among multiple components within that channel?

Oh, now I understand what you mean.

I need to share code between multiple channels, between the Pro version and Basic version. Right now I copied my global brs file in both channels and make all modifications twice and I'm hoping that there is a better way to share global functions between channels. 
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
belltown
Roku Guru

Re: What it the best way to share source with global functions between projects?

I see what you want to do.

Ideally, you shouldn't have shared files that both need modifying. You should have one repository for your shared (library) code, make the changes in that one place, then copy each changed library file to both channels' directories.

If there are minor differences between files used in one channel versus files used in the other channel, then it might be worth refactoring your code. For example, you might want to pass parameters into your utility functions so that whichever channel they are called from can pass in parameters specific to that channel.

This is more of a general software engineering issue than a Roku-specific issue, so you can really do whatever you want. My main advice though would be (a) avoid repeating code; and (b) keep things as simple as possible.
0 Kudos
belltown
Roku Guru

Re: What it the best way to share source with global functions between projects?

Another option in your particular case is to only have one code base that works for both channels.

You'd obviously need a separate manifest file for each channel, and have to package and submit them separately, but all the rest of your code could be the same; it would just work differently depending on which manifest file was used.

For example, in Main(), you'd have an if-statement that creates either Pro-Scene or Basic-Scene depending on which manifest file was being used. You may have a separate XML file for each scene that each include either common or separate scene-specific brs code, as well as each including the same global brs code that you'd only need to define once.

That approach might be more complicated, but it will definitely reduce the duplication of code.
0 Kudos
destruk
Streaming Star

Re: What it the best way to share source with global functions between projects?

What we did when we faced this issue with 6 separate channels all using the same codebase with different graphics, servers, variables, etc is we used one section of main.brs to store the base urls and database information for the channels.  That way we'd just need to edit the rest once as the code was basically the same.  Something like if m.channelname="channel1" then load such and such graphcs, verify with this database, use this billing, and use these layouts instead of those other layouts, pull this feed, etc etc.  Belltown posted that when I was typing this - same thing... 🙂
0 Kudos
ioan
Roku Guru

Re: What it the best way to share source with global functions between projects?

Yeah, I guess having one code base for both channels would be easiest to maintain. Thanks to both of you for the input. 
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
EnTerr
Roku Guru

Re: What it the best way to share source with global functions between projects?

"ioan" wrote:
I need to share code between multiple channels, between the Pro version and Basic version. Right now I copied my global brs file in both channels and make all modifications twice and I'm hoping that there is a better way to share global functions between channels. 

Can i propose a very simple solution to your very specific problem, which avoids tackling at all sharing of sources between projects? 😉
Have only 1 channel source!

No, just wait a minute - hear me out: since your Basic version is a subset of the Pro version, build from a single codebase - moreover build a single app, once - then upload to 2 channels. But how will they differentiate? Quite simple - when started, query what's the channel# - roAppInfo.getID() - and based on that tune up the behavior (i.e. act as Pro or Basic). Say if the # is that of the Basic channel, then disable some features, maybe tweak some messages - otherwise (i.e. side-loaded or Pro), have the full functionality. Reminder, the channel name and thumbnails are specified in the dev.portal (outside of the app bundle).
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.