"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSocketConnection = void 0;
const socket_io_client_1 = require("socket.io-client");
const config_1 = require("../config");
const helpers_1 = require("../helpers");
function createSocketConnection({ user, env, socketType = 'notification', socketOptions, }) {
    const { autoConnect = true, reconnectionAttempts = 5, reconnectionDelay, reconnectionDelayMax, } = socketOptions || {};
    const pushWSUrl = config_1.API_BASE_URL[env];
    const transports = ['websocket'];
    let pushSocket = null;
    try {
        const userAddressInCAIP = socketType === 'chat'
            ? (0, helpers_1.walletToPCAIP10)(user)
            : (0, helpers_1.getCAIPAddress)(env, user, 'User');
        const query = socketType === 'notification'
            ? { address: userAddressInCAIP }
            : { mode: 'chat', did: userAddressInCAIP };
        pushSocket = (0, socket_io_client_1.io)(pushWSUrl, Object.assign(Object.assign({ transports,
            query,
            autoConnect,
            reconnectionAttempts }, (reconnectionDelay !== undefined && { reconnectionDelay })), (reconnectionDelayMax !== undefined && { reconnectionDelayMax })));
    }
    catch (e) {
        console.error('[PUSH-SDK] - Socket connection error: ', e);
    }
    return pushSocket;
}
exports.createSocketConnection = createSocketConnection;
//# sourceMappingURL=socketClient.js.map