CartoDB / mobile-sdk

CARTO Mobile SDK core project
https://carto.com/docs/carto-engine/mobile-sdk/
BSD 3-Clause "New" or "Revised" License
179 stars 65 forks source link

[New Platform] Compile Mobile SDK to the Web/Javascript via Emscripten #510

Open bugra9 opened 1 year ago

bugra9 commented 1 year ago

Hi @mtehver, I ported this excellent project to the web. My motivation,

This implementation covers multiple projects so I'm writing to this issue instead of a pull request. Related projects;

Demo: https://mobile-sdk-web.netlify.app/ Example Usage: https://github.com/bugra9/mobile-sdk/blob/emscripten-support/scripts/emscripten-dev/main.js

In the demo application, the debug icon appears after 7 seconds. You can test live with it.

Tested;

Known Issues;

  • Rendering/animation worked on MacOS 12 and on iOS 15.5 but tiles were not loaded. Safari log shows 'Failed to load resource: Worker load was blocked by Cross-Origin-Embedder-Policy'
  • Empty page on iOS 14.3. Could not find anything in the log. My guess is that WebAssembly is not supported on this device. So probably expected.
farfromrefug commented 1 year ago

@bugra9 amazing! I tried your demo site on my mobile phone and I got a blank page. I ll try tomorrow on my computer

bugra9 commented 1 year ago

@farfromrefug, I deployed very fast and didn't optimize for size. If your internet is slow, you may have to wait a little longer.

What is your browser name?

I tested it on Firefox Android and Chrome Android and it worked.

farfromrefug commented 1 year ago

I waites quite a lot and still white page. I see the debug button but then nothing in the console. tried on system webview, bromite(chrome) and mull(Firefox)

mtehver commented 1 year ago

@bugra9 Very impressive! I did a basic Emscripten port of mobile-carto-libs 2-3 years ago just for testing but making full SDK port seemed way too much work :-).

I will take a closer look at the code later this week and will add detailed questions/comments. But at the high level it looks very good.

I did a quick test on different devices:

bugra9 commented 1 year ago

Thank you. It was quite difficult for me, but the result was worth the effort. I learned a lot.

SharedArrayBuffer is required for thread support. For security reasons, it is necessary to add two headers to the response. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements

I added "Cross-Origin-Opener-Policy: same-origin" and "Cross-Origin-Embedder-Policy: require-corp" but I don't understand why Apple doesn't allow access to SharedArrayBuffer. I will investigate this.