Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port filtering while requesting new port #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NoneTirex
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.

None yet

2 participants