thalmiclabs / myo.js

Myo javascript bindings
Apache License 2.0
198 stars 63 forks source link

Throw error if no myo present #6

Closed jeffbryner closed 9 years ago

jeffbryner commented 9 years ago

It'd be nice if you could wrap the Myo.create() in a try/catch to tell if there is a myo in the system. Consider throwing an error if the connection to the localhost server fails such that the error could be caught to tell if there's no myo present.

stolksdorf commented 9 years ago

The Myo.create() command is used to setup listeners for a Myo to talk to over a specific address on the web socket. Once this listener is made, the Myo can connect, disconnect, sync, send poses, there's really no way to accurately detect if the Myo is actually connected or not (since the Myo could have sent the connected event before the listener as made.)

However you issue did point out an interesting problem with the myo.js. It was difficult before to react if the user didn't have Myo Connect running, or the web socket couldn't be established at all. So I added a Myo.onError function in ver1.5.0, that can be overwritten which will be triggered if the websocket connection can't be made. I think that's what wanted anyways.

Thanks for the heads up, and if this doesn't solve your problem, let me know and we'll work out a solution.

jeffbryner commented 9 years ago

Yup, I wanted to ship an app with myo support that doesn't spew errors to the console in the case of no myo.

Thanks, I'll test it out.

stolksdorf commented 9 years ago

Just a follow-up with @jeffbryner, did everything go as planned with your app?

jeffbryner commented 9 years ago

Thanks for the followup, yup I'm able to catch the error. I still get one from the browser if myo connect isn't running, but this gives me a hook to determine if it exists or not.

Thanks!