import { inject_remote } from "$/client/components/Source.svelte";

let raw_socket;

export const configure_socket = async () => {
  await inject_remote(document, "/js/socket.io.min.js");
}


export const connect_socket = (reconnection=false) => {
  if(raw_socket === undefined) {
    raw_socket = io({ reconnection });
  }

  return raw_socket;
}

export const reconnect_socket = () => {
  if(raw_socket !== undefined) {
    raw_socket.disconnect();
    raw_socket.connect();
  } else {
    connect_socket();
  }

  return raw_socket;
}
