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

Extend the library to more use cases #46

Open
alesgenova opened this issue Jan 19, 2021 · 7 comments
Open

Extend the library to more use cases #46

alesgenova opened this issue Jan 19, 2021 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@alesgenova
Copy link
Owner

alesgenova commented Jan 19, 2021

The utilities provided by post-me can be useful for any use case in which there is only one low level channel of communication (similar to postMessage).

By adding more classes implementing the Messenger interface (and possibly extending the Messenger interface if needed) we can directly support more scenarios.

Just a couple of example that come to mind:

@alesgenova alesgenova added enhancement New feature or request help wanted Extra attention is needed labels Jan 19, 2021
@grahamlyus
Copy link

Audio Worklet support would be nice. It seemed to hang on the handshake when I tried it. Of course, I could've made a mistake

@alesgenova
Copy link
Owner Author

@grahamlyus
Yes, audio worklet would be really interesting!

Do you have a small repo/gist to provide with your attempts at using post-me with the worklet?
Would be really helpful to get started

@grahamlyus
Copy link

@alesgenova I'll try to get an minimal example going this week.

@grahamlyus
Copy link

@alesgenova It works! I modified your demo repo: grahamlyus/post-me-demo@5564993

The big caveat is that the AudioWorklet must use the ChildHandshake, because ParentHandshake uses setTimeout which is not available in the AudioWorkletGlobalScope. This would be worthwhile highlighting in the docs.

I also added a contrived example where the Parent connects the Worker and AudioWorklet via MessageChannel so they can talk to each other. Parent then calls sum on the AudioWorklet, which delegates the call to the Worker.

I think maybe where I tripped up before was possibly making the setWorkerPort and setWorkletPort return promises and awaiting them, meaning the handshake timed out. It could also be something weird with create-react-app or webpack

@alesgenova
Copy link
Owner Author

@grahamlyus Really glad to hear it worked out!

I checked out your demo, it's a pretty cool setup with the worker/worklet directly connected over the channel, and I'm quite relieved it actually worked! :)
I'm curious to see what you're building with it, feel free to follow up once you're finished.

Btw, methods can return either values or promises, it shouldn't make a difference to the library.

Good find, I didn't consider that some contexts might not have setTimeout. You're welcome to open a PR mentioning it in the docs and maybe a mention to usage with worklets too.

If you don't have time, I can probably get around to adding it some time over the weekend.

@grahamlyus
Copy link

grahamlyus commented Feb 11, 2021

@alesgenova I dropped it into my project and it all seems to still be working well.

I'm experimenting with audio processing with WebAssembly. The Web Worker is used to download and decode chunks of an audio stream on demand when the Audio Worklet asks for them, as the process function has to be quick and the Audio Worklet only has access to a limited api anyway.

I can try adding a small readme section for Audio Worklet usage it that sounds good.

@alesgenova
Copy link
Owner Author

Sounds good to me, I think it's a cool use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants