"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const socket_io_client_1 = __importDefault(require("socket.io-client"));
class SocketIOProjectLinker {
    constructor() {
        this._config = {};
        this._config$ = new rxjs_1.Subject();
        this._projectInfo = new rxjs_1.Subject();
        this.socket = socket_io_client_1.default('http://localhost:8888');
        this.socket.on('connect', function () {
            console.log('connected!');
        });
        this.socket.on('event', function (data) {
            console.log('Socket event', data);
        });
        this.socket.on('disconnect', function () {
            console.log('disconnect');
        });
        this.socket.on('config', (data) => {
            console.info('New config', data);
            this._config = data;
            this._config$.next(this._config);
        });
        this.socket.on('project', (data) => {
            console.info('New config', data);
            this._projectInfo.next(data);
        });
    }
    hasConfig() {
        return this._config != undefined;
    }
    get projectInfoChange() {
        this.socket.emit('getProjectInfo');
        return this._projectInfo;
    }
    sync() {
        this.socket.emit('getConfig', 'all');
        this.socket.emit('getProjectInfo', 'all');
    }
    get config() {
        return this._config;
    }
    get configChange() {
        return this._config$.asObservable();
    }
    setAppConfig(data) {
        this._config.appConfig = data;
    }
    applyConfig() {
        console.info('setConfig', this._config);
        this.socket.emit('setConfig', this._config);
    }
    generate() {
        this.socket.emit('schematic', 'generate');
    }
    serve(port = 4202) {
        this.socket.emit('serve', {
            port: port
        });
    }
}
exports.SocketIOProjectLinker = SocketIOProjectLinker;
//# sourceMappingURL=socketio-project-linker copy.js.map