"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-nocheck
const react_native_1 = require("react-native");
'use strict';
const _InCallManager = require('react-native').NativeModules.InCallManager;
class InCallManager {
    constructor() {
        this.vibrate = false;
        this.audioUriMap = {
            ringtone: { _BUNDLE_: null, _DEFAULT_: null },
            ringback: { _BUNDLE_: null, _DEFAULT_: null },
            busytone: { _BUNDLE_: null, _DEFAULT_: null },
        };
    }
    start(setup) {
        setup = (setup === undefined) ? {} : setup;
        const auto = setup.auto !== false;
        const media = (setup.media === 'video') ? 'video' : 'audio';
        const ringback = (setup.ringback) ? (typeof setup.ringback === 'string') ? setup.ringback : '' : '';
        _InCallManager.start(media, auto, ringback);
    }
    stop(setup) {
        setup = (setup === undefined) ? {} : setup;
        const busytone = (setup.busytone) ? (typeof setup.busytone === 'string') ? setup.busytone : '' : '';
        _InCallManager.stop(busytone);
    }
    getIsWiredHeadsetPluggedIn() {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                let isPluggedIn = yield _InCallManager.getIsWiredHeadsetPluggedIn();
                return { isWiredHeadsetPluggedIn: isPluggedIn };
            }
            catch (e) {
                throw new Error('Incall Manager Error getting wired headset');
            }
        });
    }
    setKeepScreenOn(enable) {
        enable = (enable === true);
        _InCallManager.setKeepScreenOn(enable);
    }
    setSpeakerphoneOn(enable) {
        enable = (enable === true);
        _InCallManager.setSpeakerphoneOn(enable);
    }
    setForceSpeakerphoneOn(_flag) {
        const flag = (typeof _flag === 'boolean') ? (_flag) ? 1 : -1 : 0;
        _InCallManager.setForceSpeakerphoneOn(flag);
    }
    setMicrophoneMute(enable) {
        enable = (enable === true);
        _InCallManager.setMicrophoneMute(enable);
    }
    getAudioUri(audioType, fileType) {
        return __awaiter(this, void 0, void 0, function* () {
            if (typeof this.audioUriMap[audioType] === 'undefined') {
                return null;
            }
            if (this.audioUriMap[audioType][fileType]) {
                return this.audioUriMap[audioType][fileType];
            }
            try {
                const result = yield _InCallManager.getAudioUriJS(audioType, fileType);
                if (typeof result === 'string' && result.length > 0) {
                    this.audioUriMap[audioType][fileType] = result;
                    return result;
                }
                return null;
            }
            catch (err) {
                return null;
            }
        });
    }
    chooseAudioRoute(route) {
        return __awaiter(this, void 0, void 0, function* () {
            const result = yield _InCallManager.chooseAudioRoute(route);
            return result;
        });
    }
    requestAudioFocus() {
        return __awaiter(this, void 0, void 0, function* () {
            if (react_native_1.Platform.OS === 'android') {
                return yield _InCallManager.requestAudioFocusJS();
            }
            else {
                console.log("ios doesn't support requestAudioFocus()");
            }
        });
    }
    abandonAudioFocus() {
        return __awaiter(this, void 0, void 0, function* () {
            if (react_native_1.Platform.OS === 'android') {
                return yield _InCallManager.abandonAudioFocusJS();
            }
            else {
                console.log("ios doesn't support requestAudioFocus()");
            }
        });
    }
}
exports.default = new InCallManager();
//# sourceMappingURL=RNInCallManager.js.map