D
D
Denis Shcherbina2021-11-08 10:30:42
Angular
Denis Shcherbina, 2021-11-08 10:30:42

"reconnect" doesn't work in socket io, why?

on the server: "socket.io": "^4.3.1",
on the client (application): "socket.io-client": "^4.3.2"
on the client (angular admin): "ngx-socket-io ": "^4.1.0",

Server + application works fine.
The server + admin panel works, but after the connection is lost, the events stop working, reconnect, reconnection, etc. - does not happen (client code) angular:

import { Socket } from 'ngx-socket-io'

export class UsersOnlineComponent implements OnInit {
constructor(private socket: Socket) {}

activation_sockets() {
    this.socket.connect();
    this.socket.emit('new-user', id);
    this.socket.on("reconnect", (attempt) => {
      console.log('Соединение восстановлено')
    });
    this.socket.on("reconnect_error", (error) => {
      console.log('Пытаюсь восстановить соединение')
    })
}
}

Everything works until the connection is lost. If this happens, no reconnection occurs. I set it to true in app.module, but it doesn't work:
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const config: SocketIoConfig = { url: 'http://localhost:4600/', options: {
  reconnection: true
} };

What's wrong? how to make reconnect work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Shcherbina, 2021-11-09
@Denis_maker

It was not possible to resolve this moment. I had to downgrade to a lower version. Combination that works:
on the server: "socket.io": "^2.4.1",
on the client (app): "socket.io-client": "^2.4.0"
on the client (angular admin): " ngx-socket-io": "^3.2.0",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question