import { ConnectionState, } from '@iotize/tap/protocol/api';
import { Subject } from 'rxjs';
import { debug } from './debug';
var TAG = 'ComProtocol';
var AbstractComProtocol = /** @class */ (function () {
    function AbstractComProtocol() {
        this.connectionState = 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 == ConnectionState.CONNECTED;
    };
    AbstractComProtocol.prototype.setConnectionState = function (connectionState) {
        debug(TAG, '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 Subject();
        }
        return this._connectionStateChange;
    };
    return AbstractComProtocol;
}());
export { AbstractComProtocol };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWJzdHJhY3QtY29tLXByb3RvY29sLmpzIiwic291cmNlUm9vdCI6Im5nOi8vQGlvdGl6ZS90YXAvcHJvdG9jb2wvY29yZS8iLCJzb3VyY2VzIjpbImxpYi9hYnN0cmFjdC1jb20tcHJvdG9jb2wudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUtILGVBQWUsR0FFbEIsTUFBTSwwQkFBMEIsQ0FBQztBQUNsQyxPQUFPLEVBQWMsT0FBTyxFQUFFLE1BQU0sTUFBT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