"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initAppClient = void 0;
const middlewares_1 = require("@/middlewares");
const enum_1 = require("@/@types/enum");
const app_client_manager_1 = require("./app-client-manager");
const iwdp_app_client_1 = require("./iwdp-app-client");
const tunnel_app_client_1 = require("./tunnel-app-client");
const ws_app_client_1 = require("./ws-app-client");
const initAppClient = () => {
    const initFn = {
        ["hippy" /* Hippy */]: initHippyAppClient,
        ["voltron" /* Voltron */]: initVoltronAppClient,
        ["TDF" /* TDF */]: initTDFAppClient,
        ["TDFCore" /* TDFCore */]: initTdfCoreAppClient,
    }[global.debugAppArgv.env];
    initFn();
};
exports.initAppClient = initAppClient;
// 终端自己实现的调试协议域名
const customDomains = [
    'Page',
    'DOM',
    'CSS',
    'Overlay',
    'TDFInspector',
    'TDFPerformance',
    'TDFMemory',
    'TDFLog',
    'TDFRuntime',
];
/**
 * hippy
 *  - 安卓走 ws 通道
 *  - iOS 走 IWDP + ws 通道
 */
const initHippyAppClient = () => {
    app_client_manager_1.appClientManager.clear();
    app_client_manager_1.appClientManager.addAndroidAppClientOption({
        useAllDomain: true,
        middleWareManager: middlewares_1.androidMiddleWareManager,
        Ctor: ws_app_client_1.WSAppClient,
        platform: enum_1.DevicePlatform.Android,
    });
    app_client_manager_1.appClientManager.addIOSAppClientOption({
        useAllDomain: false,
        ignoreDomains: customDomains,
        middleWareManager: middlewares_1.iOSMiddleWareManager,
        Ctor: iwdp_app_client_1.IWDPAppClient,
        platform: enum_1.DevicePlatform.IOS,
    });
    app_client_manager_1.appClientManager.addIOSAppClientOption({
        useAllDomain: false,
        acceptDomains: customDomains,
        middleWareManager: middlewares_1.iOSMiddleWareManager,
        Ctor: ws_app_client_1.WSAppClient,
        platform: enum_1.DevicePlatform.IOS,
    });
};
/**
 * voltron，暂时与 hippy 一致
 */
const initVoltronAppClient = () => {
    app_client_manager_1.appClientManager.clear();
    initHippyAppClient();
};
/**
 * TDF
 *  - 安卓
 *    - tunnel 通道
 *  - ios
 *    - 自实现协议走 tunnel 通道
 *    - jsc 实现的协议走 IWDP 通道
 */
const initTDFAppClient = () => {
    app_client_manager_1.appClientManager.clear();
    app_client_manager_1.appClientManager.addAndroidAppClientOption({
        useAllDomain: true,
        middleWareManager: middlewares_1.androidMiddleWareManager,
        Ctor: tunnel_app_client_1.TunnelAppClient,
        platform: enum_1.DevicePlatform.Android,
    });
    app_client_manager_1.appClientManager.addIOSAppClientOption({
        useAllDomain: false,
        ignoreDomains: customDomains,
        middleWareManager: middlewares_1.iOSMiddleWareManager,
        Ctor: iwdp_app_client_1.IWDPAppClient,
        platform: enum_1.DevicePlatform.IOS,
    });
    app_client_manager_1.appClientManager.addIOSAppClientOption({
        useAllDomain: false,
        acceptDomains: customDomains,
        middleWareManager: middlewares_1.iOSMiddleWareManager,
        Ctor: tunnel_app_client_1.TunnelAppClient,
        platform: enum_1.DevicePlatform.IOS,
    });
};
/**
 * TDFCore
 *  - 安卓：tunnel 通道
 *  - ios：tunnel 通道
 */
const initTdfCoreAppClient = () => {
    app_client_manager_1.appClientManager.clear();
    app_client_manager_1.appClientManager.addAndroidAppClientOption({
        useAllDomain: true,
        middleWareManager: middlewares_1.androidMiddleWareManager,
        Ctor: tunnel_app_client_1.TunnelAppClient,
        platform: enum_1.DevicePlatform.Android,
    });
    app_client_manager_1.appClientManager.addIOSAppClientOption({
        useAllDomain: true,
        middleWareManager: middlewares_1.iOSMiddleWareManager,
        Ctor: tunnel_app_client_1.TunnelAppClient,
        platform: enum_1.DevicePlatform.IOS,
    });
};
