Each attempt to connect needs a new socket. So, your code:
const socket = new SockJS('http://localhost:8080/ws');
console.log("socket -> ", socket);
const stompClient = new Client({
webSocketFactory: () => socket,
Needs to change to
const stompClient = new Client({
webSocketFactory: () => new SockJS('http://localhost:8080/ws'),
Basically, the factory method must return a new socket when invoked.
See https://stomp-js.github.io/guide/stompjs/rx-stomp/using-stomp-with-sockjs.html