How to connect socket.io into third party app

Hello All,

I want to connect my flutter mobile application with a frappe socket.io.

Does anyone have experience in this?

are you done with your problem? i have same this issue. my apps which with nodejs can’t connect to socket.

there is the code

import { io } from "socket.io-client";
import dotenv from "dotenv";
dotenv.config();

const socket = io(process.env.SITE_URL + "/" + process.env.SITE_NAME, {
    extraHeaders: {
        Authorization:
            "token " + process.env.API_KEY + ":" + process.env.API_SECRET,
    },
    auth: {
        token: "token " + process.env.API_KEY + ":" + process.env.API_SECRET,
    },
    withCredentials: true,
});

socket.on("connect", () => {
    console.log("Connected to the server", process.env.SITE_URL);
});

socket.on("event_msgprint", () => {
    console.log("trigered new message");
});

.env

SITE_URL="http://learn.localhost:9000"
SITE_NAME="learn.local"
API_SECRET="be0afb090465400"
API_KEY="d6bffffae2b47f1"

but client doesn’t connect to the server

i guess the problem is from authentication, but i don’t have idea to fix this. can anyone help me ?

Update:

I have connected to the server, but not success to listen any event

Code:

import { io } from "socket.io-client";
import dotenv from "dotenv";
dotenv.config();

const socket = io(process.env.SITE_URL + "/learn.local", {
    extraHeaders: {
        Authorization:
            "token " + process.env.API_KEY + ":" + process.env.API_SECRET,
        "x-frappe-site-name": "learn.local",
        origin: "http://learn.local:8000",
        cookie: "token=" + process.env.API_KEY + ":" + process.env.API_SECRET,
    },
    withCredentials: true,
    autoConnect: true,
    timeout: 2000,
});

socket.on("connect", () => {
    console.log("Connected to the server", process.env.SITE_URL);
});

socket.on("event_msgprint", () => {
    console.log("trigered new message");
});

socket.on("error", (d) => {
    console.log("have error in this connection", d);
});

socket.on("reconnect", (attemp) => {
    console.log("reconnected", attemp);
});
// console.log(process.env.API_KEY);
socket.on("connect_error", (error) => {
    console.log("connect_error", error);
});

socket.onAny((data) => {
    console.log(data);
});

socket.connect();