"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const DeviceSignals_1 = require("../enums/DeviceSignals");
class VirtualDevice extends events_1.EventEmitter {
    constructor() {
        super();
        this.addListener(DeviceSignals_1.DeviceSignal.onDeviceStartedSignal, (args) => this.onDeviceStarted(args));
        this.addListener(DeviceSignals_1.DeviceSignal.onDeviceKilledSignal, (args) => this.onDeviceKilled(args));
        this.addListener(DeviceSignals_1.DeviceSignal.onDeviceErrorSignal, (args) => this.onDeviceError(args));
        this.addListener(DeviceSignals_1.DeviceSignal.onDeviceAttachedSignal, (args) => this.onAttachToDevice(args));
    }
    get device() {
        return this._device;
    }
    subscribeForEvents() {
        this._deviceProcess.stdin.on("data", (data) => this.stdin(data));
        this._deviceProcess.stdout.on("data", (data) => this.stdout(data));
        this._deviceProcess.stderr.on("data", (data) => {
            const dataToLog = data.toString();
            console.log("stderr: ", dataToLog);
        });
        this._deviceProcess.once("uncaughtException", (data) => {
            const dataToLog = data.toString();
            console.log("error: ", dataToLog);
            this.emit(DeviceSignals_1.DeviceSignal.onDeviceKilledSignal, this._device);
        });
        this._deviceProcess.once("close" || "exit" || "disconnect", (data) => {
            const dataToLog = data.toString();
            console.log("close: ", dataToLog);
            this.emit(DeviceSignals_1.DeviceSignal.onDeviceKilledSignal, this.device);
        });
        this._deviceProcess.once("error", (data) => {
            const dataToLog = data.toString();
            console.log("error: ", dataToLog);
            this.emit(DeviceSignals_1.DeviceSignal.onDeviceKilledSignal, this.device);
        });
    }
}
exports.VirtualDevice = VirtualDevice;
//# sourceMappingURL=virtual-device.js.map