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

Can this support wasmJs? #64

Open
LiePy opened this issue Sep 9, 2024 · 7 comments
Open

Can this support wasmJs? #64

LiePy opened this issue Sep 9, 2024 · 7 comments

Comments

@LiePy
Copy link

LiePy commented Sep 9, 2024

Hi, It's a great project, but when I try to use it in my Compose Multiplatform project, which includes wasmJs platrom, I ran into this problem
Build Error Log:
:shared:wasmJsMain: Could not resolve io.github.davidepianca98:kmqtt-common:0.4.8.
Required by:
project :shared

@davidepianca98
Copy link
Owner

Hello, WASM is not currently on the supported target list. It would be interesting to explore as a future supported target but it's not currently in the plans.

@mipastgt
Copy link

mipastgt commented Jan 2, 2025

As WASM is gaining more and more popularity it would be nice to see support for it here.

@Phaestion
Copy link

Phaestion commented Feb 9, 2025

Hi @davidepianca98 thanks for the awesome library!
I've been digging into the code to see if I could contribute a PR to as WASM support. Of course WASM and JS (browser target and not the Node target you already support) would only be able to support a Websocket connection, given that you simply can't create a TCP socket in the browser.

This led me to how you implemented the current Websocket connection on the other platforms and saw that you are essentially implemented the HTTP protocol messaging and then requesting an upgrade to a Websocket, which you then handle essentially the same as a socket after the Websocket establishment.

Given that it is not possible to get a TCP socket in the browser and that the code in the library uses a "socket" abstraction, this blocks the establishment of a Websocket in the browser directly and passing that to the rest of the code as an abstraction.

This brings up the question, why do any of the UDP, TCP, TLS socket things per platform and not just use Ktor to do that for you? This would get rid of a lot of platform specific code, leading to a lower maintenance burden and also opens up the possibility for more platforms to be supported. I realise that this would be a major change in the repository though, but I would be more than happy to help out with this effort.

@davidepianca98
Copy link
Owner

@Phaestion hello. When I initially made this library 5 years ago, I looked into using Ktor but they didn't provide the lower level networking APIs, it was just an HTTP library. Now I am not sure whether they do, but if they support both client and server for the supported platforms it would be awesome to finally be able to get rid of the lower level layer here. Unfortunately you can see that my ability to maintain this repository has been very limited in the last few months, so I very much welcome any PR that addreses any of the current issues.

@Phaestion
Copy link

That totally makes sense @davidepianca98.

Regarding the supported platforms. Ktor client supports JVM, JS (browser and Node), WASM and all Native platforms
Ktor server supports JVM and all Native platforms except mingwX64 and also no support for JS (browser and Node) and WASM.

If moving to ktor the client would gain JS Browser and WasmJS support. The broker would gain WasmJS support, however it would lose NodeJS and Mingw support. Would that be something that would be ok for you?

@Phaestion
Copy link

Phaestion commented Feb 9, 2025

Just adding to my previous comment, both ktor server and client have TCP, UDP, TLS sockets support. Of course also Websocket support.

@davidepianca98
Copy link
Owner

@Phaestion I think it's a bit unfortunate that mingw support for the broker would not be available, but I checked the ktor documentation for the sockets library and I think it's worth it. I don't know whether anyone is actually using the nodejs broker, but I consider it a really low priority target, so losing that is fine.
If you could make it happen I would be very grateful.

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