import {Interfaces} from "./Interfaces"; export class App { private clientsManager: Interfaces.ClientsManagerInterface; private apiConnector: Interfaces.ApiConnectorInterface; private conversationsManager: Interfaces.ConversationsManagerInterface; private logger: Interfaces.LoggerInterface; constructor(apiConnector: Interfaces.ApiConnectorInterface, clientsManager: Interfaces.ClientsManagerInterface, conversationsManager: Interfaces.ConversationsManagerInterface, logger: Interfaces.LoggerInterface, apiServer: Interfaces.ServerInterface, config: AppConfigInterface) { this.apiConnector = apiConnector; this.clientsManager = clientsManager; this.conversationsManager = conversationsManager; this.logger = logger; let httpServer = require('http').createServer(apiServer.processRequest.bind(apiServer)).listen(config.port, config.host); let socketIO = require('socket.io')(httpServer); socketIO.on('connection', (socket) => { socket.on('userConnect', (data) => { this.logger.debug(`Client connected`); this.clientsManager.add(socket, data, this.conversationsManager); }); }); this.logger.info(`Server started at ${config.host}:${config.port}`); this.logger.debug(`App started in debug mode`); } } export interface AppConfigInterface { host: string; port: number; mode: Interfaces.AppMode; }