index.js 1.07 KB
const MODULE_NAME = 'KOMODO_SDK-PUSH-TRX.CLIENT';

const config = require('komodo-sdk/config');
const logger = require('tektrans-logger');
const uniqid = require('uniqid');
const connect = require('./connect');

const debugAllGatewaysFromConfig = global.SDK_PUSH_TRX_DEBUG_ALL_GATEWAYS_FROM_CONFIG
    || false;

const connectAll = (xidFromCaller) => {
    const xid = xidFromCaller || uniqid();

    const gateways = config.gateways
        .filter((gateway) => !gateway.disabled
            && gateway.name
            && gateway.url
            && (gateway.url.indexOf('ws://') !== 0)
            && ((new URL(gateway.url) || {}).protocol === 'ws:'));

    if (debugAllGatewaysFromConfig) {
        logger.verbose(`${MODULE_NAME} 80C7AAD6: Dumping config.gateways`, {
            xid,
            gateways: config.gateways,
        });
    }

    logger.verbose(`${MODULE_NAME} 79B5FEB5: Connecting to all gateways`, {
        xid,
        gatewayNames: gateways.map((gateway) => gateway.name),
    });

    gateways.forEach((gateway) => {
        connect(xid, gateway);
    });
};

connectAll();