The subject says it all:
How can a JavaScript app detect if a Leap Motion device is connected.
It's so easy to move the Leap Motion devices from one computer to another, how can a JavaScript app detect if there is a device currently connected to the computer?
Update 2013-08-08
I have marked this question as answered because as Dmitry's work shows there is - as of this writing - no simple way for a JavaScript app to know if a Leap Motion device is connected at the load time of the app.
That depends on what operating system API and drivers you have available. When a device is connected to a computer an operating system can detect a device connected to one of its sockets (using IRQ, polling etc.). You can then use driver or OS API (if it supports this kind of devices natively) to check a state of the device. Since this is usually done using a more low-level programming language like C++, C or even the assembly language (javascript is not suitable for several reasons) you should check your javascript API reference (not sure if you use browser API, Win8 API or something else) and see if there are any functions related.
Update: The API link you sent seems to be quite vague on that. However I figured out that it establishes a WebSocket connection to a localhost under the hood. The Controller.connect()
function is really a procedure (does not return anything). But I found a more useful link (getting started: http://js.leapmotion.com/start) there is a description of different events that they provide including the following:
You can use a callback instead of a predicate in this case:
function doMyOwnStuff()
{
console.log( "O_o" );
}
var controller = new Leap.Controller();
controller.on('deviceConnected', function() {
console.log("A Leap device has been connected.");
doMyOwnStuff();
});
controller.on('deviceDisconnected', function() {
console.log("A Leap device has been disconnected.");
});
//should probably fire a 'deviceConnected'
controller.connect();
I hope it helps because I don't have the hardware to test.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加