Angular does not stop loading when using socket.io

Discussão em 'Angular' iniciado por Long, Dezembro 3, 2024.

  1. Long

    Long Guest

    I use socket.io-client in 1 service connect to python and i dont't know why if i connect to the server, my page will loading and do not expose any element. I used postmant to test, it still normal

    I tried config proxy by create "proxy.config.json" file and run with "ng serve --proxy-config proxy.config.json"

    I tried remove or add transport (do not use long-polling but it had same result) It still log "Connected to Websocket" in Vscode website still loading. Somebody helps me, i'm really hopeless

    This is my code:

    `

    private socket: any;

    private readonly socketUrl = 'http://localhost:5000';

    private messageServerSubject: Subject<{status: string, road: string}> = new
    Subject<{status: string, road: string}>();
    public messageServer$ = this.messageServerSubject.asObservable();

    constructor() {
    this.connect();
    }

    private connect(): void {
    this.socket = io(this.socketUrl, {transports: ['websocket'], reconnection: false});

    this.socket.on('connect', () => {
    console.log('Connected to WebSocket');
    });

    this.socket.on('connect_error', (error: any) => {
    console.error('Connection error:', error);
    });

    this.socket.on('image_processed', (responseMessage: { status: string, road: string }) => {
    console.log(responseMessage);
    this.messageServerSubject.next(responseMessage);
    });


    }`

    This is my proxy config:

    {
    "/socket.io": {
    "target": "http://localhost:5000",
    "ws": true,
    "secure": false,
    "changeOrigin": true,
    "logLevel": "debug"
    }


    }

    Continue reading...

Compartilhe esta Página