plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

Uncaught plugin websocket not found

Open DIMFLIX opened this issue 2 years ago • 6 comments

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

DIMFLIX avatar Nov 20 '23 17:11 DIMFLIX

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");
}

FabianLars avatar Nov 20 '23 19:11 FabianLars

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.

DIMFLIX avatar Nov 20 '23 19:11 DIMFLIX

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.

FabianLars avatar Nov 20 '23 19:11 FabianLars

@FabianLars

image image image image

DIMFLIX avatar Nov 21 '23 11:11 DIMFLIX

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)

FabianLars avatar Nov 21 '23 12:11 FabianLars

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.

DIMFLIX avatar Nov 21 '23 12:11 DIMFLIX

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();
    };
  }, []);

RainyNight9 avatar Nov 06 '24 07:11 RainyNight9

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

FabianLars avatar Nov 06 '24 10:11 FabianLars

image

@FabianLars Yes, registered.

RainyNight9 avatar Nov 09 '24 03:11 RainyNight9