"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var api_1 = require("../../protocol/api");
var rxjs_1 = require("rxjs");
var logger_1 = require("../../logger");
var logger = logger_1.default('ComProtocol');
var AbstractComProtocol = /** @class */ (function () {
    function AbstractComProtocol() {
        this.connectionState = api_1.ConnectionState.DISCONNECTED;
        this._options = {
            connect: {
                timeout: 1000
            },
            disconnect: {
                timeout: 1000
            },
            send: {
                timeout: 500
            }
        };
    }
    Object.defineProperty(AbstractComProtocol.prototype, "options", {
        get: function () {
            return this._options;
        },
        set: function (options) {
            this._options = options;
        },
        enumerable: true,
        configurable: true
    });
    AbstractComProtocol.prototype.getConnectionState = function () {
        return this.connectionState;
    };
    AbstractComProtocol.prototype.isConnected = function () {
        return this.connectionState == api_1.ConnectionState.CONNECTED;
    };
    AbstractComProtocol.prototype.setConnectionState = function (connectionState) {
        logger.debug('setConnectionState', connectionState, 'Old: ', this.connectionState);
        var event = {
            newState: connectionState,
            oldState: this.connectionState
        };
        this.connectionState = connectionState;
        if (this._connectionStateChange) {
            this._connectionStateChange.next(event);
        }
        return this;
    };
    /**
     * Must be implemented in childs
     */
    AbstractComProtocol.prototype.receiveStream = function () {
        throw new Error("Method not implemented.");
    };
    AbstractComProtocol.prototype.onConnectionStateChange = function () {
        if (!this._connectionStateChange) {
            this._connectionStateChange = new rxjs_1.Subject();
        }
        return this._connectionStateChange;
    };
    return AbstractComProtocol;
}());
exports.AbstractComProtocol = AbstractComProtocol;
