webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.37k stars 146 forks source link

Documentation of Binary Protocol to Implement Other Wrappers #300

Closed codesplode closed 6 months ago

codesplode commented 6 months ago

Hi there and thank you for an awesome project!

I'm interested in using this project with a JVM backend and would like more information about the websocket / binary protocol the backend needs to implement to accomplish this.

Looking at the other wrapper it seems implementing this is the primary challenge to making a wrapper for the JVM, which seems like it should not be a very hard task with a good understanding of the protocol.

Could you point me in the right direction on any documentation for it? I didn't find any after going through the documentation, examples, and wrapper repositories, so it looks like digging in the C source may be the only possibility remaining, but I'm concerned about missing something doing that as I do not work in C all the time.

Thank you!

fibodevy commented 6 months ago

Why would you want to implement the protocol without using the C library? How will you start the browser, manage profiles etc? The protocol is nothing fancy, why use this one? Or you want to use just webui.js + your own backend?

hassandraga commented 6 months ago

Hey @codesplode, Welcome. What @fibodevy wants to say is that you don't need to deal with the binary communication protocol between our JVM backend and the frontend. Instead, you only need to use Java JNI to load the pre-compiled WebUI dynamic library .dll, .dynlib, .so, and start using it directly.

To create a new JVM wrapper, you have to wrap every WebUI C APIs, example (this is quick and untested):

public class WebUI {
    // Native (C) functions
    public native void webui_exit();

    // Load the library
    static {
        System.loadLibrary("webui-2");
    }

    public static void main(String[] args) {
        WebUI webui = new WebUI();
        // Call the C function
        WebUI.webui_exit();
    }
}
codesplode commented 6 months ago

Thanks so much for the quick response!

I haven't had great luck or performance with JNI in the past, but that's mostly due to attempting it with much more complex libraries. I'll definitely give that a go and I can probably write a script to generate the wrapper.

Side request: If anyone has a script already to do this binding in another language I'd appreciate pointing me to it, but I should be able to solve that with the header file.

Thank you @fibodevy and @hassandraga ! I'll share the results if all goes well!

Closing this issue for now so it is no longer in the open list as I have what I need to move forward.