swissmanu / harmonyhubjs-client

A Node.JS library which allows you to interact with your Logitech Harmony Hub.
https://github.com/swissmanu/harmonyhubjs-client
MIT License
155 stars 42 forks source link

General implementation recommendations? #24

Closed netactivenl closed 8 years ago

netactivenl commented 8 years ago

Hi,

I'm a noob on NodeJs development, so please forgive me for asking this here. It just happens I'm building an app using the harmonyhubjs-client. My app needs to send commands to the hub, but also receive triggers when the current hub activity changes. My app would be running 24/7.

I'd like some advise on whether to go for one global client instance and use that for everything (so reusing one connection over and over) or to instantiate a client whenever the app is requested to execute an action (e.g. change the current activity) and immediately close the client (connection) afterwards.

Any advice would be greatly appreciated!

Cheers, Raymond

swissmanu commented 8 years ago

hi raymond

there is no correct or wrong answer. it really depends on how you are gonna structure your application.

having a "global" client for everything should not be a problem i guess. you can model your system into various sub modules and let them all use the global instance. or you go the opposite extreme and let each module connect to a hub on its own. i'm not sure how logitech limits the max. connection count on their hardware though.

i personally would prefer the "many modules, one client instance" approach for getting things started. you could easy switch to isolated clients if needed this way.

make sure you have a look at orchestra-jsapi. it builds upon harmonhubjs-client and harmonhubjs-discover and abstracts away some low-level stuff for you. this may make things more easy for you if you're not that experienced with nodejs yet.

happy hacking & let me know how things work out :)