Skip to content

Commit

Permalink
Update usb package to 2.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
windowsair authored and thegecko committed Feb 24, 2024
1 parent 229bd3d commit 6a33cc9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 28 deletions.
81 changes: 60 additions & 21 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
"dependencies": {
"@types/node-hid": "^1.2.0",
"@types/usb": "^1.5.1",
"@types/w3c-web-usb": "^1.0.4"
"@types/w3c-web-usb": "^1.0.10"
},
"devDependencies": {
"@rollup/plugin-eslint": "^9.0.5",
"@stylistic/eslint-plugin-js": "^1.5.4",
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
Expand All @@ -66,7 +67,7 @@
"tslib": "^2.6.2",
"typedoc": "^0.25.7",
"typescript": "^5.3.3",
"usb": "^1.9.2",
"usb": "^2.11.0",
"webusb": "^2.2.0"
}
}
15 changes: 10 additions & 5 deletions src/transport/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ export class USB implements Transport {
await new Promise<void>((resolve, reject) => {
this.device.setConfiguration(this.configuration, error => {
if (error) {
reject(new Error(error));
reject(new Error(error.message));
} else {
resolve();
}
});
});

const interfaces = this.device.interfaces.filter(iface => {
const interfaces = this.device.interfaces?.filter(iface => {
return iface.descriptor.bInterfaceClass === this.interfaceClass;
});

if (!interfaces.length) {
if (!interfaces?.length) {
throw new Error('No valid interfaces found.');
}

Expand Down Expand Up @@ -195,7 +195,11 @@ export class USB implements Transport {
if (exception) {
reject(exception);
} else {
resolve(buffer);
if (buffer !== undefined) {
resolve(buffer);
} else {
resolve(new Buffer(0));
}
}
});
return;
Expand All @@ -214,7 +218,8 @@ export class USB implements Transport {
} else if (!buffer) {
reject(new Error('No buffer read'));
} else {
resolve(buffer);
// Buffer type for IN transfer
resolve(buffer as Buffer);
}
}
);
Expand Down

0 comments on commit 6a33cc9

Please sign in to comment.