Skip to content

Commit

Permalink
Fixed USBConnectionEvent type
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko committed Jan 4, 2020
1 parent 183e468 commit 325a2d2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webusb",
"version": "2.0.0",
"version": "2.0.1",
"description": "Node.js implementation of the WebUSB Specification",
"homepage": "https://github.com/thegecko/webusb",
"author": "Rob Moran <[email protected]>",
Expand Down
11 changes: 6 additions & 5 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
* SOFTWARE.
*/

import { DOMEvent, W3CUSBConnectionEvent } from "./interfaces";

// tslint:disable:max-classes-per-file

/**
* @hidden
*/
export class Event implements DOMEvent {
export class DOMEvent implements Event {

/**
* Type of the event
Expand Down Expand Up @@ -155,10 +153,13 @@ export class Event implements DOMEvent {
}
}

export class USBConnectionEvent extends Event implements W3CUSBConnectionEvent {
/**
* @hidden
*/
export class W3CUSBConnectionEvent extends DOMEvent implements USBConnectionEvent {

/**
* {@link USBDevice} connected or disconnected
* Device connected or disconnected
*/
public readonly device: USBDevice;

Expand Down
10 changes: 0 additions & 10 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
* SOFTWARE.
*/

/**
* @hidden
*/
export interface DOMEvent extends Event {}

/**
* @hidden
*/
export interface W3CUSBConnectionEvent extends USBConnectionEvent {}

/**
* @hidden
*/
Expand Down
6 changes: 3 additions & 3 deletions src/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { EventDispatcher, TypedDispatcher } from "./dispatcher";
import { USBAdapter, adapter } from "./adapter";
import { USBConnectionEvent } from "./events";
import { W3CUSBConnectionEvent } from "./events";
import { USBDevice } from "./device";
import { W3CUSB } from "./interfaces";

Expand Down Expand Up @@ -92,7 +92,7 @@ export class USB extends (EventDispatcher as new() => TypedDispatcher<USBEvents>
const deviceConnectCallback = device => {
// When connected, emit an event if it was a known allowed device
if (this.replaceAllowedDevice(device)) {
const event = new USBConnectionEvent(this as EventTarget, "connect", { device }) as USBConnectionEvent;
const event = new W3CUSBConnectionEvent(this as EventTarget, "connect", { device }) as USBConnectionEvent;
this.dispatchEvent(event);

if (this.onconnect) {
Expand All @@ -106,7 +106,7 @@ export class USB extends (EventDispatcher as new() => TypedDispatcher<USBEvents>
const device = this.allowedDevices.find(allowedDevices => allowedDevices._handle === handle);

if (device) {
const event = new USBConnectionEvent(this as EventTarget, "disconnect", { device }) as USBConnectionEvent;
const event = new W3CUSBConnectionEvent(this as EventTarget, "disconnect", { device }) as USBConnectionEvent;
this.dispatchEvent(event);

if (this.ondisconnect) {
Expand Down

0 comments on commit 325a2d2

Please sign in to comment.