"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FxdkDataService = exports.SingleEventEmitter = void 0;
var core_1 = require("@theia/core");
var inversify_1 = require("inversify");
var SingleEventEmitter = /** @class */ (function () {
    function SingleEventEmitter() {
        this.listeners = new Set();
    }
    SingleEventEmitter.prototype.on = function (listener) {
        var _this = this;
        this.listeners.add(listener);
        return core_1.Disposable.create(function () { return _this.listeners.delete(listener); });
    };
    SingleEventEmitter.prototype.emit = function (data) {
        this.listeners.forEach(function (listener) { return listener(data); });
    };
    return SingleEventEmitter;
}());
exports.SingleEventEmitter = SingleEventEmitter;
var FxdkDataService = /** @class */ (function () {
    function FxdkDataService() {
        this.data = {};
        this.bufferedServerOutput = '';
        this.structuredServerMessages = [];
        this.bufferedServerOutputChanged = new SingleEventEmitter();
        this.structuredServerMessageReceivedEvent = new SingleEventEmitter();
        this.clearAllServerOutputsEvent = new SingleEventEmitter();
        this.structuredGameMessages = [];
        this.structuredGameMessageReceivedEvent = new SingleEventEmitter();
        this.clearGameOutputEvent = new SingleEventEmitter();
    }
    FxdkDataService.prototype.onBufferedServerOutputChanged = function (cb) {
        return this.bufferedServerOutputChanged.on(cb);
    };
    FxdkDataService.prototype.onStructuredServerMessageReceived = function (cb) {
        return this.structuredServerMessageReceivedEvent.on(cb);
    };
    FxdkDataService.prototype.onClearAllServerOutputs = function (cb) {
        return this.clearAllServerOutputsEvent.on(cb);
    };
    FxdkDataService.prototype.getBufferedServerOutput = function () {
        return this.bufferedServerOutput;
    };
    FxdkDataService.prototype.getStructuredServerMessages = function () {
        return this.structuredServerMessages;
    };
    FxdkDataService.prototype.clearAllServerOutputs = function () {
        this.bufferedServerOutput = '';
        this.structuredServerMessages = [];
        this.clearAllServerOutputsEvent.emit();
    };
    FxdkDataService.prototype.setBufferedServerOutput = function (output) {
        this.bufferedServerOutput = output;
        this.bufferedServerOutputChanged.emit(this.bufferedServerOutput);
    };
    FxdkDataService.prototype.receiveStructuredServerMessage = function (message) {
        this.structuredServerMessages.push(message);
        this.structuredServerMessageReceivedEvent.emit(message);
    };
    FxdkDataService.prototype.onStructuredGameMessageReceived = function (cb) {
        return this.structuredGameMessageReceivedEvent.on(cb);
    };
    FxdkDataService.prototype.onClearGameOutput = function (cb) {
        return this.clearGameOutputEvent.on(cb);
    };
    FxdkDataService.prototype.getStructuredGameMessage = function () {
        return this.structuredGameMessages;
    };
    FxdkDataService.prototype.receiveStructuredGameMessage = function (message) {
        this.structuredGameMessages.push(message);
        this.structuredGameMessageReceivedEvent.emit(message);
    };
    FxdkDataService.prototype.clearGameOutput = function () {
        this.structuredGameMessages = [];
        this.clearGameOutputEvent.emit();
    };
    FxdkDataService.prototype.sendMessageToShell = function (type, data) {
        window.parent.postMessage({ type: type, data: data }, '*');
    };
    FxdkDataService = __decorate([
        inversify_1.injectable()
    ], FxdkDataService);
    return FxdkDataService;
}());
exports.FxdkDataService = FxdkDataService;
//# sourceMappingURL=fxdk-data-service.js.map