"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const timingCommands_1 = require("./Timing/timingCommands");
const handleFileSystemRequests_1 = require("./FileSystem/handleFileSystemRequests");
const handleHtmlSnapshotTakingRequests_1 = require("./Html/handleHtmlSnapshotTakingRequests");
const handleOfflineCacheRequests_1 = require("./Offline/Cache/handleOfflineCacheRequests");
const handleVideoRequests_1 = require("./Video/handleVideoRequests");
const handleOsdRequests_1 = require("./OSD/handleOsdRequests");
const handleApplicationRequests_1 = require("./Management/App/handleApplicationRequests");
const handlePowerRequests_1 = require("./Management/Power/handlePowerRequests");
const handleDisplayRequests_1 = require("./Display/handleDisplayRequests");
const consoleCommands_1 = require("./Console/consoleCommands");
const handleManagementRequests_1 = require("./Management/handleManagementRequests");
const handleScreenRequests_1 = require("./Management/Screen/handleScreenRequests");
const handleSecurityCommands_1 = require("./Management/Security/handleSecurityCommands");
const handleAudioRequests_1 = require("./Management/Audio/handleAudioRequests");
const handleRemoteControlRequests_1 = require("./Management/RemoteControl/handleRemoteControlRequests");
const handleDebugRequests_1 = require("./Management/Debug/handleDebugRequests");
const managementOsRequests_1 = require("./Management/Os/managementOsRequests");
const handleMonitoringRequests_1 = require("./handleMonitoringRequests");
const handleTimeCommands_1 = require("./Management/Time/handleTimeCommands");
const handleNativeCommands_1 = require("./NativeCommands/handleNativeCommands");
const handleManagementNetworkRequests_1 = require("./Management/Network/handleManagementNetworkRequests");
const handlePeerRecoveryRequests_1 = require("./Management/PeerRecovery/handlePeerRecoveryRequests");
const handleAutoRecoveryRequests_1 = require("./Management/AutoRecovery/handleAutoRecoveryRequests");
const enhancer_1 = require("../Util/Console/enhancer");
const handleDeviceInfoRequests_1 = require("./DeviceInfo/handleDeviceInfoRequests");
class Monitoring {
    frontApplet;
    /** @internal */
    constructor(frontApplet) {
        this.frontApplet = frontApplet;
        this.interceptConsoleLogging();
        void this.handleTimingLoaded();
        (0, handleMonitoringRequests_1.handleMonitoringRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleHtmlSnapshotTakingRequests_1.handleHtmlSnapshotTakingRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleOfflineCacheRequests_1.handleOfflineCacheRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleVideoRequests_1.handleVideoRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleFileSystemRequests_1.handleFileSystemRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleOsdRequests_1.handleOSDRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleApplicationRequests_1.handleManagementApplicationRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handlePowerRequests_1.handleManagementPowerRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleDisplayRequests_1.handleDisplayRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleManagementRequests_1.handleManagementRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleScreenRequests_1.handleManagementScreenRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleSecurityCommands_1.handleManagementSecurityRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleAudioRequests_1.handleManagementAudioRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleRemoteControlRequests_1.handleManagementRemoteControlRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleDebugRequests_1.handleManagementDebugRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, managementOsRequests_1.handleManagementOsRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleTimeCommands_1.handleManagementTimeCommands)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleNativeCommands_1.handleManagementNativeCommandsMdcRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleManagementNetworkRequests_1.handleManagementNetworkRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handlePeerRecoveryRequests_1.handleManagementPeerRecoveryRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleAutoRecoveryRequests_1.handleManagementAutoRecoveryRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
        (0, handleDeviceInfoRequests_1.handleDeviceInfoRequests)(this.onCommand.bind(this), this.dispatch.bind(this), this.frontApplet);
    }
    onCommand(listener) {
        this.frontApplet.command.onCommand((command) => {
            if (typeof this.frontApplet.config === 'object' && this.frontApplet.config.sosMonitoring) {
                listener(command);
            }
        });
    }
    async dispatch(command) {
        if (typeof this.frontApplet.config === 'object' && this.frontApplet.config.sosMonitoring) {
            await this.frontApplet.command.dispatch(command);
        }
    }
    async handleTimingLoaded() {
        await this.frontApplet.onReady();
        await this.dispatch({ type: timingCommands_1.TimingLoaded });
    }
    interceptConsoleLogging() {
        (0, enhancer_1.enhanceStandardConsoleLogging)((type, ...args) => {
            void this.dispatch({
                type: consoleCommands_1.ConsoleLogged,
                level: type,
                messages: args,
            });
        });
    }
}
exports.default = Monitoring;
//# sourceMappingURL=Monitoring.js.map