-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Hi
I am trying to compile PROJ library (from https://proj.org) with emscripten to be used from the browser. The main problem I have is trying to replace the cURL functionality we have.
Following this recommendation
#3270 (comment)
I used emscripten_fetch instead of cURL.
One of the requirements we have is to do the requests synchronous. The code is replacing cURL, in "kind of an inheritance". So we cannot change the design of the complete library to have asynchronous requests.
The purpose of the network access is to download small pieces of a file, using the http range-request feature. So yes, the application may block for a short time, but not a long one.
You can see how I am using emscripten_fetch with the option EMSCRIPTEN_FETCH_SYNCHRONOUS at https://github.com/jjimenezshaw/PROJ/blob/emscripten/src/networkfilemanager.cpp#L2046 (the line may change in the future) I am linking with -pthread, as documentation says (see the script below)
(Once I make it work, I will make a PR to merge that branch into master)
The options how I am compiling it are in https://github.com/jjimenezshaw/wasm-proj/blob/dev/build_wasm.sh#L273
Actually you have the full script for a docker file to see if I am doing something wrong.
It is more confusing, because in Chrome it does work, but not in Firefox or Safari.
In https://jjimenezshaw.github.io/wasm-proj/example.html , if you click on Compute, it will run a computation that ends up calling fetch (obviously if you don't deselect the "use network" option).
In Chrome it says "Blocking on the main thread is very dangerous" in the console when calling the function proj._proj_trans_array, but it continues. In Firefox it blocks there.
If the file over the network is used, the output must be "Transformed: x=3500067.619803459, y=6074524.809364015, z=0" (without network the number are different).
I would appreciate any clue about how to configure the project, and how to call emscripten_fetch correctly to make it work synchronously.
Having PROJ complete (with network access) in the browser would be very useful for many users.
Thank you
Version of emscripten/emsdk:
"4.0.5" and "4.0.19"