"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSystemMessageOfType = exports.systemMessageFromSubscriber = void 0;
const protocol_1 = require("@logsn/protocol");
const rxjs_1 = require("rxjs");
// creating this to leverage rxjs tools to manage cold and hot subscriptions, shareReplay, etc.
const systemMessageFromSubscriber = (subscriber) => {
    return new rxjs_1.Observable((observer) => {
        const messageListener = (content, metadata) => {
            const message = protocol_1.SystemMessage.deserialize(content);
            observer.next({ message: message, metadata });
        };
        subscriber.subscribe(messageListener);
        return () => {
            subscriber.unsubscribe();
        };
    });
};
exports.systemMessageFromSubscriber = systemMessageFromSubscriber;
const isSystemMessageOfType = (type) => (systemMessage) => {
    return systemMessage.message.messageType === type;
};
exports.isSystemMessageOfType = isSystemMessageOfType;
//# sourceMappingURL=SystemMessageObservable.js.map