text: const io = require("socket.io");
  const SessionService = require("../services/SessionService");
  let socketServer;
  module.exports = {
    init: async ({ server, log }) => {
      socketServer = io(server);
      const wrap = (middleware) => (socket, next) =>
        middleware(socket.request, {}, next);
      socketServer.use(wrap(SessionService.getSessionMiddleware()));
  
      socketServer.use((socket, next) => {
        const { user } = socket.request.session;
        if (!user) {
          next(new Error("User not authenticated"));
        }
        socket.user = user;
        next();
      });
      socketServer.on("connection", (socket) => {
        const { _id } = socket.user;
        log.info(`New User connected: id: ${_id}`);
        socket.join(_id);
        socket.emit("joined");
  
        socket.on("join-room", (room) => {
          socket.join(room);
          log.info(`${socket.user._id} has joined room : ${room}`);
  
          socket.emit("join-room-ack");
        });
      });
    },
  
    getServerSocket: () => {
      if (!socketServer) throw new Error("Socket io server not initialized");
  
      return socketServer;
    },
  };
  