WebAPI/WebUSB

< WebAPI
Revision as of 23:28, 1 October 2014 by Chaasof (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

WebUSB provides a way for USB device drivers to be implemented in pure JavaScript.

Basic usage strategy:

Create a MozUSBManager in order to claim specific device types and begin receiving events related to them. Once a device type is claimed, you can respond to the 'attachdevice' event by sending and receiving data over the device's endpoints.

Example:

var usbm = new MozUSBManager();
var descriptor = {
  deviceClass: n,
  deviceSubClass: n,
  deviceProtocol: n,
  deviceVendor: n,
  deviceProduct: n
};

usbm.addEventListener("attachdevice", function () {
  // ...
});
usbm.addEventListener("detachdevice", function () {
  // ...
});

usbm.claimDevice(descriptor);