Get URL / local IP in Qt WASM
-
Hi all, I'm wondering if there's any way to get the local IP (or URL) of the web server hosting a Qt WASM program, from the program? From what I've seen through looking online, it seems it can be done through javascript, but I'm not sure how I'd go about it through this, apart from messing around with the generated js gluecode?
To clarify what I'm doing it for, I have a chat client and, not relevant for this task, a chat server. The chat client will always be downloaded from a web server running on the same IP as the chat server (on different hardcoded ports). I don't want a user to need to input the IP, as it will always be the same IP as the one it's just downloaded the client from.
Any ideas on how to go about this?
Cheers,
Ollie
-
You can use emscripten API to read the JavaScript window.location object.
#include <emscripten/val.h> ... emscripten::val location = emscripten::val::global("location"); auto host = location["hostname"].as<std::string>(); auto port = location["port"].as<std::string>();