"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMockSocket = exports.resultMock = exports.bulkSocketMock = exports.secureChannelMock = exports.withSocketErrors = exports.socketErrorSubject = void 0;
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
exports.socketErrorSubject = new rxjs_1.Subject();
const withSocketErrors = (observable) => (0, rxjs_1.merge)(observable, exports.socketErrorSubject.pipe((0, operators_1.mergeMap)(e => (0, rxjs_1.throwError)(() => e))));
exports.withSocketErrors = withSocketErrors;
const pause = ms => (0, rxjs_1.interval)(ms).pipe((0, operators_1.take)(1), (0, operators_1.ignoreElements)());
const secureChannelMock = (managerGranted = false) => !managerGranted
    ? (0, rxjs_1.concat)(pause(500), (0, rxjs_1.of)({
        type: "device-permission-requested",
    }), pause(500), (0, rxjs_1.of)({
        type: "device-permission-granted",
    }), pause(500))
    : pause(1000);
exports.secureChannelMock = secureChannelMock;
const bulkSocketMock = (duration = 1000) => {
    const total = Math.floor((duration - 100) / 100);
    return (0, rxjs_1.interval)(100).pipe((0, operators_1.take)(total + 1), (0, operators_1.map)(index => ({
        type: "bulk-progress",
        progress: index / total,
        index,
        total,
    })));
};
exports.bulkSocketMock = bulkSocketMock;
const resultMock = (payload) => (0, rxjs_1.of)({
    type: "result",
    payload,
});
exports.resultMock = resultMock;
const createMockSocket = (...observables) => (0, exports.withSocketErrors)((0, rxjs_1.concat)(...observables));
exports.createMockSocket = createMockSocket;
//# sourceMappingURL=socket.mock.js.map