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 and remove listeners #22

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

Conversation

stylesuxx
Copy link

Resolves #20

@google-cla
Copy link

google-cla bot commented Mar 23, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@stylesuxx
Copy link
Author

@googlebot I signed it!

@reillyeon
Copy link
Collaborator

Unfortunately this doesn't implement the events properly because it will pass through the USBConnectionEvent objects instead of translating them to their Web Serial API equivalents. As you guessed on #20 I did start working on a patch to implement connection events but unfortunately it's non-trivial to get right because EventTarget doesn't support specifying a custom "get the parent" algorithm. That is tracked by whatwg/dom#583 but we can probably work around it by implementing our own Event interface and dispatching routine.

@stylesuxx
Copy link
Author

Alright, I feared it would not be as easy as I thought. I mean - technically it seems to be working, at least for my use case the disconnect handler is triggered. But I will leave it now up to you to finish your proper solution.

@stylesuxx
Copy link
Author

Hey @reillyeon - just wanted to bump this issue since I am now running into the same issue with a different project and was wondering if there is any chance you made any progress with this?

@reillyeon
Copy link
Collaborator

I haven't had a chance to look at this. As a workaround your code can add its own listeners for the connect and disconnect events on navigator.usb. You can use the SerialPort constructor to turn a USBDevice instance into a SerialPort instance. It just really shouldn't be fired through the polyfill unless we can turn it to the right kind of event on the SerialPort interface.

@stylesuxx
Copy link
Author

Alright, I will give that a try, thank you.

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.

Adding and removing event listeners
2 participants