Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
kyleabaker
Level 7

Better to re-use the same screen port or create new one?

I've noticed in at least one of the sdk examples that a port is being created and reused for more than one screen (stored in m.port). Will this cause problems stacking screens with the same port or should I be creating a unique port object for each screen?
0 Kudos
5 Replies
destruk
Level 10

Re: Better to re-use the same screen port or create new one?

When you check a port, it removes the keypress from the queue. So really, one port or multiple ports shouldn't make much of a difference.
0 Kudos
TheEndless
Level 7

Re: Better to re-use the same screen port or create new one?

Sharing a port allows you to use the same wait loop to process events from multiple components (e.g., an roImageCanvas on top of an roVideoPlayer with roSystemLog enabled). If you don't have that need, then it doesn't really matter which approach you take.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
gabek
Level 7

Re: Better to re-use the same screen port or create new one?

I like the approach of creating one central event bus, with one loop. Each component can re-use the same port assigned to that loop and all callbacks can come through that central point. Not everybody needs that, but I find that it cleans things up.
0 Kudos
belltown
Level 7

Re: Better to re-use the same screen port or create new one?

"gabek" wrote:
I like the approach of creating one central event bus, with one loop. Each component can re-use the same port assigned to that loop and all callbacks can come through that central point. Not everybody needs that, but I find that it cleans things up.

With only one event loop handling all events from all components, you'd need a way to know which component generated which event. That might be harder to do if they share the same port, depending on the complexity of your code.
https://github.com/belltown/
0 Kudos
gabek
Level 7

Re: Better to re-use the same screen port or create new one?

"belltown" wrote:
With only one event loop handling all events from all components, you'd need a way to know which component generated which event. That might be harder to do if they share the same port, depending on the complexity of your code.


It's true! My logic is broken up by component. As messages come in it gets routed to a function for that component type that determines who is expecting that callback. I suppose it sounds more complex typing it out than I think it is Smiley Happy But centralizing that code has been cleaner for me.
0 Kudos