Skip to content

Conversation

@RealTirex
Copy link

It's missing feature in navigator.serial.requestPort method: https://developer.mozilla.org/en-US/docs/Web/API/Serial/requestPort

I added filtering by more elements than is described in the documentation.

Comment on lines +77 to +79
(!("id" in filter) || filter["id"] === port.id) &&
(!("name" in filter) || filter["name"] === port.name) &&
(!("transport" in filter) || filter["transport"] === port.transport)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is TypeScript, a new type for "extended" filters should be added. The SerialPortFilter type can be extended in types.ts and each filter can then be typecast to that extended type.

Also, please consider creating another (sub)function like checkPortMatch(port: SerialPortData, filter: SerialPortFilter): boolean. Each port could then be checked against each provided filter. The current form is complex to understand, because it uses ! and || with negative logic values.
A function built with if (filter.<value> && filter.<value> != port.<value>) return false; would be also less error-prone.

See:
https://wicg.github.io/serial/#dom-serialportfilter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants