import { socketConnect, socketEvent, socketAuthPayload } from '@/socket/app';
import { loggerBackground } from '@/plugins/logger';

const socketAppConnect = async () => {
  const socketApp = socketConnect();
  let socketId = socketApp.id;

  socketApp.on(socketEvent.connect, () => {
    socketId = socketApp.id;

    loggerBackground.log({
      msg: 'SOCKET_APP_CONNECT',
      id: socketId,
    });

    socketApp.emit(socketEvent.auth, socketAuthPayload());
  });

  return socketApp;
};

export default socketAppConnect;
