TikTok.apk(点击下载) / LiveHostNetwork.java


package com.ss.android.ugc.aweme.live.livehostimpl;

import X.AbstractC35351DuW;
import X.AbstractC35352DuX;
import X.AbstractC35853E6g;
import X.AnonymousClass0WE;
import X.AnonymousClass0ZI;
import X.AnonymousClass2W5;
import X.C11210cg;
import X.C12030e0;
import X.C20920sL;
import X.C29021Cx;
import X.C35345DuQ;
import X.C35846E5z;
import X.C35851E6e;
import X.C35852E6f;
import X.C524024v;
import X.C524124w;
import X.E18;
import X.E1C;
import X.E1D;
import X.EnumC35349DuU;
import X.F3T;
import X.FK4;
import X.FKK;
import android.content.Context;
import android.net.Uri;
import com.bytedance.android.livesdkapi.host.IHostContext;
import com.bytedance.android.livesdkapi.host.IHostNetwork;
import com.bytedance.android.livesdkapi.ws.LiveWsMessage;
import com.bytedance.common.wschannel.model.WsChannelMsg;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.ugc.aweme.network.RetrofitFactory;
import com.bytedance.retrofit2.mime.TypedByteArray;
import com.bytedance.retrofit2.mime.TypedInput;
import com.bytedance.retrofit2.mime.TypedOutput;
import com.ss.android.common.applog.AppLog;
import com.ss.android.deviceregister.DeviceRegisterManager;
import com.ss.android.ugc.aweme.live.ILiveInnerService;
import com.ss.android.ugc.aweme.ttlive.ILiveApi;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

public class LiveHostNetwork implements IHostNetwork {
    public volatile ILiveApi LIZ;

    /* renamed from: com.ss.android.ugc.aweme.live.livehostimpl.LiveHostNetwork$5  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass5 {
        public static final /* synthetic */ int[] LIZ;

