import type { Socket } from "socket.io-client"

let activeSocket: Socket | null = null

export const setActiveSocket = (socket: Socket) => {
  activeSocket = socket
}

export const getActiveSocket = (): Socket | null => activeSocket

export const isActiveSocket = (socket: Socket): boolean =>
  socket === activeSocket

export const teardownSocket = (socket: Socket) => {
  socket.removeAllListeners()
  if (socket.connected) {
    socket.disconnect()
  }
}
