tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
960 stars 268 forks source link

Uncaught plugin websocket not found #746

Open DIMFLIX-OFFICIAL opened 11 months ago

DIMFLIX-OFFICIAL commented 11 months ago

11-20 17:14:05.142 28311 28311 E Tauri/Console: File: http://tauri.localhost/ - Line 0 - Msg: Uncaught plugin websocket not found

main.ts

import WebSocket from "@tauri-apps/plugin-websocket";

const ws = await WebSocket.connect("ws://157b-89-178-124-63.ngrok-free.app/ws");

I did everything according to the instructions https://github.com/tauri-apps/tauri-plugin-websocket/tree/v2

It doesn't work

FabianLars commented 11 months ago

This should mean that you're missing the rust part of the usage instructions from the readme.

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_websocket::init()) // <- This line!
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
DIMFLIX-OFFICIAL commented 11 months ago

This should mean that you're missing the rust part of the usage instructions from the readme.

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_websocket::init()) // <- This line!
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

I have this line. But I still have this error.

FabianLars commented 11 months ago

Hmm, can you double check if all the versions are on their latest v2 alpha version?

So for rust it's tauri tauri-build and tauri-plugin-websocket that has to be 2.0.0-alpha (or the concrete version) and then run cargo update in the src-tauri dir.

For the js packages it should be enough to re-run the install commands like npm install --save @tauri-apps/api @tauri-apps/plugin-websocket

P.S. i just tried it in a fresh create-tauri-app and there it works so hopefully we're just dealing with an outdated version here.

DIMFLIX-OFFICIAL commented 11 months ago

@FabianLars

image image image image

FabianLars commented 11 months ago

Ohhh, we're talking about mobile. Sorry, should have asked that. It could be that the websocket plugin doesn't support mobile yet but that should print different errors 🤔

I'll try it out in my app as soon as i can (have to set up my android env again though)

DIMFLIX-OFFICIAL commented 11 months ago

Ohhh, we're talking about mobile. Sorry, should have asked that. It could be that the websocket plugin doesn't support mobile yet but that should print different errors 🤔

I'll try it out in my app as soon as i can (have to set up my android env again though)

Yes, it's a mobile app.

RainyNight9 commented 6 days ago

I have the same problem, but I'm on desktop app.
https://tauri.app/plugin/websocket/ Follow this document.

image

image

I can't get the data in the code, but I can see the data in the console ws request? ?

image

image

useEffect(() => {
    let ws: WebSocket | null = null;

    const connectWebSocket = async () => {
      try {
        ws = await WebSocket.connect("ws://localhost:2900/ws");
        ws.addListener((msg) => {
          console.log("Received Message:", msg);
        });
        await ws.send("Hello World! 11111");
      } catch (error) {
        console.error("WebSocket failed:", error);
      }
    };

    connectWebSocket();

    return () => {
      ws?.disconnect();
    };
  }, []);
FabianLars commented 6 days ago

@RainyNight9 And you also registered it in rust like this? https://github.com/tauri-apps/plugins-workspace/issues/746#issuecomment-1819646642

RainyNight9 commented 3 days ago

image

@FabianLars Yes, registered.