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

Programmable Audio - SharedArrayBuffer on Ordinals.com #3850

Closed
owenstrevor opened this issue Jul 10, 2024 · 7 comments
Closed

Programmable Audio - SharedArrayBuffer on Ordinals.com #3850

owenstrevor opened this issue Jul 10, 2024 · 7 comments

Comments

@owenstrevor
Copy link

owenstrevor commented Jul 10, 2024

We're emulating the Nintendo NES 8-bit sound chip and the Texas Instruments TMS5220 speech synthesizer chip to make the sound effects for the Pizza Pets project.

We noticed that ordinals.com is not running in a cross origin isolated environment, so therefore we do not have access to the "SharedArrayBuffer" object which we would like to be able to use in order to have communication between audio worklets and the main thread, without having to go through the hassle of copying memory buffers back and forth between threads.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer

I was wondering, would it be possible to set the necessary headers on your server to enable this?

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

cc @patrick99e99

Thanks so much!

@Trollfarmer
Copy link

Trollfarmer commented Jul 11, 2024

@patrick99e99
Copy link
Contributor

patrick99e99 commented Jul 14, 2024

@owenstrevor Did you try the service worker approach?

We are trying to have as good of a UX as possible, this means that we have an animated loading screen that displays immediately on page load, and proceeds to animate until all dependencies and resources have loaded. The "service worker approach" involves having an abrupt page refresh which would result in a less than ideal user experience based off of how we are loading / preparing the application.

It would be ideal if we can just get the ordinals indexers to all offer cross origin isolated environments by setting these headers.

@casey
Copy link
Collaborator

casey commented Aug 12, 2024

This seems reasonable to me. The only question I have is, it looks like these are more restrictive policies, is it possible that they could break any existing inscriptions?

@patrick99e99
Copy link
Contributor

patrick99e99 commented Aug 12, 2024

is it possible that they could break any existing inscriptions?

I can't see how. All these headers do is isolate the webpage from other origins, and disallow any communication with cross-origins that have not opted in. The result of this is the unlocking of features such as the SharedArrayBuffer.

Inscriptions viewed from the indexers already have no access to the outside world, so it's expected that they should not allow any cross-origin windows from interacting with them or making any communication with other cross-origins.

@casey
Copy link
Collaborator

casey commented Aug 12, 2024

Okay, sounds reasonable to me. Feel free to open a PR! It would also be worth thinking about how to communicate this change to the various explorers, since to get cross-ecosystem support, other explorers would have to add this header as well.

@patrick99e99
Copy link
Contributor

patrick99e99 commented Aug 12, 2024

Feel free to open a PR!

#3898

I thought more about this... One potential side effect of this change is that Ord will be completely broken for anyone attempting to run it on a different computer within their home network with intentions of accessing it remotely via a local domain like: my-other-computer-running-ord.local. This is because it requires a "secure context", so must be served with https with the exception of localhost being allowed for http.

For that reason, I added the server config option disable_cross_origin_isolated to allow people to get around this if it is ever an issue for them.

@casey
Copy link
Collaborator

casey commented Aug 13, 2024

Merged! I added a test, and changed the name of the flag to --disable-cross-origin-isolation. Thanks for the PR!

@casey casey closed this as completed Aug 13, 2024
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

No branches or pull requests

4 participants