        /* JADX WARNING: Can't wrap try/catch for region: R(10:0|1|2|3|4|5|6|7|8|(3:9|10|12)) */
        /* JADX WARNING: Can't wrap try/catch for region: R(12:0|1|2|3|4|5|6|7|8|9|10|12) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0018 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x0023 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x002e */
        /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0039 */
        static {
            Covode.recordClassIndex(80853);
            int[] iArr = new int[FKK.values().length];
            LIZ = iArr;
            iArr[FKK.CONNECTION_UNKNOWN.ordinal()] = 1;
            LIZ[FKK.CONNECTING.ordinal()] = 2;
            LIZ[FKK.CONNECT_FAILED.ordinal()] = 3;
            LIZ[FKK.CONNECT_CLOSED.ordinal()] = 4;
            try {
                LIZ[FKK.CONNECTED.ordinal()] = 5;
            } catch (NoSuchFieldError unused) {
            }
        }
    }

    static {
        Covode.recordClassIndex(80848);
    }

    private ILiveApi LIZ() {
        if (this.LIZ == null) {
            this.LIZ = (ILiveApi) RetrofitFactory.LIZ().LIZIZ("https://api-va.tiktokv.com").LIZJ().LIZ(ILiveApi.class);
        }
        return this.LIZ;
    }

    public static Map<String, String> LIZ(List<E18> list) {
        HashMap hashMap = new HashMap();
        if (list != null) {
            for (E18 e18 : list) {
                hashMap.put(e18.getName(), e18.getValue());
            }
        }
        return hashMap;
    }

    private void LIZ(String str) {
        if (C20920sL.LIZLLL()) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("url", str);
                jSONObject.putOpt("source", "livesdk");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            C29021Cx.LIZ("ttlive_minor_mode_live", 1, jSONObject);
        }
    }

    public static byte[] LIZ(InputStream inputStream) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        if (inputStream != null) {
            byte[] bArr = new byte[4096];
            while (true) {
                int read = inputStream.read(bArr);
                if (read == -1) {
                    break;
                }
                byteArrayOutputStream.write(bArr, 0, read);
            }
        }
        return byteArrayOutputStream.toByteArray();
    }

    private int LIZIZ() {
        Long.valueOf(AnonymousClass0WE.LJJI.LJII()).intValue();
        int i2 = 0;
        try {
            String[] split = AnonymousClass0WE.LJJI.LJIIIIZZ().split("\\.");
            int length = split.length;
            int i3 = 0;
            while (i2 < length) {
                try {
                    i3 = Integer.parseInt(split[i2]) + (i3 * 100);
                    i2++;
                } catch (Throwable unused) {
                    i2 = i3;
                    return i2;
                }
            }
            return i3;
        } catch (Throwable unused2) {
            return i2;
        }
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public AnonymousClass2W5<E1D> downloadFile(boolean z, int i2, String str, List<E18> list, Object obj) {
        AnonymousClass0ZI<TypedInput> downloadFile = LIZ().downloadFile(z, i2, str, LIZ(list), obj);
        LIZ(str);
        return new E1C(downloadFile);
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public AnonymousClass2W5<E1D> get(String str, List<E18> list, Object obj) {
        AnonymousClass0ZI<TypedInput> r1 = LIZ().get(str, LIZ(list), obj);
        LIZ(str);
        return new E1C(r1);
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public Map<String, String> getCommonParams() {
        HashMap hashMap = new HashMap();
        C11210cg.LIZIZ(hashMap, false);
        return hashMap;
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public String getHostDomain() {
        return ((ILiveInnerService) C524024v.LIZ(ILiveInnerService.class)).LIZ();
    }

    @Override // X.AbstractC524424z
    public void onInit() {
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public AnonymousClass2W5<E1D> post(String str, List<E18> list, String str2, byte[] bArr, Object obj) {
        AnonymousClass0ZI<TypedInput> post = LIZ().post(str, new TypedByteArray(str2, bArr, new String[0]), LIZ(list), obj);
        LIZ(str);
        return new E1C(post);
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public AbstractC35352DuX registerWsChannel(Context context, String str, Map<String, String> map, final AbstractC35351DuW duW) {
        map.put("sid", AppLog.getSessionKey());
        try {
            Uri.Builder buildUpon = Uri.parse(str).buildUpon();
            for (String str2 : map.keySet()) {
                buildUpon.appendQueryParameter(str2, map.get(str2));
            }
            str = buildUpon.build().toString();
        } catch (Throwable unused) {
        }
        ArrayList arrayList = new ArrayList();
        arrayList.add(str);
        HashMap hashMap = new HashMap();
        hashMap.put("ttnet_ignore_offline", "1");
        C35851E6e LIZ2 = C35851E6e.LIZ(10001);
        LIZ2.LJI = "e1bd35ec9db7b8d846de66ed140b1ad9";
        LIZ2.LJ = 9;
        LIZ2.LIZLLL = AnonymousClass0WE.LJIILJJIL;
        LIZ2.LJFF = LIZIZ();
        LIZ2.LJII = DeviceRegisterManager.getDeviceId();
        LIZ2.LJIIIIZZ = DeviceRegisterManager.getInstallId();
        C35851E6e LIZ3 = LIZ2.LIZ(arrayList).LIZ(hashMap);
        LIZ3.LIZIZ.putAll(new HashMap<String, String>((IHostContext) C524124w.LIZ(IHostContext.class)) {
            /* class com.ss.android.ugc.aweme.live.livehostimpl.LiveHostNetwork.AnonymousClass2 */
            public final /* synthetic */ IHostContext LIZ;

            static {
                Covode.recordClassIndex(80850);
            }

            {
                this.LIZ = r5;
                put("X-Tt-Token", C12030e0.LIZIZ());
                put("sdk-version", "2340");
                if (r5.isBoe()) {
                    put("x-use-boe", "1");
                    put("x-tt-env", r5.getBoeLane());
                } else if (r5.isPpe()) {
                    put("x-use-ppe", "1");
                    put("x-tt-env", r5.getPpeLane());
                }
            }
        });
        final AbstractC35853E6g LIZ4 = FK4.LIZ(context, LIZ3.LIZ(), new F3T() {
            /* class com.ss.android.ugc.aweme.live.livehostimpl.LiveHostNetwork.AnonymousClass3 */

            static {
                Covode.recordClassIndex(80851);
            }

            @Override // X.F3T
            public final void LIZ(C35846E5z e5z, JSONObject jSONObject) {
                if (e5z != null && e5z.LIZJ == 10001) {
                    EnumC35349DuU duU = EnumC35349DuU.CONNECTION_UNKNOWN;
                    int i2 = AnonymousClass5.LIZ[e5z.LIZIZ.ordinal()];
                    if (i2 == 1) {
                        duU = EnumC35349DuU.CONNECTION_UNKNOWN;
                    } else if (i2 == 2) {
                        duU = EnumC35349DuU.CONNECTING;
                    } else if (i2 == 3) {
                        duU = EnumC35349DuU.CONNECT_FAILED;
                    } else if (i2 == 4) {
                        duU = EnumC35349DuU.CONNECT_CLOSED;
                    } else if (i2 == 5) {
                        duU = EnumC35349DuU.CONNECTED;
                    }
                    duW.LIZ(duU, jSONObject);
                }
            }

            @Override // X.F3T
            public final void LIZ(WsChannelMsg wsChannelMsg) {
                if (wsChannelMsg != null && wsChannelMsg.LJIIL == 10001) {
                    C35345DuQ duQ = new C35345DuQ(wsChannelMsg.LJIIL);
                    duQ.LIZIZ = wsChannelMsg.LJ;
                    duQ.LIZLLL = wsChannelMsg.LJI;
                    duQ.LJII = wsChannelMsg.LIZLLL;
                    duQ.LIZJ = wsChannelMsg.LJFF;
                    duQ.LJFF = wsChannelMsg.LJIIIZ;
                    duQ.LJI = wsChannelMsg.LJIIIIZZ;
                    duQ.LJ = wsChannelMsg.LIZ();
                    duQ.LJIIIIZZ = wsChannelMsg.LJIIJJI;
                    if (wsChannelMsg.LJII != null) {
                        for (WsChannelMsg.MsgHeader msgHeader : wsChannelMsg.LJII) {
                            duQ.LIZ.put(msgHeader.LIZ, msgHeader.LIZIZ);
                        }
                    }
                    duW.LIZ(duQ.LIZIZ());
                }
            }
        });
        return new AbstractC35352DuX() {
            /* class com.ss.android.ugc.aweme.live.livehostimpl.LiveHostNetwork.AnonymousClass4 */

            static {
                Covode.recordClassIndex(80852);
            }

            @Override // X.AbstractC35352DuX
            public final void LIZ(LiveWsMessage liveWsMessage) {
                C35852E6f e6f = new C35852E6f(liveWsMessage.LJIIJ);
                e6f.LIZ = liveWsMessage.LIZJ;
                e6f.LIZJ = liveWsMessage.LJ;
                e6f.LJI = liveWsMessage.LIZIZ;
                e6f.LIZIZ = liveWsMessage.LIZLLL;
                e6f.LJ = liveWsMessage.LJII;
                e6f.LJFF = liveWsMessage.LJI;
                e6f.LIZLLL = liveWsMessage.LIZ();
                e6f.LJII = liveWsMessage.LJIIIZ;
                if (liveWsMessage.LJFF != null) {
                    for (LiveWsMessage.MsgHeader msgHeader : liveWsMessage.LJFF) {
                        e6f.LIZ(msgHeader.LIZ, msgHeader.LIZIZ);
                    }
                }
                LIZ4.LIZ(e6f.LIZIZ(), null);
            }

            @Override // X.AbstractC35352DuX
            public final boolean LIZ() {
                return LIZ4.LIZJ();
            }

            @Override // X.AbstractC35352DuX
            public final void LIZIZ() {
                LIZ4.LIZIZ();
            }
        };
    }

    @Override // com.bytedance.android.livesdkapi.host.IHostNetwork
    public AnonymousClass2W5<E1D> uploadFile(int i2, String str, List<E18> list, final String str2, final byte[] bArr, final long j, final String str3) {
        AnonymousClass0ZI<TypedInput> postMultiPart = LIZ().postMultiPart(i2, str, LIZ(list), new TypedOutput() {
            /* class com.ss.android.ugc.aweme.live.livehostimpl.LiveHostNetwork.AnonymousClass1 */

            static {
                Covode.recordClassIndex(80849);
            }

            @Override // com.bytedance.retrofit2.mime.TypedOutput
            public final String fileName() {
                return null;
            }

            @Override // com.bytedance.retrofit2.mime.TypedOutput
            public final long length() {
                return j;
            }

            @Override // com.bytedance.retrofit2.mime.TypedOutput
            public final String md5Stub() {
                return str3;
            }

            @Override // com.bytedance.retrofit2.mime.TypedOutput
            public final String mimeType() {
                return str2;
            }

            @Override // com.bytedance.retrofit2.mime.TypedOutput
            public final void writeTo(OutputStream outputStream) {
                outputStream.write(bArr);
            }
        });
        LIZ(str);
        return new E1C(postMultiPart);
    }
}