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

PR: Unify API between WebSerial and this #2238

Closed
frank-dspeed opened this issue Apr 20, 2021 · 4 comments
Closed

PR: Unify API between WebSerial and this #2238

frank-dspeed opened this issue Apr 20, 2021 · 4 comments

Comments

@frank-dspeed
Copy link
Contributor

frank-dspeed commented Apr 20, 2021

💥 Proposal

What feature you'd like to see

(A clear and concise description of what the proposal is.)
I will implement functions that exist on the WebSerial API on this Project as also Port the most API's of this project to WebSerial.

Motivation

I want to enable Easyer Code ReUse between the both API's so that serialport and webSerialApi can be used with the same code.

Pitch

Will Allow people to use node-serialport as normal with NodeJS while allowing to switch to WebSerialAPI when running in Electron or NW.JS or the Browser.

Implementation State

Includes Interface and bindings for webserial
npm install @serialport/webserial

const SerialPort = await import('@serialport/webserial');
// Usage like SerialPort Docs but also supports All Methods of the WebStream API & WebSerial API

The Goal is to allow better code reuse between node-serialport and WebSerialAPI

Web StreamAPI

Break Able Read maybe implement able via https://github.com/MattiasBuelens/web-streams-polyfill

const { value, done } = port.read();

Related Issues

@reconbot
Copy link
Member

Making a binding that uses web serial is a great idea.

@frank-dspeed
Copy link
Contributor Author

@reconbot it is not only about the binding there is more i also need to add some extra objects and functions. As also stop to force using buffer but all that is not needed. Will expose the same api that serialport uses in the W3C Specs and i will only add some interfaces to your application to support both syntaxes. so you can use node-serialport or WebSerialApi if it exists.

i just created a repo for that where i also publish a pollyfill so that the WebSerialApi matches your API with the event emitter and all that. https://github.com/frank-dspeed/WebSerialToSerialPort-API

@frank-dspeed
Copy link
Contributor Author

Conclusion

Implementing a WebSerial API brings no reuseable code because of the Permission System of the Browser and so the alternate methods of retriving ports.

There exists a WebStream Ponyfill that can get used to reuse Logic between the implementations.

At All i Come to the conclusion that nothing can be added here that would bring any benefits anyway i want to add similar behavior to some of the functions in here i think needs more evaluations of code samples

@reconbot
Copy link
Member

reconbot commented Jul 5, 2021

closing this over #2271

@reconbot reconbot closed this as completed Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants