UNPKG

@mdf.js/openc2

Version:

MMS - API - Observability

78 lines 2.8 kB
"use strict"; /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SocketIOAdapter = void 0; const crash_1 = require("@mdf.js/crash"); const socket_client_provider_1 = require("@mdf.js/socket-client-provider"); const Adapter_1 = require("../Adapter"); class SocketIOAdapter extends Adapter_1.Adapter { /** * Create a new OpenC2 adapter for Socket.IO * @param adapterOptions - Adapter configuration options * @param type - component type * @param options - Socket.IO client configuration options */ constructor(adapterOptions, type, options) { var _a; super(adapterOptions, type); this.provider = socket_client_provider_1.SocketIOClient.Factory.create({ config: { ...options, auth: { nodeId: adapterOptions.id, actuators: (_a = adapterOptions.actuators) !== null && _a !== void 0 ? _a : [], type, token: adapterOptions.token, }, }, name: adapterOptions.id, }); } /** Adapter health status */ get status() { return this.provider.status; } /** Component checks */ get checks() { return this.provider.checks; } /** Connect the OpenC2 Adapter to the underlayer transport system */ async start() { try { await this.provider.start(); } catch (rawError) { const error = crash_1.Crash.from(rawError); throw new crash_1.Crash(`Error performing the subscription to OpenC2 topics: ${error.message}`, error.uuid, { cause: error }); } } /** Connect the OpenC2 Adapter to the underlayer transport system */ async stop() { try { await this.provider.stop(); } catch (rawError) { const error = crash_1.Crash.from(rawError); throw new crash_1.Crash(`Error performing the unsubscription to OpenC2 topics: ${error.message}`, error.uuid, { cause: error }); } } /** Close the OpenC2 Adapter to the underlayer transport system */ async close() { try { await this.provider.close(); } catch (rawError) { const error = crash_1.Crash.from(rawError); throw new crash_1.Crash(`Error closing the OpenC2 adapter: ${error.message}`, error.uuid, { cause: error, }); } } } exports.SocketIOAdapter = SocketIOAdapter; //# sourceMappingURL=SocketIOAdapter.js.map