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

sending data / making a website with sokol? #825

Closed
digitalsignalperson opened this issue May 3, 2023 · 3 comments
Closed

sending data / making a website with sokol? #825

digitalsignalperson opened this issue May 3, 2023 · 3 comments

Comments

@digitalsignalperson
Copy link

Can/should sokol be used to make something like a SPA? Are there any examples, e.g. interacting with a REST API?

Looking at sokol_fetch.h it looks like receiving only, not uploading (a related issue discussing sokol_fetch.h and bidirectional comms with websockets: #367)

Looking for possible solutions:

The Emscripten Fetch API allows native code to transfer files via XHR (HTTP GET, PUT, POST) and Emscripten_fetch can be used to upload files to remote servers via HTTP PUT
https://emscripten.org/docs/api_reference/fetch.html

Ways to interact with javascript with emscripten:
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-javascript-from-c-c

Similar discussion but for "Making a website with Godot", with a good comment: https://www.reddit.com/r/godot/comments/ga158t/comment/foxl2b2/?utm_source=reddit&utm_medium=web2x&context=3

It's cool that e.g. this nuklear demo is only a 350kB wasm file https://floooh.github.io/sokol-html5/nuklear-sapp.html
versus minimal godot HTML5 exports look like ~4MB

@floooh
Copy link
Owner

floooh commented May 3, 2023

The sokol headers are not a general SDK for building complete applications, they might just provide a couple of cross-platform building blocks.

If the goal is a web application (as opposed to a cross-platform application that also runs on the web), I would probably use a hybrid approach, where big blocks of functionality are implemented in JS (for instance things like communicating with REST endpoints), and the WASM code calls out into JS (or the opposite approach that the 'main loop' is implemented in JS and calls into WASM functions.

@floooh floooh closed this as completed May 3, 2023
@digitalsignalperson
Copy link
Author

I also noticed from #342

sokol_fetch.h: CURL for HTTP(S) requests on non-web platforms

https://github.com/bqqbarbhg/spear/blob/6e5017491fe3d9c4ac667a3d96585ccd55f7bc8a/src/ext/sokol/sokol_fetch_impl.h#L1673-L2001

Thoughts on implementing more curl in a cross platform way? For wasm: https://github.com/wapm-packages/curl

@floooh
Copy link
Owner

floooh commented May 4, 2023

I did something similar in an older project: https://github.com/floooh/oryol/tree/master/code/Modules/HttpFS

This attempts to use platform-native APIs for talking to HTTP endpoints. There's a couple of issues with this approach (mainly that the Windows HTTP API sucks), and in the end it's almost certainly better to link with curl on native platforms and use the fetch API on the web. Integrating curl into the build system on native platforms isn't trivial either though, so a sokol header which requires libcurl as dependency would kinda defeat the purpose of STB style headers (which always should be easy to integrate).

TL;DR: there most likely won't be a sokol header which provides a generic HTTP wrapper API.

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

2 participants