How can a JavaScript app detect if a Leap Motion device is connected

Theo

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.

Dmitrii S.

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:

  • deviceConnected - A Leap device has been connected
  • deviceDisconnected - A Leap device has been disconnected

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]

編集
0

コメントを追加

0

関連記事

分類Dev

How HTTPs proxies can detect HTTPs packets?

分類Dev

How can i make my springboot app websocket app get connected via a "ws://" url while using stomp

分類Dev

How can an app detect that it's going to be uninstalled?

分類Dev

How can we programmatically detect which iOS version is device running on?

分類Dev

How to reliably detect if an external keyboard is connected on iOS 9?

分類Dev

How to detect the turnover motion in android?

分類Dev

How to get IP address of cellular network when device is connected to WiFi in Android

分類Dev

How can I detect macOS command keys in JavaScript

分類Dev

Detect rings/circuits of connected voxels

分類Dev

Swift, macos - Can I detect or make other app to be in the foreground?

分類Dev

How can I detect a hidden Desktop?

分類Dev

How to install a Progressive Web App on a mobile device?

分類Dev

How can I detect embeds in a message?

分類Dev

How many (classes of) objects can YOLO detect?

分類Dev

How does an AWS IoT device show as "connected"

分類Dev

How to make pulseaudio and ubuntu detect the same audio device as alsa driver

分類Dev

I Can't Shake/Motion on my device

分類Dev

How can we detect notification cancel?

分類Dev

Leap Motion Controller SetTimeout Javascriptスコアリングが不正確ですか?

分類Dev

Get connected HDMI device's HDMI version in android app

分類Dev

How can I detect and parse from one of these string formats in JavaScript?

分類Dev

Detect if a USB device is plugged in Javascript from browser

分類Dev

How to detect click event of connected Bluetooth peripheral device (Selfie stick)?

分類Dev

Can't run app on Android device

分類Dev

How to detect if Chromecast is already connected on Android Sender?

分類Dev

How detect the devices connected to wif network

分類Dev

LEAP MOTION + OCULUS + THREE.JS: can't get "optimizeHMD = true" working (head mounted)

分類Dev

Detect iOS device battery level when app is closed

分類Dev

更新機能でのLeap Motion再生音(openframework)

Related 関連記事

  1. 1

    How HTTPs proxies can detect HTTPs packets?

  2. 2

    How can i make my springboot app websocket app get connected via a "ws://" url while using stomp

  3. 3

    How can an app detect that it's going to be uninstalled?

  4. 4

    How can we programmatically detect which iOS version is device running on?

  5. 5

    How to reliably detect if an external keyboard is connected on iOS 9?

  6. 6

    How to detect the turnover motion in android?

  7. 7

    How to get IP address of cellular network when device is connected to WiFi in Android

  8. 8

    How can I detect macOS command keys in JavaScript

  9. 9

    Detect rings/circuits of connected voxels

  10. 10

    Swift, macos - Can I detect or make other app to be in the foreground?

  11. 11

    How can I detect a hidden Desktop?

  12. 12

    How to install a Progressive Web App on a mobile device?

  13. 13

    How can I detect embeds in a message?

  14. 14

    How many (classes of) objects can YOLO detect?

  15. 15

    How does an AWS IoT device show as "connected"

  16. 16

    How to make pulseaudio and ubuntu detect the same audio device as alsa driver

  17. 17

    I Can't Shake/Motion on my device

  18. 18

    How can we detect notification cancel?

  19. 19

    Leap Motion Controller SetTimeout Javascriptスコアリングが不正確ですか?

  20. 20

    Get connected HDMI device's HDMI version in android app

  21. 21

    How can I detect and parse from one of these string formats in JavaScript?

  22. 22

    Detect if a USB device is plugged in Javascript from browser

  23. 23

    How to detect click event of connected Bluetooth peripheral device (Selfie stick)?

  24. 24

    Can't run app on Android device

  25. 25

    How to detect if Chromecast is already connected on Android Sender?

  26. 26

    How detect the devices connected to wif network

  27. 27

    LEAP MOTION + OCULUS + THREE.JS: can't get "optimizeHMD = true" working (head mounted)

  28. 28

    Detect iOS device battery level when app is closed

  29. 29

    更新機能でのLeap Motion再生音(openframework)

ホットタグ

アーカイブ