package com.bytedance.android.live.liveinteract.multicohost.service;

import X.2K3;
import X.2Pr;
import X.2lV;
import X.2sG;
import X.6iy;
import X.7Vf;
import X.7Vj;
import X.7Vk;
import X.7Vl;
import X.7Vm;
import X.7Vn;
import X.8dp;
import X.9HM;
import X.AnonymousClass12L;
import X.AnonymousClass2AJ;
import X.AnonymousClass2AX;
import X.AnonymousClass2BE;
import X.AnonymousClass2BG;
import X.AnonymousClass2BH;
import X.AnonymousClass2C7;
import X.AnonymousClass2CC;
import X.C09630aP;
import X.C10000b0;
import X.C11100cm;
import X.C14280hu;
import X.C14380i4;
import X.C14430i9;
import X.C14450iB;
import X.C14750if;
import X.C14760ig;
import X.C14770ih;
import X.C16590ld;
import X.C16630lh;
import X.C18000nu;
import X.C18010nv;
import X.C18030nx;
import X.C18050nz;
import X.C18230oH;
import X.C18250oJ;
import X.C18270oL;
import X.C18410oZ;
import X.C18420oa;
import X.C18430ob;
import X.C18440oc;
import X.C18460oe;
import X.C18470of;
import X.C18480og;
import X.C18490oh;
import X.C18500oi;
import X.C18510oj;
import X.C18520ok;
import X.C18530ol;
import X.C18540om;
import X.C18550on;
import X.C18560oo;
import X.C20660sC;
import X.C24170xr;
import X.C31851Ol;
import X.C33211Tr;
import X.C33221Ts;
import X.C33231Tt;
import X.C33241Tu;
import X.C33251Tv;
import X.C33261Tw;
import X.C33271Tx;
import X.C33281Ty;
import X.C42451mF;
import X.C42461mG;
import X.C49701xw;
import X.C53682Ak;
import X.CwZ;
import X.Cwu;
import X.Fv2;
import X.Fz8;
import X.G9W;
import X.GQb;
import X.GiY;
import X.IOW;
import X.K0R;
import X.Lea;
import X.Lel;
import X.Ls0;
import X.LsD;
import X.M12;
import X.MLi;
import X.MMF;
import X.MOo;
import X.MOw;
import X.MOx;
import X.MVA;
import X.TC2;
import X.TC7;
import X.TCR;
import X.TCS;
import X.TCa;
import X.TCh;
import X.TD3;
import X.TD4;
import X.TD5;
import X.TD6;
import X.TDA;
import X.TDz;
import X.TE5;
import X.TEK;
import X.TFh;
import X.TFi;
import X.TFj;
import X.TFk;
import X.TFl;
import X.TFm;
import X.TFn;
import X.TFo;
import X.TFq;
import X.TFr;
import X.TH0;
import X.THo;
import X.THu;
import X.TI4;
import X.TI5;
import X.TIB;
import X.TIX;
import X.TIZ;
import X.TIo;
import X.TIt;
import X.TIv;
import android.content.Context;
import android.graphics.Rect;
import android.os.SystemClock;
import android.text.TextUtils;
import com.bytedance.android.live.base.model.ImageModel;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.livesdk.chatroom.model.interact.CohostListUser;
import com.bytedance.android.livesdk.comp.api.linkcore.api.ILinkMicService;
import com.bytedance.android.livesdk.livesetting.linkmic.MtCoHostReplyTimeOutSetting;
import com.bytedance.android.livesdk.model.message.LinkMessage;
import com.bytedance.android.livesdk.model.message.linker.invite_message.InviterRivalExtra;
import com.bytedance.android.livesdk.model.message.linker.invite_message.LinkerInviteContent;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.depend.model.live.StreamUrl;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import kotlin.h.b.n;

public class MultiCoHostServiceImpl implements IMultiCoHostService, TC7, TIt, TH0 {
    public static final C18420oa Companion = new C18420oa((byte) 0);
    public final ArrayList<C18230oH> coHostUserList = new ArrayList<>();
    public final ConcurrentHashMap<Long, C18230oH> coHostUserMap = new ConcurrentHashMap<>();
    public Cwu<Integer, Integer> containerSize = new Cwu<>(0, 0);
    public DataChannel dataChannel;
    public boolean isAnchor;
    public boolean isAttached;
    public boolean isDestroyChannel;
    public boolean isSDKEnabled;
    public C31851Ol mDataHolder;
    public TIo mLinkMicManager;
    public Map<Class<?>, List<LsD<THu, C20660sC<?>, 2Pr>>> mLinkMicMessageHandlers = new HashMap();
    public ILinkMicService mLinkMicService;
    public THu mLinkMicSession;
    public TIB mLiveConfig;
    public Room room;
    public C18010nv state = C18010nv.None;
    public final C18050nz timeOutManager = new C18050nz();

    static {
        Covode.recordClassIndex(7709);
    }

    public void onFirstFrameTimerTimeout(long j) {
    }

    public void onInit() {
    }

    public void onRemoteMute(boolean z, String str, boolean z2) {
        M12.LIZ(str);
    }

    public void onRoomMsgSentResult(long j, int i) {
    }

    public void onSendRtcRoomMessage(THu tHu, String str) {
        M12.LIZ(tHu, str);
    }

    public void onStartJoinRtcChannel() {
    }

    public void onTalkStateUpdated(String[] strArr, boolean[] zArr, int[] iArr) {
    }

    public String onTriggerSei() {
        return null;
    }

    public C18010nv getCoHostState() {
        return this.state;
    }

    public THu getLinkSession() {
        return this.mLinkMicSession;
    }

    public boolean isAttached() {
        return this.isAttached;
    }

    public void refreshUserList() {
        C09630aP.LIZ(4, "MultiCoHostService", "refreshUserList");
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            tHu.updateUserList();
        }
    }

    private final void resetToFullScreen() {
        C09630aP.LIZ(4, "MultiCoHostService", "resetToFullScreen");
        C14380i4 r3 = new C14380i4(-1, -1, 0, true);
        DataChannel dataChannel2 = this.dataChannel;
        if (dataChannel2 != null) {
            dataChannel2.LIZJ(AnonymousClass2AJ.class, r3);
        }
    }

    public void closeMultiGuest() {
        DataChannel dataChannel2;
        if (this.isAnchor && (dataChannel2 = this.dataChannel) != null) {
            dataChannel2.LIZJ(AnonymousClass2CC.class, true);
        }
    }

    public void recoverMultiGuest() {
        DataChannel dataChannel2;
        if (this.isAnchor && (dataChannel2 = this.dataChannel) != null) {
            dataChannel2.LIZJ(AnonymousClass2CC.class, false);
        }
    }

    public void closeWithModeSwitch() {
        C09630aP.LIZ(4, "MultiCoHostService", "closeWithModeSwitch, state = " + this.state);
        if (this.state != C18010nv.Received || refuseInvited(this.mLinkMicSession, "closeWithModeSwitch").isEmpty()) {
            destroySession("closeWithModeSwitch");
        }
    }

    public boolean isEnableSDK() {
        boolean z;
        if (this.isAttached) {
            z = this.isSDKEnabled;
        } else {
            z = false;
        }
        C09630aP.LIZ(4, "MultiCoHostService", "isEnableSDK, isAttached = " + this.isAttached + ", enabled = " + z);
        return z;
    }

    public void detach() {
        C09630aP.LIZ(4, "MultiCoHostService", "detach, isAttached = " + this.isAttached);
        if (this.isAttached) {
            TIo tIo = this.mLinkMicManager;
            if (tIo == null) {
                n.LIZ("");
            }
            tIo.LIZIZ(this);
            TIo tIo2 = this.mLinkMicManager;
            if (tIo2 == null) {
                n.LIZ("");
            }
            tIo2.LIZ();
            destroySession("detach");
            this.isAttached = false;
            setEnableSDK(false, "detach");
            this.dataChannel = null;
            this.mDataHolder = null;
            this.mLinkMicMessageHandlers.clear();
            this.room = null;
        }
    }

    public List<C18230oH> getCoHostLinkedUserList() {
        if (this.mLinkMicSession == null) {
            return Lel.INSTANCE;
        }
        if (this.room == null) {
            return Lel.INSTANCE;
        }
        ArrayList arrayList = new ArrayList();
        Room room2 = this.room;
        if (room2 == null) {
            n.LIZIZ();
        }
        long ownerUserId = room2.getOwnerUserId();
        C18230oH r0 = this.coHostUserMap.get(Long.valueOf(ownerUserId));
        if (r0 != null) {
            arrayList.add(r0);
        }
        Collection<C18230oH> values = this.coHostUserMap.values();
        n.LIZIZ(values, "");
        ArrayList arrayList2 = new ArrayList();
        for (T next : values) {
            C18230oH r1 = (C18230oH) next;
            if (!r1.LIZ(Long.valueOf(ownerUserId)) && r1.LJFF == C18270oL.LINKED) {
                arrayList2.add(next);
            }
        }
        arrayList.addAll(Lea.LIZ(arrayList2, new C18430ob()));
        return arrayList;
    }

    public List<C18230oH> getCoHostUserList() {
        THu tHu = this.mLinkMicSession;
        if (tHu == null) {
            return Lel.INSTANCE;
        }
        TCR userManager = tHu.userManager();
        if (userManager != null) {
            userManager.LIZJ();
        }
        if (this.room == null) {
            return Lel.INSTANCE;
        }
        this.coHostUserList.clear();
        Room room2 = this.room;
        if (room2 == null) {
            n.LIZIZ();
        }
        long ownerUserId = room2.getOwnerUserId();
        C18230oH r1 = this.coHostUserMap.get(Long.valueOf(ownerUserId));
        if (r1 != null) {
            this.coHostUserList.add(r1);
        }
        Collection<C18230oH> values = this.coHostUserMap.values();
        n.LIZIZ(values, "");
        ArrayList arrayList = new ArrayList();
        for (T next : values) {
            C18230oH r12 = (C18230oH) next;
            if (!r12.LIZ(Long.valueOf(ownerUserId)) && r12.LJFF == C18270oL.LINKED) {
                arrayList.add(next);
            }
        }
        this.coHostUserList.addAll(Lea.LIZ(arrayList, new C18440oc()));
        ArrayList<C18230oH> arrayList2 = this.coHostUserList;
        Collection<C18230oH> values2 = this.coHostUserMap.values();
        n.LIZIZ(values2, "");
        ArrayList arrayList3 = new ArrayList();
        for (T next2 : values2) {
            C18230oH r13 = (C18230oH) next2;
            if (!r13.LIZ(Long.valueOf(ownerUserId)) && r13.LJFF != C18270oL.LINKED) {
                arrayList3.add(next2);
            }
        }
        arrayList2.addAll(arrayList3);
        return this.coHostUserList;
    }

    public void onLayoutWindowUpdate(TCa tCa) {
        M12.LIZ(tCa);
        M12.LIZ(tCa);
    }

    public void onPreLayoutSwitch(TCa tCa) {
        M12.LIZ(tCa);
        M12.LIZ(tCa);
    }

    public void onReceivedSei(String str) {
        M12.LIZ(str);
        C18410oZ.LIZIZ(str);
    }

    public void onTurnOffEngine(String str) {
        M12.LIZ(str);
        C18410oZ.LIZJ(str);
    }

    public void onSei(String str) {
        TIo tIo = this.mLinkMicManager;
        if (tIo == null) {
            n.LIZ("");
        }
        tIo.LIZ(str);
    }

    public void onSeiBattleIdUpdated(long j) {
        DataChannel dataChannel2 = this.dataChannel;
        if (dataChannel2 != null) {
            dataChannel2.LIZIZ(AnonymousClass2C7.class, String.valueOf(j));
        }
    }

    public C18230oH getCoHostUser(long j) {
        if (this.mLinkMicSession == null) {
            return null;
        }
        return this.coHostUserMap.get(Long.valueOf(j));
    }

    public long getCoHostUserCountDown(long j) {
        Long l = this.timeOutManager.LIZ.get(Long.valueOf(j));
        if (l != null) {
            return l.longValue();
        }
        return 0;
    }

    public void onApplyTimerCancel(long j) {
        if (this.mLinkMicSession != null) {
            long j2 = j;
            C09630aP.LIZ(4, "MultiCoHostService", "onApplyTimerCancel, uid = ".concat(String.valueOf(j2)));
            this.timeOutManager.LIZ(j2, 0, C18030nx.SDK_APPLY);
        }
    }

    public void onInviteTimerCancel(long j) {
        if (this.mLinkMicSession != null) {
            long j2 = j;
            C09630aP.LIZ(4, "MultiCoHostService", "onInviteTimerCancel, uid = ".concat(String.valueOf(j2)));
            this.timeOutManager.LIZ(j2, 0, C18030nx.SDK_INVITE);
        }
    }

    public void onNeedJoinChannel(TFq tFq) {
        M12.LIZ(tFq);
        C09630aP.LIZ(4, "MultiCoHostService", "onNeedJoinChannel");
        C31851Ol r1 = this.mDataHolder;
        if (r1 != null) {
            r1.LIZ(true);
        }
        closeMultiGuest();
        tFq.LIZ();
    }

    public void onStartPushStream(THu tHu) {
        DataChannel dataChannel2;
        M12.LIZ(tHu);
        C18410oZ.LIZJ(tHu);
        if (this.isAnchor && (dataChannel2 = this.dataChannel) != null) {
            dataChannel2.LIZJ(AnonymousClass2AX.class, new GQb(7));
        }
    }

    private final C18230oH addCurrentUser(long j) {
        C18250oJ r0;
        User owner;
        C18230oH coHostUser = getCoHostUser(C18470of.LIZ());
        if (coHostUser == null) {
            coHostUser = ensureCoHostUser(C18470of.LIZ());
            Room room2 = this.room;
            if (room2 == null || (owner = room2.getOwner()) == null) {
                r0 = null;
            } else {
                r0 = C18470of.LIZ(owner);
            }
            coHostUser.LIZ = r0;
            coHostUser.LIZIZ = j;
        }
        return coHostUser;
    }

    private final C18230oH ensureCoHostUser(long j) {
        C18250oJ r0;
        User owner;
        C18230oH coHostUser = getCoHostUser(j);
        if (coHostUser == null) {
            coHostUser = new C18230oH(j, (byte) 0);
            if (C18470of.LIZ() == j) {
                Room room2 = this.room;
                if (room2 == null || (owner = room2.getOwner()) == null) {
                    r0 = null;
                } else {
                    r0 = C18470of.LIZ(owner);
                }
                coHostUser.LIZ = r0;
            }
        }
        this.coHostUserMap.put(Long.valueOf(j), coHostUser);
        return coHostUser;
    }

    private final void removeUser(long j) {
        C09630aP.LIZ(4, "MultiCoHostService", "removeUser, uid = ".concat(String.valueOf(j)));
        C18230oH r1 = this.coHostUserMap.get(Long.valueOf(j));
        if (r1 != null) {
            r1.LIZ(C18270oL.IDLE);
        }
        this.coHostUserMap.remove(Long.valueOf(j));
        this.timeOutManager.LIZ(j);
    }

    private final boolean tryRefuseInvite(LinkerInviteContent linkerInviteContent) {
        int i;
        GiY LIZ = GiY.LIZ();
        n.LIZIZ(LIZ, "");
        if (LIZ.LIZLLL) {
            i = 11;
        } else {
            C31851Ol r0 = this.mDataHolder;
            if (r0 == null || !r0.LJLJJL) {
                return false;
            }
            i = 13;
        }
        replyInvite(new K0R(linkerInviteContent.LIZIZ, linkerInviteContent.LIZ, i), (TIZ<TD6>) null);
        return true;
    }

    public C18230oH getCoHostUserWithLinkMicId(String str) {
        Object obj;
        M12.LIZ(str);
        if (this.mLinkMicSession == null) {
            return null;
        }
        Iterator it = 2lV.LJFF(this.coHostUserMap).iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            }
            obj = it.next();
            if (TextUtils.equals(((C18230oH) ((Cwu) obj).getSecond()).LJIIJ, str)) {
                break;
            }
        }
        Cwu cwu = (Cwu) obj;
        if (cwu != null) {
            return (C18230oH) cwu.getSecond();
        }
        return null;
    }

    public void onApplyTimerTimeout(long j) {
        if (this.mLinkMicSession != null) {
            long j2 = j;
            C42451mF.LIZ.LIZ().LJ(j2);
            C09630aP.LIZ(4, "MultiCoHostService", "onApplyTimerTimeout, uid = ".concat(String.valueOf(j2)));
            this.timeOutManager.LIZ(j2, 0, C18030nx.SDK_APPLY);
            tryDestroySession(j2);
        }
    }

    public void onInviteTimerTimeout(long j) {
        if (this.mLinkMicSession != null) {
            long j2 = j;
            C09630aP.LIZ(4, "MultiCoHostService", "onInviteTimerTimeout, uid = ".concat(String.valueOf(j2)));
            C42451mF.LIZ.LIZ().LIZIZ(j2);
            this.timeOutManager.LIZ(j2, 0, C18030nx.SDK_INVITE);
            tryDestroySession(j2);
        }
    }

    public void onSessionCreate(THu tHu) {
        M12.LIZ(tHu);
        C09630aP.LIZ(4, "MultiCoHostService", "onSessionCreate, session scene = " + tHu.scene());
        if (tHu.scene() == 2) {
            ensureSession("onSessionCreate");
        }
    }

    public void onSessionDestroy(THu tHu) {
        M12.LIZ(tHu);
        C09630aP.LIZ(4, "MultiCoHostService", "onSessionDestroy, session scene = " + tHu.scene());
        if (tHu.scene() == 2) {
            destroySession("onSessionDestroy");
        }
    }

    public void cancelAll(boolean z) {
        int i;
        C09630aP.LIZ(4, "MultiCoHostService", "cancelAll");
        if (z) {
            i = 2131828432;
        } else {
            i = 2131828427;
        }
        Fz8.LIZ(C10000b0.LJ(), i);
        for (Map.Entry next : this.coHostUserMap.entrySet()) {
            C09630aP.LIZ(4, "MultiCoHostService", "cancelAll, user = " + next.getValue());
            if (((C18230oH) next.getValue()).LIZ()) {
                this.timeOutManager.LIZ(((Number) next.getKey()).longValue(), 0, C18030nx.OTHER);
                this.timeOutManager.LIZ(((C18230oH) next.getValue()).LIZIZ, 0, C18030nx.OTHER);
            }
        }
        destroySession("cancelAll");
    }

    public void onContainerOffsetYDidUpdate(float f) {
        TCS layoutManager;
        TCa LIZJ;
        Rect playerRange;
        C09630aP.LIZ(4, "MultiCoHostService", "onContainerOffsetYDidUpdate offsetY:".concat(String.valueOf(f)));
        THu linkSession = getLinkSession();
        if (linkSession != null && (layoutManager = linkSession.layoutManager()) != null && (LIZJ = layoutManager.LIZJ()) != null && (playerRange = LIZJ.getPlayerRange()) != null) {
            C14380i4 r4 = new C14380i4(playerRange.width(), playerRange.height(), playerRange.top + ((int) f), false);
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                dataChannel2.LIZJ(AnonymousClass2AJ.class, r4);
            }
        }
    }

    public final boolean tryDestroySession(long j) {
        Integer num;
        C09630aP.LIZ(4, "MultiCoHostService", "tryDestroySession, uid = ".concat(String.valueOf(j)));
        THu tHu = this.mLinkMicSession;
        boolean z = false;
        if (tHu == null) {
            return false;
        }
        List LIZIZ = tHu.userManager().LIZIZ();
        Integer num2 = null;
        if (LIZIZ != null) {
            num = Integer.valueOf(LIZIZ.size());
        } else {
            num = null;
        }
        int intValue = num.intValue();
        THu tHu2 = this.mLinkMicSession;
        if (tHu2 == null) {
            n.LIZIZ();
        }
        List LIZJ = tHu2.userManager().LIZJ();
        if (LIZJ != null) {
            num2 = Integer.valueOf(LIZJ.size());
        }
        if (intValue + num2.intValue() <= 0) {
            z = true;
        }
        removeUser(j);
        C09630aP.LIZ(4, "MultiCoHostService", "tryDestroySession, needDestroy = ".concat(String.valueOf(z)));
        if (z) {
            destroySession("tryDestroySession");
        }
        return z;
    }

    private final C14430i9 buildCoHostInviteEvent(MVA mva) {
        Object obj;
        Object obj2;
        String str;
        Object obj3;
        int i;
        List<String> list;
        String str2;
        User user;
        ImageModel avatarThumb;
        User user2;
        MVA mva2 = mva;
        Map map = mva2.LJI;
        Map<String, String> map2 = null;
        if (map != null) {
            obj = map.get("check_perception_center");
        } else {
            obj = null;
        }
        if (!(obj instanceof Boolean)) {
            obj = null;
        }
        if (!n.LIZ(obj, true)) {
            return null;
        }
        String valueOf = String.valueOf(mva2.LIZIZ);
        Map map3 = mva2.LJI;
        if (map3 != null) {
            obj2 = map3.get("sec_to_user_id");
        } else {
            obj2 = null;
        }
        if (!(obj2 instanceof String)) {
            obj2 = null;
        }
        String str3 = (String) obj2;
        String str4 = "";
        if (str3 == null) {
            str3 = str4;
        }
        String valueOf2 = String.valueOf(mva2.LIZ);
        C31851Ol r0 = this.mDataHolder;
        if (r0 == null || (user2 = r0.LJJLIIIJJI) == null || (str = user2.getUsername()) == null) {
            str = str4;
        }
        C14760ig r4 = C14770ih.Companion;
        Map map4 = mva2.LJI;
        if (map4 != null) {
            obj3 = map4.get("source_type");
        } else {
            obj3 = null;
        }
        if (!(obj3 instanceof Integer)) {
            obj3 = null;
        }
        Integer num = (Integer) obj3;
        if (num != null) {
            i = num.intValue();
        } else {
            i = 0;
        }
        C14770ih LIZ = r4.LIZ(i);
        C31851Ol r02 = this.mDataHolder;
        if (r02 == null || (user = r02.LJJLIIIJJI) == null || (avatarThumb = user.getAvatarThumb()) == null || (list = avatarThumb.mUrls) == null) {
            list = Lel.INSTANCE;
        }
        C31851Ol r03 = this.mDataHolder;
        if (r03 != null) {
            map2 = r03.LJLJLLL;
        }
        C31851Ol r04 = this.mDataHolder;
        if (!(r04 == null || (str2 = r04.LJLLJ) == null)) {
            str4 = str2;
        }
        C14450iB r05 = r6;
        C14450iB r6 = new C14450iB(valueOf, str3, valueOf2, str, LIZ, (List) list, (Map) map2, str4, false, true, 64);
        return new C14430i9(r05);
    }

    private final THu ensureSession(String str) {
        Integer num;
        Long l;
        StringBuilder sb = new StringBuilder("ensureSession, source = ");
        sb.append(str);
        sb.append(" mLinkMicSession = ");
        THu tHu = this.mLinkMicSession;
        Integer num2 = null;
        if (tHu != null) {
            num = Integer.valueOf(tHu.hashCode());
        } else {
            num = null;
        }
        sb.append(num);
        C09630aP.LIZ(4, "MultiCoHostService", sb.toString());
        THu tHu2 = this.mLinkMicSession;
        if (tHu2 != null) {
            return tHu2;
        }
        TIo tIo = this.mLinkMicManager;
        if (tIo == null) {
            n.LIZ("");
        }
        C31851Ol r0 = this.mDataHolder;
        if (r0 != null) {
            l = Long.valueOf(r0.LJ);
        } else {
            l = null;
        }
        THu LIZ = tIo.LIZ(2, String.valueOf(l));
        this.mLinkMicSession = LIZ;
        if (LIZ == null) {
            n.LIZIZ();
        }
        TIv rtcManager = LIZ.rtcManager();
        TIB tib = this.mLiveConfig;
        if (tib == null) {
            n.LIZ("");
        }
        rtcManager.LIZ(tib);
        THu tHu3 = this.mLinkMicSession;
        if (tHu3 == null) {
            n.LIZIZ();
        }
        tHu3.addLinkMicEventListener(this);
        THu tHu4 = this.mLinkMicSession;
        if (tHu4 == null) {
            n.LIZIZ();
        }
        tHu4.addTimeoutListener(this);
        THu tHu5 = this.mLinkMicSession;
        if (tHu5 == null) {
            n.LIZIZ();
        }
        tHu5.layoutManager().LIZ(this);
        StringBuilder sb2 = new StringBuilder("ensureSession, mLinkMicSession = ");
        THu tHu6 = this.mLinkMicSession;
        if (tHu6 != null) {
            num2 = Integer.valueOf(tHu6.hashCode());
        }
        sb2.append(num2);
        sb2.append(" register listener finished");
        C09630aP.LIZ(4, "MultiCoHostService", sb2.toString());
        THu tHu7 = this.mLinkMicSession;
        if (tHu7 == null) {
            n.LIZIZ();
        }
        return tHu7;
    }

    private final boolean tryRefuseApply(TFk tFk) {
        boolean z;
        int i;
        int i2;
        int i3;
        long j;
        TCR userManager;
        List LIZ;
        TCR userManager2;
        List LIZIZ;
        if (C16590ld.LIZ.LIZJ() == C16630lh.NORMAL && C16590ld.LIZIZ.LIZJ() == C16630lh.NORMAL) {
            z = false;
        } else {
            z = true;
        }
        THu tHu = this.mLinkMicSession;
        if (tHu == null || (userManager2 = tHu.userManager()) == null || (LIZIZ = userManager2.LIZIZ()) == null) {
            i = 0;
        } else {
            i = LIZIZ.size();
        }
        THu tHu2 = this.mLinkMicSession;
        if (tHu2 == null || (userManager = tHu2.userManager()) == null || (LIZ = userManager.LIZ()) == null) {
            i2 = 0;
        } else {
            i2 = LIZ.size();
        }
        if (i + i2 < 4 && !z) {
            return false;
        }
        TEK tek = tFk.LIZ;
        if (z) {
            i3 = 9;
        } else {
            i3 = 2;
        }
        Long l = tek.LIZ;
        long j2 = 0;
        if (l != null) {
            j = l.longValue();
        } else {
            j = 0;
        }
        Long l2 = tek.LIZIZ;
        if (l2 != null) {
            j2 = l2.longValue();
        }
        permitApply(new TI5(j, j2, (String) null, String.valueOf(tek.LIZLLL), i3, (Map) null, 100), (TIZ<TD5>) null);
        return true;
    }

    public final void destroySession(String str) {
        ArrayList<Long> arrayList;
        ArrayList<Long> arrayList2;
        TCS layoutManager;
        C09630aP.LIZ(4, "MultiCoHostService", "destroySession, source = " + str + "  mLinkMicSession = " + this.mLinkMicSession);
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            dispatchMessage(tHu, new C18530ol(str));
            THu tHu2 = this.mLinkMicSession;
            if (tHu2 != null) {
                tHu2.removeLinkMicEventListener(this);
            }
            THu tHu3 = this.mLinkMicSession;
            if (!(tHu3 == null || (layoutManager = tHu3.layoutManager()) == null)) {
                layoutManager.LIZIZ(this);
            }
            THu tHu4 = this.mLinkMicSession;
            if (tHu4 != null) {
                tHu4.dispose();
            }
            THu tHu5 = this.mLinkMicSession;
            if (tHu5 != null) {
                tHu5.removeTimeoutListener(this);
            }
            this.mLinkMicSession = null;
            this.timeOutManager.LIZ();
            if (this.coHostUserMap.size() > 0) {
                C31851Ol r0 = this.mDataHolder;
                if (!(r0 == null || (arrayList2 = r0.LJLLILLLL) == null)) {
                    arrayList2.clear();
                }
                C31851Ol r02 = this.mDataHolder;
                if (!(r02 == null || (arrayList = r02.LJLLILLLL) == null)) {
                    ConcurrentHashMap<Long, C18230oH> concurrentHashMap = this.coHostUserMap;
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    for (Map.Entry next : concurrentHashMap.entrySet()) {
                        if (((C18230oH) next.getValue()).LIZIZ()) {
                            linkedHashMap.put(next.getKey(), next.getValue());
                        }
                    }
                    ArrayList arrayList3 = new ArrayList(linkedHashMap.size());
                    for (Map.Entry key : linkedHashMap.entrySet()) {
                        arrayList3.add(key.getKey());
                    }
                    arrayList.addAll(arrayList3);
                }
            }
            this.coHostUserMap.clear();
            this.coHostUserList.clear();
            updateState(C18010nv.None, true);
            C31851Ol r1 = this.mDataHolder;
            if (r1 != null) {
                r1.LJ("destroySession");
            }
        }
    }

    private final C14430i9 buildCoHostInviteEvent(TI4 ti4) {
        Object obj;
        Object obj2;
        String str;
        Object obj3;
        int i;
        List<String> list;
        String str2;
        User user;
        ImageModel avatarThumb;
        User user2;
        TI4 ti42 = ti4;
        Map map = ti42.LJI;
        Map<String, String> map2 = null;
        if (map != null) {
            obj = map.get("check_perception_center");
        } else {
            obj = null;
        }
        if (!(obj instanceof Boolean)) {
            obj = null;
        }
        if (!n.LIZ(obj, true)) {
            return null;
        }
        String valueOf = String.valueOf(ti42.LIZIZ);
        Map map3 = ti42.LJI;
        if (map3 != null) {
            obj2 = map3.get("sec_to_user_id");
        } else {
            obj2 = null;
        }
        if (!(obj2 instanceof String)) {
            obj2 = null;
        }
        String str3 = (String) obj2;
        String str4 = "";
        if (str3 == null) {
            str3 = str4;
        }
        String valueOf2 = String.valueOf(ti42.LIZ);
        C31851Ol r0 = this.mDataHolder;
        if (r0 == null || (user2 = r0.LJJLIIIJJI) == null || (str = user2.getUsername()) == null) {
            str = str4;
        }
        C14760ig r4 = C14770ih.Companion;
        Map map4 = ti42.LJI;
        if (map4 != null) {
            obj3 = map4.get("invite_type");
        } else {
            obj3 = null;
        }
        if (!(obj3 instanceof Integer)) {
            obj3 = null;
        }
        Integer num = (Integer) obj3;
        if (num != null) {
            i = num.intValue();
        } else {
            i = 0;
        }
        C14770ih LIZ = r4.LIZ(i);
        C31851Ol r02 = this.mDataHolder;
        if (r02 == null || (user = r02.LJJLIIIJJI) == null || (avatarThumb = user.getAvatarThumb()) == null || (list = avatarThumb.mUrls) == null) {
            list = Lel.INSTANCE;
        }
        C31851Ol r03 = this.mDataHolder;
        if (r03 != null) {
            map2 = r03.LJLJLLL;
        }
        C31851Ol r04 = this.mDataHolder;
        if (!(r04 == null || (str2 = r04.LJLLJ) == null)) {
            str4 = str2;
        }
        C14450iB r05 = r6;
        C14450iB r6 = new C14450iB(valueOf, str3, valueOf2, str, LIZ, (List) list, (Map) map2, str4, false, true, 64);
        return new C14430i9(r05);
    }

    public void onFirstRemoteAudio(THu tHu, TEK tek) {
        M12.LIZ(tHu, tek);
        C18410oZ.LIZ(tHu, tek);
    }

    public void onFirstRemoteVideoFrame(THu tHu, TEK tek) {
        M12.LIZ(tHu, tek);
        C18410oZ.LIZIZ(tHu, tek);
    }

    public void onJoinChannelMessageReceived(THu tHu, TFh tFh) {
        M12.LIZ(tHu, tFh);
        C18410oZ.LIZ(tHu, tFh);
    }

    public void onJoinDirectMessageReceived(THu tHu, TFi tFi) {
        M12.LIZ(tHu, tFi);
        C18410oZ.LIZ(tHu, tFi);
    }

    public void onKickOutMessageReceived(THu tHu, TDA tda) {
        M12.LIZ(tHu, tda);
        C18410oZ.LIZ(tHu, tda);
    }

    public void onRtcError(THu tHu, TE5 te5) {
        M12.LIZ(tHu, te5);
        C18410oZ.LIZ(tHu, te5);
    }

    public void onRtcInit(THu tHu, TIB tib) {
        M12.LIZ(tHu);
        C18410oZ.LIZIZ(tHu);
    }

    public void onRtcStartResult(THu tHu, IOW iow) {
        M12.LIZ(tHu, iow);
        C18410oZ.LIZ(tHu, iow);
    }

    public void kickOut(MLi mLi, TIZ<7Vf> tiz) {
        M12.LIZ(mLi);
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            tHu.kickOut(mLi, tiz);
        }
    }

    public void onFirstRemoteVideoFrameRender(THu tHu, TEK tek) {
        M12.LIZ(tHu, tek);
        dispatchMessage(tHu, new C18510oj(tek));
    }

    private final void refuseAllUserOnLinkMicFinish(THu tHu, String str) {
        C09630aP.LIZ(4, "MultiCoHostService", "refuseAllUserOnLinkMicFinish, source = ".concat(String.valueOf(str)));
        refuseInvited(tHu, str);
        refuseApplied(tHu, str);
    }

    public void onUserLeft(String str, long j) {
        M12.LIZ(str);
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            dispatchMessage(tHu, new C18520ok());
        }
    }

    public <T> void unsubscribe(Class<T> cls, LsD<? super THu, ? super C20660sC<T>, 2Pr> lsD) {
        M12.LIZ(cls, lsD);
        List list = this.mLinkMicMessageHandlers.get(cls);
        if (list != null) {
            Objects.requireNonNull(list, "null cannot be cast to non-null type kotlin.collections.MutableCollection<T>");
            Ls0.LIZIZ(list).remove(lsD);
        }
    }

    private final void dispatchMessage(THu tHu, Object obj) {
        List<LsD> list = this.mLinkMicMessageHandlers.get(obj.getClass());
        if (list != null) {
            for (LsD invoke : list) {
                invoke.invoke(tHu, new C20660sC(obj));
            }
        }
    }

    public void onApplyTimerCountDown(long j, long j2) {
        StringBuilder sb = new StringBuilder("onApplyTimerCountDown, uid = ");
        long j3 = j;
        sb.append(j3);
        sb.append(", timeLeft = ");
        long j4 = j2;
        sb.append(j4);
        C09630aP.LIZ(4, "MultiCoHostService", sb.toString());
        if (this.mLinkMicSession != null) {
            this.timeOutManager.LIZ(j3, j4, C18030nx.SDK_APPLY);
        }
    }

    public void onInviteTimerCountDown(long j, long j2) {
        StringBuilder sb = new StringBuilder("onInviteTimerCountDown, uid = ");
        long j3 = j;
        sb.append(j3);
        sb.append(", timeLeft = ");
        long j4 = j2;
        sb.append(j4);
        C09630aP.LIZ(4, "MultiCoHostService", sb.toString());
        if (this.mLinkMicSession != null) {
            this.timeOutManager.LIZ(j3, j4, C18030nx.SDK_INVITE);
        }
    }

    public void onLeaveMessageReceived(THu tHu, TFj tFj) {
        long j;
        M12.LIZ(tHu, tFj);
        C09630aP.LIZ(4, "MultiCoHostService", "onLeaveMessageReceived, message = ".concat(String.valueOf(tFj)));
        if (!(!n.LIZ(tHu, this.mLinkMicSession))) {
            C24170xr r3 = C24170xr.LIZLLL;
            Long l = tFj.LIZ.LIZIZ;
            if (l != null) {
                j = l.longValue();
            } else {
                j = 0;
            }
            r3.LIZ("left", j);
        }
    }

    public <T> void subscribe(Class<T> cls, LsD<? super THu, ? super C20660sC<T>, 2Pr> lsD) {
        List list;
        M12.LIZ(cls, lsD);
        if (!this.mLinkMicMessageHandlers.containsKey(cls)) {
            this.mLinkMicMessageHandlers.put(cls, new ArrayList());
        }
        if (Ls0.LIZ(lsD, 2) && lsD != null && (list = this.mLinkMicMessageHandlers.get(cls)) != null) {
            list.add(lsD);
        }
    }

    private final List<C18230oH> refuseInvited(THu tHu, String str) {
        C09630aP.LIZ(4, "MultiCoHostService", "refuseInvited, source = ".concat(String.valueOf(str)));
        Collection<C18230oH> values = this.coHostUserMap.values();
        n.LIZIZ(values, "");
        ArrayList arrayList = new ArrayList();
        for (T next : values) {
            if (((C18230oH) next).LJFF == C18270oL.INVITED) {
                arrayList.add(next);
            }
        }
        List<C18230oH> list = arrayList;
        C09630aP.LIZ(4, "MultiCoHostService", "refuseInvited, userList = " + list.size());
        for (C18230oH r2 : list) {
            C09630aP.LIZ(4, "MultiCoHostService", "refuseInvited, user = ".concat(String.valueOf(r2)));
            replyInvite(new K0R(r2.LJIILJJIL, r2.LJIILIIL, 7), (TIZ<TD6>) null);
        }
        return list;
    }

    private final void updateCoHostUserFromLinkUser(TEK tek, C18270oL r6) {
        long j;
        Long l = tek.LIZIZ;
        if (l != null) {
            long longValue = l.longValue();
            C18230oH r2 = this.coHostUserMap.get(Long.valueOf(longValue));
            if (r2 == null) {
                r2 = ensureCoHostUser(longValue);
            }
            Object obj = tek.LJFF;
            if (obj instanceof CohostListUser) {
                updateCoHostUserFromCoHostListUser(r2, (CohostListUser) obj);
            } else {
                r2.LIZ(r6);
            }
            Long l2 = tek.LIZ;
            if (l2 != null) {
                j = l2.longValue();
            } else {
                j = 0;
            }
            r2.LJIILJJIL = j;
            String str = tek.LIZLLL;
            if (str == null) {
                str = "";
            }
            r2.LIZIZ(str);
            C09630aP.LIZ(4, "MultiCoHostService", "updateCoHostUserFromLinkUser, multiCoHostUser= ".concat(String.valueOf(r2)));
        }
    }

    private final void updateState(C18010nv r4, boolean z) {
        C14750if r1;
        C09630aP.LIZ(4, "MultiCoHostService", "updateState, this.state = " + this.state + " newState = " + r4 + ", force = " + z);
        if (z || r4.getValue() > this.state.getValue()) {
            this.state = r4;
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                dataChannel2.LIZIZ(AnonymousClass2BH.class, r4);
            }
            int i = C18490oh.LIZ[this.state.ordinal()];
            if (i == 1) {
                r1 = C14750if.INVITING;
            } else if (i == 2) {
                r1 = C14750if.APPLYING;
            } else if (i == 3) {
                r1 = C14750if.CONNECTION_START;
            } else if (i == 4) {
                r1 = C14750if.CONNECTION_SUCCEED;
            } else if (i != 5) {
                r1 = C14750if.DISABLED;
            } else {
                r1 = C14750if.CONNECTION_FINISH_SUCCEED;
            }
            C31851Ol r0 = this.mDataHolder;
            if (r0 != null) {
                r0.LIZIZ(r1);
            }
        }
    }

    public void cancelApply(MOw mOw, TIZ<7Vm> tiz) {
        MOw mOw2 = mOw;
        M12.LIZ(mOw2);
        if (this.mLinkMicSession != null) {
            2sG r6 = new 2sG();
            r6.element = getCoHostUser(C18470of.LIZ());
            C09630aP.LIZ(4, "MultiCoHostService", "cancelApply, param = ".concat(String.valueOf(mOw2)));
            C18230oH r1 = (C18230oH) r6.element;
            if (r1 != null) {
                r1.LIZ(C18270oL.CANCELING);
            }
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            LIZ.LJFF(mOw2.LIZIZ);
            THu tHu = this.mLinkMicSession;
            if (tHu != null) {
                tHu.cancelApply(mOw2, new C33231Tt(this, LIZ, mOw2, tiz, r6));
            }
        }
    }

    public void cancelInvite(MOx mOx, TIZ<7Vn> tiz) {
        M12.LIZ(mOx);
        if (this.mLinkMicSession != null) {
            C09630aP.LIZ(4, "MultiCoHostService", "cancelInvite, param = ".concat(String.valueOf(mOx)));
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            LIZ.LIZJ(mOx.LIZIZ);
            C18230oH r1 = this.coHostUserMap.get(Long.valueOf(mOx.LIZIZ));
            if (r1 != null) {
                r1.LIZ(C18270oL.CANCELING);
            }
            THu tHu = this.mLinkMicSession;
            if (tHu != null) {
                tHu.cancelInvite(mOx, new C33241Tu(this, LIZ, mOx, tiz));
            }
        }
    }

    public C18230oH getCoHostUserWithPlayType(long j, boolean z) {
        C18230oH r6 = null;
        if (z) {
            C18230oH coHostUser = getCoHostUser(C18470of.LIZ());
            if (coHostUser != null && coHostUser.LIZIZ == j) {
                r6 = coHostUser;
            }
        } else {
            C18230oH coHostUser2 = getCoHostUser(j);
            if (coHostUser2 != null && coHostUser2.LIZIZ == C18470of.LIZ()) {
                r6 = coHostUser2;
            }
        }
        C09630aP.LIZ(4, "MultiCoHostService", "getCoHostUser, isApply = " + z + ", coHostUser = " + r6);
        return r6;
    }

    public void leave(MOo mOo, TIZ<7Vk> tiz) {
        M12.LIZ(mOo);
        if (this.mLinkMicSession != null) {
            C09630aP.LIZ(4, "MultiCoHostService", "leave, param = ".concat(String.valueOf(mOo)));
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                dataChannel2.LIZJ(AnonymousClass2AX.class, new GQb(8));
            }
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            String str = mOo.LIZ;
            if (str == null) {
                str = "";
            }
            LIZ.LIZ(str, "");
            THu tHu = this.mLinkMicSession;
            if (tHu != null) {
                tHu.leaveChannel(mOo, new C33261Tw(LIZ, mOo, tiz));
            }
        }
    }

    public void onCancelApplyMessageReceived(THu tHu, TFl tFl) {
        long j;
        LinkMessage linkMessage;
        M12.LIZ(tHu, tFl);
        C09630aP.LIZ(4, "MultiCoHostService", "onCancelApplyMessageReceived, session = " + tHu + ", message = " + tFl);
        if (!(!n.LIZ(tHu, this.mLinkMicSession)) && this.room != null) {
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            Long l = tFl.LIZ.LIZIZ;
            long j2 = 0;
            if (l != null) {
                j = l.longValue();
            } else {
                j = 0;
            }
            THo tHo = tFl.LIZIZ.LIZJ;
            if (tHo != null) {
                linkMessage = tHo.LIZLLL;
            } else {
                linkMessage = null;
            }
            LIZ.LJII(j, linkMessage);
            C18050nz r3 = this.timeOutManager;
            Long l2 = tFl.LIZ.LIZIZ;
            if (l2 != null) {
                j2 = l2.longValue();
            }
            r3.LIZ(j2);
            dispatchMessage(tHu, tFl);
        }
    }

    public void onCancelInviteMessageReceived(THu tHu, TFm tFm) {
        long j;
        LinkMessage linkMessage;
        M12.LIZ(tHu, tFm);
        C09630aP.LIZ(4, "MultiCoHostService", "onCancelInviteMessageReceived, message = ".concat(String.valueOf(tFm)));
        if (!(!n.LIZ(tHu, this.mLinkMicSession)) && this.room != null) {
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            Long l = tFm.LIZ.LIZIZ;
            if (l != null) {
                j = l.longValue();
            } else {
                j = 0;
            }
            THo tHo = tFm.LIZIZ.LIZJ;
            if (tHo != null) {
                linkMessage = tHo.LIZLLL;
            } else {
                linkMessage = null;
            }
            LIZ.LIZLLL(j, linkMessage);
            C18050nz r2 = this.timeOutManager;
            Room room2 = this.room;
            if (room2 == null) {
                n.LIZIZ();
            }
            r2.LIZ(room2.getOwnerUserId());
            dispatchMessage(tHu, tFm);
            destroySession("onCancelInviteMessageReceived");
        }
    }

    public void onCreateChannelMessageReceived(THu tHu, TFn tFn) {
        LinkMessage linkMessage;
        Long l;
        C31851Ol r2;
        M12.LIZ(tHu, tFn);
        C09630aP.LIZ(4, "MultiCoHostService", "onCreateChannelMessageReceived, message = ".concat(String.valueOf(tFn)));
        if (!this.isAnchor) {
            C42461mG LIZ = C42461mG.LIZ.LIZ();
            THo tHo = tFn.LIZIZ.LIZJ;
            if (tHo != null) {
                linkMessage = tHo.LIZLLL;
            } else {
                linkMessage = null;
            }
            LIZ.LIZ(linkMessage);
            ensureSession("onCreateChannelMessageReceived");
            if (tFn.LIZ.LIZJ != null && (((l = tFn.LIZ.LIZJ) == null || l.longValue() != 0) && (r2 = this.mDataHolder) != null)) {
                Long l2 = tFn.LIZ.LIZJ;
                if (l2 == null) {
                    n.LIZIZ();
                }
                r2.LJ = l2.longValue();
            }
            dispatchMessage(tHu, new C18460oe(true));
        }
    }

    public void onDestroyChannelMessageReceived(THu tHu, TFo tFo) {
        LinkMessage linkMessage;
        M12.LIZ(tHu, tFo);
        C09630aP.LIZ(4, "MultiCoHostService", "onDestroyChannelMessageReceived, message = ".concat(String.valueOf(tFo)));
        if (this.mLinkMicSession != null && !this.isAnchor) {
            C42461mG LIZ = C42461mG.LIZ.LIZ();
            THo tHo = tFo.LIZIZ.LIZJ;
            if (tHo != null) {
                linkMessage = tHo.LIZLLL;
            } else {
                linkMessage = null;
            }
            LIZ.LIZIZ(linkMessage);
            this.isDestroyChannel = true;
            resetToFullScreen();
            updateState$default(this, C18010nv.Finished, false, 2, (Object) null);
            dispatchMessage(tHu, new C18460oe(false));
            destroySession("onDestroyChannelMessageReceived");
        }
    }

    public void onLinkMicStateChanged(THu tHu, int i) {
        M12.LIZ(tHu);
        if (this.mLinkMicSession != null) {
            C09630aP.LIZ(4, "MultiCoHostService", "onLinkMicStateChanged, state = " + i + " , mLinkMicSession = " + this.mLinkMicSession + ", session = " + tHu + ' ');
            if (i != 0) {
                if (i == 6) {
                    C42451mF.LIZ.LIZ().LIZIZ("leave_with_sdk_reason", "");
                    if (getCoHostState() == C18010nv.Applied) {
                        Fz8.LIZ(C10000b0.LJ(), 2131829683);
                    }
                    refuseAllUserOnLinkMicFinish(tHu, "onLinkMicStateChanged, state = ".concat(String.valueOf(i)));
                    updateState$default(this, C18010nv.Finished, false, 2, (Object) null);
                } else {
                    return;
                }
            }
            destroySession("state ".concat(String.valueOf(i)));
        }
    }

    public void onLocalLinkedListDidChange(List<TEK> list, List<TEK> list2) {
        long j;
        M12.LIZ(list, list2);
        ArrayList arrayList = new ArrayList();
        Iterator<T> it = list.iterator();
        while (true) {
            long j2 = 0;
            if (!it.hasNext()) {
                break;
            }
            Long l = ((TEK) it.next()).LIZIZ;
            if (l != null) {
                j2 = l.longValue();
            }
            C18230oH coHostUser = getCoHostUser(j2);
            if (coHostUser != null) {
                arrayList.add(coHostUser);
            }
        }
        List list3 = arrayList;
        ArrayList arrayList2 = new ArrayList();
        for (TEK tek : list2) {
            Long l2 = tek.LIZIZ;
            if (l2 != null) {
                j = l2.longValue();
            } else {
                j = 0;
            }
            C18230oH coHostUser2 = getCoHostUser(j);
            if (coHostUser2 != null) {
                arrayList2.add(coHostUser2);
            }
        }
        List list4 = arrayList2;
        THu tHu = this.mLinkMicSession;
        if (tHu == null) {
            n.LIZIZ();
        }
        dispatchMessage(tHu, new C18550on(true, false, list3, list4));
    }

    public void onLocalLinkedListWillChange(List<TEK> list, List<TEK> list2) {
        long j;
        M12.LIZ(list, list2);
        ArrayList arrayList = new ArrayList();
        Iterator<T> it = list.iterator();
        while (true) {
            long j2 = 0;
            if (!it.hasNext()) {
                break;
            }
            Long l = ((TEK) it.next()).LIZIZ;
            if (l != null) {
                j2 = l.longValue();
            }
            C18230oH coHostUser = getCoHostUser(j2);
            if (coHostUser != null) {
                arrayList.add(coHostUser);
            }
        }
        List list3 = arrayList;
        ArrayList arrayList2 = new ArrayList();
        for (TEK tek : list2) {
            Long l2 = tek.LIZIZ;
            if (l2 != null) {
                j = l2.longValue();
            } else {
                j = 0;
            }
            C18230oH coHostUser2 = getCoHostUser(j);
            if (coHostUser2 != null) {
                arrayList2.add(coHostUser2);
            }
        }
        List list4 = arrayList2;
        THu tHu = this.mLinkMicSession;
        if (tHu == null) {
            n.LIZIZ();
        }
        dispatchMessage(tHu, new C18550on(false, true, list3, list4));
    }

    public void permitApply(TI5 ti5, TIZ<TD5> tiz) {
        M12.LIZ(ti5);
        if (this.mLinkMicSession != null) {
            this.timeOutManager.LIZ(ti5.LIZIZ);
            C09630aP.LIZ(4, "MultiCoHostService", "permitApply, param = ".concat(String.valueOf(ti5)));
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            THu tHu = this.mLinkMicSession;
            if (tHu != null) {
                tHu.permitApply(ti5, new C33271Tx(ti5, LIZ, tiz));
            }
            if (ti5.LJ == 1) {
                C31851Ol r0 = this.mDataHolder;
                if (r0 != null) {
                    r0.LIZJ = true;
                }
                updateState$default(this, C18010nv.Prepared, false, 2, (Object) null);
            }
        }
    }

    public void replyInvite(K0R k0r, TIZ<TD6> tiz) {
        M12.LIZ(k0r);
        C09630aP.LIZ(4, "MultiCoHostService", "replyInvite, param = ".concat(String.valueOf(k0r)));
        Room LJI = AnonymousClass12L.LJI(this.dataChannel);
        if (LJI != null) {
            this.timeOutManager.LIZ(LJI.getOwnerUserId());
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            THu tHu = this.mLinkMicSession;
            if (tHu != null) {
                tHu.replyInvite(k0r, new C33281Ty(this, k0r, LIZ, tiz));
            }
            if (k0r.LIZJ == 1) {
                closeMultiGuest();
                C31851Ol r0 = this.mDataHolder;
                if (r0 != null) {
                    r0.LIZJ = true;
                }
                C09630aP.LIZ(4, "MultiCoHostService", "replyInvite, replyStatus = " + k0r.LIZJ + ", dataChannel = " + this.dataChannel);
                DataChannel dataChannel2 = this.dataChannel;
                if (dataChannel2 != null) {
                    dataChannel2.LIZIZ(C53682Ak.class, new G9W(4));
                }
                updateState$default(this, C18010nv.Prepared, false, 2, (Object) null);
            }
        }
    }

    public void setEnableSDK(boolean z, String str) {
        M12.LIZ(str);
        C09630aP.LIZ(4, "MultiCoHostService", "setEnableSDK, isAttached = " + this.isAttached + ", enable = " + z + "  source = " + str);
        if (this.isAttached) {
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                dataChannel2.LIZ(AnonymousClass2BE.class, Boolean.valueOf(z));
            }
            TIo tIo = this.mLinkMicManager;
            if (tIo == null) {
                n.LIZ("");
            } else {
                tIo.LIZ(!z);
            }
            this.isSDKEnabled = z;
        }
    }

    private final List<C18230oH> refuseApplied(THu tHu, String str) {
        C09630aP.LIZ(4, "MultiCoHostService", "refuseApplied, source = ".concat(String.valueOf(str)));
        Collection<C18230oH> values = this.coHostUserMap.values();
        n.LIZIZ(values, "");
        ArrayList arrayList = new ArrayList();
        for (T next : values) {
            if (((C18230oH) next).LJFF == C18270oL.APPLIED) {
                arrayList.add(next);
            }
        }
        List<C18230oH> list = arrayList;
        C09630aP.LIZ(4, "MultiCoHostService", "refuseApplied, userList = " + list.size());
        for (C18230oH r6 : list) {
            C09630aP.LIZ(4, "MultiCoHostService", "refuseApplied, user = ".concat(String.valueOf(r6)));
            permitApply(new TI5(r6.LJIILJJIL, r6.LJIILIIL, (String) null, (String) null, 7, (Map) null, 108), (TIZ<TD5>) null);
        }
        return list;
    }

    private final boolean updateCoHostUserFromCoHostListUser(C18230oH r6, CohostListUser cohostListUser) {
        long j;
        C18000nu r0;
        C18270oL r02;
        Long l = cohostListUser.LJIILIIL;
        if (l != null) {
            j = l.longValue();
        } else {
            j = 0;
        }
        r6.LJIILJJIL = j;
        String str = cohostListUser.LJIIZILJ;
        if (str == null) {
            str = "";
        }
        String str2 = cohostListUser.LJIIIZ;
        if (str2 == null) {
            str2 = "";
        }
        r6.LIZ = new C18250oJ(str, str2, cohostListUser.LJIIJ);
        int i = cohostListUser.LJIILLIIL;
        if (i == C18000nu.SUPPORT_TWO.ordinal()) {
            r0 = C18000nu.SUPPORT_TWO;
        } else if (i == C18000nu.SUPPORT_MULTI.ordinal()) {
            r0 = C18000nu.SUPPORT_MULTI;
        } else {
            r0 = C18000nu.NONE;
        }
        M12.LIZ(r0);
        r6.LIZJ = r0;
        if (cohostListUser.LJIJJ != null) {
            Long l2 = cohostListUser.LJIJJ;
            n.LIZIZ(l2, "");
            r6.LIZIZ = l2.longValue();
        }
        r6.LIZLLL = cohostListUser.LJIIL;
        if (cohostListUser.LJIJI != null) {
            Boolean bool = cohostListUser.LJIJI;
            n.LIZIZ(bool, "");
            r6.LJ = bool.booleanValue();
        }
        if (cohostListUser.LJIIJJI != null) {
            Long l3 = cohostListUser.LJIIJJI;
            n.LIZIZ(l3, "");
            r6.LJI = l3.longValue();
        }
        if (cohostListUser.LJIILL != null) {
            Long l4 = cohostListUser.LJIILL;
            n.LIZIZ(l4, "");
            r6.LJII = l4.longValue();
        }
        if (cohostListUser.LJJ != null) {
            String str3 = cohostListUser.LJJ;
            n.LIZIZ(str3, "");
            r6.LIZIZ(str3);
        }
        C18270oL r1 = r6.LJFF;
        if (!(r1 == C18270oL.INVITING || r1 == C18270oL.APPLYING)) {
            int i2 = cohostListUser.LJIILJJIL;
            if (i2 == 1) {
                r02 = C18270oL.LINKED;
            } else if (i2 == 2) {
                r02 = C18270oL.APPLIED;
            } else if (i2 != 3) {
                r02 = C18270oL.IDLE;
            } else {
                r02 = C18270oL.INVITED;
            }
            r6.LIZ(r02);
        }
        return true;
    }

    public void apply(MVA mva, TIZ<7Vl> tiz) {
        HashMap hashMap;
        MVA mva2 = mva;
        M12.LIZ(mva2);
        C09630aP.LIZ(4, "MultiCoHostService", "apply, param = ".concat(String.valueOf(mva2)));
        C14430i9 buildCoHostInviteEvent = buildCoHostInviteEvent(mva2);
        ensureSession("apply");
        Object obj = null;
        updateState$default(this, C18010nv.Applied, false, 2, (Object) null);
        C18230oH addCurrentUser = addCurrentUser(mva2.LIZIZ);
        C09630aP.LIZ(4, "MultiCoHostService", "apply, add user = ".concat(String.valueOf(addCurrentUser)));
        if (mva2.LJI != null) {
            Map map = mva2.LJI;
            if (map != null) {
                obj = map.get("request_id");
            }
            String str = (String) obj;
            if (str == null) {
                str = "";
            }
            addCurrentUser.LIZ(str);
            Map map2 = mva2.LJI;
            if ((map2 == null || (map2 instanceof HashMap)) && (hashMap = (HashMap) mva2.LJI) != null) {
                hashMap.remove("user_info");
            }
        }
        addCurrentUser.LIZ(C18270oL.APPLYING);
        C31851Ol r1 = this.mDataHolder;
        if (r1 != null) {
            r1.LIZ(C14280hu.APPLY);
        }
        C31851Ol r2 = this.mDataHolder;
        if (r2 != null) {
            r2.LJZL = SystemClock.uptimeMillis();
        }
        C42451mF LIZ = C42451mF.LIZ.LIZ();
        LIZ.LIZLLL(mva2.LIZIZ);
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            tHu.apply(mva2, new C33211Tr(this, LIZ, mva2, addCurrentUser, tiz, buildCoHostInviteEvent));
        }
    }

    public void invite(TI4 ti4, TIZ<7Vj> tiz) {
        Object obj;
        HashMap hashMap;
        TI4 ti42 = ti4;
        M12.LIZ(ti42);
        C09630aP.LIZ(4, "MultiCoHostService", "invite, param = ".concat(String.valueOf(ti42)));
        C14430i9 buildCoHostInviteEvent = buildCoHostInviteEvent(ti42);
        ensureSession("invite");
        Object obj2 = null;
        updateState$default(this, C18010nv.Invited, false, 2, (Object) null);
        C18230oH ensureCoHostUser = ensureCoHostUser(ti42.LIZIZ);
        ensureCoHostUser.LIZIZ = C18470of.LIZ();
        ensureCoHostUser.LJIIL = true;
        if (ti42.LJI != null) {
            Map map = ti42.LJI;
            if (map != null) {
                obj = map.get("user_info");
            } else {
                obj = null;
            }
            ensureCoHostUser.LIZ = (C18250oJ) obj;
            Map map2 = ti42.LJI;
            if (map2 != null) {
                obj2 = map2.get("request_id");
            }
            String str = (String) obj2;
            if (str == null) {
                str = "";
            }
            ensureCoHostUser.LIZ(str);
            Map map3 = ti42.LJI;
            if ((map3 == null || (map3 instanceof HashMap)) && (hashMap = (HashMap) ti42.LJI) != null) {
                hashMap.remove("user_info");
            }
        }
        C31851Ol r1 = this.mDataHolder;
        if (r1 != null) {
            r1.LIZ(C14280hu.INVITER);
        }
        ensureCoHostUser.LIZ(C18270oL.INVITING);
        C31851Ol r2 = this.mDataHolder;
        if (r2 != null) {
            r2.LJZ = SystemClock.uptimeMillis();
        }
        C42451mF LIZ = C42451mF.LIZ.LIZ();
        LIZ.LIZ(ti42.LIZIZ);
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            tHu.invite(ti42, new C33251Tv(this, LIZ, ti42, ensureCoHostUser, tiz, buildCoHostInviteEvent));
        }
    }

    public void onApplyMessageReceived(THu tHu, TFk tFk) {
        Object obj;
        LinkMessage linkMessage;
        LinkMessage linkMessage2;
        long j;
        M12.LIZ(tHu, tFk);
        C09630aP.LIZ(4, "MultiCoHostService", "onApplyMessageReceived, message = ".concat(String.valueOf(tFk)));
        if (!(!n.LIZ(tHu, this.mLinkMicSession)) && this.room != null) {
            THo tHo = tFk.LIZIZ.LIZJ;
            if (tHo != null) {
                obj = tHo.LIZIZ;
            } else {
                obj = null;
            }
            Objects.requireNonNull(obj, "null cannot be cast to non-null type com.bytedance.android.livesdk.model.message.linker.invite_message.LinkerInviteContent");
            LinkerInviteContent linkerInviteContent = (LinkerInviteContent) obj;
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            long j2 = linkerInviteContent.LIZ;
            THo tHo2 = tFk.LIZIZ.LIZJ;
            if (tHo2 != null) {
                linkMessage = tHo2.LIZLLL;
            } else {
                linkMessage = null;
            }
            LIZ.LJ(j2, linkMessage);
            if (!tryRefuseApply(tFk)) {
                C42451mF LIZ2 = C42451mF.LIZ.LIZ();
                long j3 = linkerInviteContent.LIZ;
                THo tHo3 = tFk.LIZIZ.LIZJ;
                if (tHo3 != null) {
                    linkMessage2 = tHo3.LIZLLL;
                } else {
                    linkMessage2 = null;
                }
                LIZ2.LJFF(j3, linkMessage2);
                updateState$default(this, C18010nv.Received, false, 2, (Object) null);
                C18050nz r4 = this.timeOutManager;
                C18030nx r5 = C18030nx.MESSAGE_APPLY;
                Long l = tFk.LIZ.LIZIZ;
                if (l != null) {
                    j = l.longValue();
                } else {
                    j = 0;
                }
                r4.LIZ(r5, j, (long) MtCoHostReplyTimeOutSetting.INSTANCE.getValue());
                List<InviterRivalExtra> list = linkerInviteContent.LJIIL.LJIIIIZZ;
                n.LIZIZ(list, "");
                ArrayList arrayList = new ArrayList(9HM.LIZ(list, 10));
                for (InviterRivalExtra inviterRivalExtra : list) {
                    arrayList.add(Long.valueOf(inviterRivalExtra.LJIIJJI));
                }
                C24170xr.LIZ(true, linkerInviteContent.LIZ, (List<Long>) arrayList);
                dispatchMessage(tHu, tFk);
            }
        }
    }

    public void onLayoutSwitch(TCa tCa, int i) {
        THu linkSession;
        TCS layoutManager;
        TCa LIZJ;
        Rect playerRange;
        M12.LIZ(tCa);
        C09630aP.LIZ(4, "MultiCoHostService", "onLayoutSwitch, layout = ".concat(String.valueOf(tCa)));
        if (((Number) this.containerSize.getFirst()).intValue() != 0 && ((Number) this.containerSize.getSecond()).intValue() != 0 && (linkSession = getLinkSession()) != null && (layoutManager = linkSession.layoutManager()) != null && (LIZJ = layoutManager.LIZJ()) != null && (playerRange = LIZJ.getPlayerRange()) != null) {
            C09630aP.LIZ(4, "MultiCoHostService", "onLayoutSwitch, rect = " + playerRange + ", width=" + playerRange.width() + " height=" + playerRange.height());
            StringBuilder sb = new StringBuilder("onLayoutSwitch, containerSize = ");
            sb.append(this.containerSize);
            C09630aP.LIZ(4, "MultiCoHostService", sb.toString());
            if (((Number) this.containerSize.getFirst()).intValue() == playerRange.width() && ((Number) this.containerSize.getSecond()).intValue() == playerRange.height()) {
                resetToFullScreen();
            } else if (!this.isDestroyChannel) {
                C14380i4 r4 = new C14380i4(playerRange.width(), playerRange.height(), playerRange.top, false);
                DataChannel dataChannel2 = this.dataChannel;
                if (dataChannel2 != null) {
                    dataChannel2.LIZJ(AnonymousClass2AJ.class, r4);
                }
            }
        }
    }

    public void onPermitApplyMessageReceived(THu tHu, TD4 td4) {
        Long l;
        LinkMessage linkMessage;
        long j;
        M12.LIZ(tHu, td4);
        C09630aP.LIZ(4, "MultiCoHostService", "onPermitApplyMessageReceived, message = ".concat(String.valueOf(td4)));
        boolean z = true;
        if (!(!n.LIZ(tHu, this.mLinkMicSession)) && (l = td4.LIZ.LIZIZ) != null) {
            long longValue = l.longValue();
            C09630aP.LIZ(4, "MultiCoHostService", "onPermitApplyMessageReceived, permitUserId = ".concat(String.valueOf(longValue)));
            this.timeOutManager.LIZ(longValue);
            int i = td4.LIZIZ;
            LinkMessage linkMessage2 = null;
            if (i != 1) {
                C42451mF LIZ = C42451mF.LIZ.LIZ();
                THo tHo = td4.LJ.LIZJ;
                if (tHo != null) {
                    linkMessage2 = tHo.LIZLLL;
                }
                LIZ.LIZIZ(longValue, i, linkMessage2);
                if (!(i == 2 || i == 5)) {
                    z = false;
                }
                if (!C18470of.LIZ(this.dataChannel) && z) {
                    dispatchMessage(tHu, new C18500oi());
                }
                tryDestroySession(longValue);
            } else {
                C42451mF LIZ2 = C42451mF.LIZ.LIZ();
                THo tHo2 = td4.LJ.LIZJ;
                if (tHo2 != null) {
                    linkMessage = tHo2.LIZLLL;
                } else {
                    linkMessage = null;
                }
                LIZ2.LJI(longValue, linkMessage);
                closeMultiGuest();
                C31851Ol r5 = this.mDataHolder;
                if (r5 != null) {
                    Long l2 = td4.LIZ.LIZJ;
                    if (l2 != null) {
                        j = l2.longValue();
                    } else {
                        j = 0;
                    }
                    r5.LJ = j;
                }
                C31851Ol r0 = this.mDataHolder;
                if (r0 != null) {
                    r0.LJFF = longValue;
                }
                updateState$default(this, C18010nv.Prepared, false, 2, (Object) null);
            }
            dispatchMessage(tHu, td4);
        }
    }

    public void onReplyInviteMessageReceived(THu tHu, TFr tFr) {
        Long l;
        LinkMessage linkMessage;
        long j;
        M12.LIZ(tHu, tFr);
        C09630aP.LIZ(4, "MultiCoHostService", "onReplyInviteMessageReceived, message = ".concat(String.valueOf(tFr)));
        boolean z = true;
        if (!(!n.LIZ(tHu, this.mLinkMicSession)) && (l = tFr.LIZ.LIZIZ) != null) {
            C09630aP.LIZ(4, "MultiCoHostService", "onReplyInviteMessageReceived, inviteeUserId = ".concat(String.valueOf(l)));
            this.timeOutManager.LIZ(l.longValue());
            int i = tFr.LIZIZ;
            LinkMessage linkMessage2 = null;
            if (i != 1) {
                C42451mF LIZ = C42451mF.LIZ.LIZ();
                long longValue = l.longValue();
                THo tHo = tFr.LIZLLL.LIZJ;
                if (tHo != null) {
                    linkMessage2 = tHo.LIZLLL;
                }
                LIZ.LIZ(longValue, i, linkMessage2);
                if (!(i == 2 || i == 5)) {
                    z = false;
                }
                if (!C18470of.LIZ(this.dataChannel) && z) {
                    dispatchMessage(tHu, new C18500oi());
                }
                tryDestroySession(l.longValue());
            } else {
                C42451mF LIZ2 = C42451mF.LIZ.LIZ();
                long longValue2 = l.longValue();
                THo tHo2 = tFr.LIZLLL.LIZJ;
                if (tHo2 != null) {
                    linkMessage = tHo2.LIZLLL;
                } else {
                    linkMessage = null;
                }
                LIZ2.LIZJ(longValue2, linkMessage);
                closeMultiGuest();
                C31851Ol r2 = this.mDataHolder;
                if (r2 != null) {
                    Long l2 = tFr.LIZ.LIZJ;
                    if (l2 != null) {
                        j = l2.longValue();
                    } else {
                        j = 0;
                    }
                    r2.LJ = j;
                }
                C31851Ol r22 = this.mDataHolder;
                if (r22 != null) {
                    r22.LJFF = l.longValue();
                }
                updateState$default(this, C18010nv.Prepared, false, 2, (Object) null);
            }
            dispatchMessage(tHu, tFr);
        }
    }

    public void onInviteMessageReceived(THu tHu, TD3 td3) {
        Object obj;
        LinkMessage linkMessage;
        LinkMessage linkMessage2;
        long j;
        C14770ih r0;
        User owner;
        MultiCoHostServiceImpl multiCoHostServiceImpl = this;
        TD3 td32 = td3;
        THu tHu2 = tHu;
        M12.LIZ(tHu2, td32);
        C09630aP.LIZ(4, "MultiCoHostService", "onInviteMessageReceived, message = ".concat(String.valueOf(td32)));
        Integer num = null;
        if (!n.LIZ(tHu2, multiCoHostServiceImpl.mLinkMicSession)) {
            StringBuilder sb = new StringBuilder("onInviteMessageReceived, session error, session = ");
            sb.append(tHu2.hashCode());
            sb.append(", mLinkMicSession=");
            THu tHu3 = multiCoHostServiceImpl.mLinkMicSession;
            if (tHu3 != null) {
                num = Integer.valueOf(tHu3.hashCode());
            }
            sb.append(num);
            C09630aP.LIZ(4, "MultiCoHostService", sb.toString());
        } else if (multiCoHostServiceImpl.room != null) {
            C31851Ol r2 = multiCoHostServiceImpl.mDataHolder;
            if (r2 != null) {
                r2.LJZI = SystemClock.uptimeMillis();
            }
            THo tHo = td32.LIZLLL.LIZJ;
            if (tHo != null) {
                obj = tHo.LIZIZ;
            } else {
                obj = null;
            }
            Objects.requireNonNull(obj, "null cannot be cast to non-null type com.bytedance.android.livesdk.model.message.linker.invite_message.LinkerInviteContent");
            LinkerInviteContent linkerInviteContent = (LinkerInviteContent) obj;
            C42451mF LIZ = C42451mF.LIZ.LIZ();
            long j2 = linkerInviteContent.LIZ;
            THo tHo2 = td32.LIZLLL.LIZJ;
            if (tHo2 != null) {
                linkMessage = tHo2.LIZLLL;
            } else {
                linkMessage = null;
            }
            LIZ.LIZ(j2, linkMessage);
            if (!multiCoHostServiceImpl.tryRefuseInvite(linkerInviteContent)) {
                C42451mF LIZ2 = C42451mF.LIZ.LIZ();
                long j3 = linkerInviteContent.LIZ;
                THo tHo3 = td32.LIZLLL.LIZJ;
                if (tHo3 != null) {
                    linkMessage2 = tHo3.LIZLLL;
                } else {
                    linkMessage2 = null;
                }
                LIZ2.LIZIZ(j3, linkMessage2);
                updateState$default(multiCoHostServiceImpl, C18010nv.Received, false, 2, (Object) null);
                C31851Ol r1 = multiCoHostServiceImpl.mDataHolder;
                if (r1 != null) {
                    r1.LIZ(C14280hu.INVITEE);
                }
                C18230oH ensureCoHostUser = multiCoHostServiceImpl.ensureCoHostUser(linkerInviteContent.LIZ);
                ensureCoHostUser.LJIILJJIL = linkerInviteContent.LIZIZ;
                ensureCoHostUser.LIZ(C18270oL.INVITED);
                C18050nz r10 = multiCoHostServiceImpl.timeOutManager;
                C18030nx r11 = C18030nx.MESSAGE_INVITE;
                Room room2 = multiCoHostServiceImpl.room;
                long j4 = 0;
                if (room2 == null || (owner = room2.getOwner()) == null) {
                    j = 0;
                } else {
                    j = owner.getId();
                }
                r10.LIZ(r11, j, (long) MtCoHostReplyTimeOutSetting.INSTANCE.getValue());
                C31851Ol r102 = multiCoHostServiceImpl.mDataHolder;
                if (r102 != null) {
                    Long l = td32.LIZ.LIZJ;
                    if (l != null) {
                        j4 = l.longValue();
                    }
                    r102.LJ = j4;
                }
                int i = linkerInviteContent.LJIIL.LIZIZ;
                if (i == 1) {
                    C31851Ol r12 = multiCoHostServiceImpl.mDataHolder;
                    if (r12 != null) {
                        r12.LIZ(C14770ih.FOLLOW_INVITE);
                    }
                } else if (i == 2) {
                    C31851Ol r13 = multiCoHostServiceImpl.mDataHolder;
                    if (r13 != null) {
                        r13.LIZ(C14770ih.RECOMMEND_INVITE);
                    }
                } else if (i == 5) {
                    C31851Ol r14 = multiCoHostServiceImpl.mDataHolder;
                    if (r14 != null) {
                        r14.LIZ(C14770ih.RANDOM_LINK_MIC_INVITE);
                    }
                } else if (i == 20) {
                    C31851Ol r15 = multiCoHostServiceImpl.mDataHolder;
                    if (r15 != null) {
                        r15.LIZ(C14770ih.WEEKLY_RANK_INVITE);
                    }
                } else if (i == 21) {
                    C31851Ol r16 = multiCoHostServiceImpl.mDataHolder;
                    if (r16 != null) {
                        r16.LIZ(C14770ih.HOURLY_RANK_INVITE);
                    }
                } else if (i == 23) {
                    C31851Ol r17 = multiCoHostServiceImpl.mDataHolder;
                    if (r17 != null) {
                        r17.LIZ(C14770ih.WEEKLY_RISING_INVITE);
                    }
                } else if (i == C14770ih.NONE.getType()) {
                    C31851Ol r18 = multiCoHostServiceImpl.mDataHolder;
                    if (r18 != null) {
                        r18.LIZ(C14770ih.NONE);
                    }
                } else {
                    C31851Ol r19 = multiCoHostServiceImpl.mDataHolder;
                    if (r19 != null) {
                        r19.LIZ(C14770ih.ACTIVITY);
                    }
                    C31851Ol r02 = multiCoHostServiceImpl.mDataHolder;
                    if (!(r02 == null || (r0 = r02.LJIILL) == null)) {
                        r0.setType(i);
                    }
                }
                C24170xr.LIZ(false, linkerInviteContent.LIZ, (List<Long>) 6iy.LIZ(Long.valueOf(linkerInviteContent.LIZ)));
                multiCoHostServiceImpl.dispatchMessage(tHu2, td32);
            }
        }
    }

    public void onRoomMsgReceived(THu tHu, String str, String str2) {
        M12.LIZ(tHu, str, str2);
        C18410oZ.LIZ(tHu, str, str2);
    }

    public void onRtcEndResult(THu tHu, boolean z, TE5 te5) {
        M12.LIZ(tHu);
        C18410oZ.LIZ(tHu);
    }

    public void onUserMsgReceived(THu tHu, String str, String str2) {
        M12.LIZ(tHu, str, str2);
        C18410oZ.LIZIZ(tHu, str, str2);
    }

    public void onVideoMute(long j, String str, boolean z) {
        M12.LIZ(str);
        C18410oZ.LIZLLL(str);
    }

    public void onAudioMute(long j, String str, boolean z) {
        M12.LIZ(str);
        C18410oZ.LIZ(str);
        THu tHu = this.mLinkMicSession;
        if (tHu != null) {
            dispatchMessage(tHu, new C18480og(j, str, z));
        }
    }

    public void onUserJoined(THu tHu, TEK tek, TDz tDz) {
        long j;
        M12.LIZ(tHu, tek);
        C09630aP.LIZ(4, "MultiCoHostService", "onUserJoined, message = ".concat(String.valueOf(tDz)));
        if (!(!n.LIZ(tHu, this.mLinkMicSession))) {
            C24170xr r3 = C24170xr.LIZLLL;
            Long l = tek.LIZIZ;
            if (l != null) {
                j = l.longValue();
            } else {
                j = 0;
            }
            r3.LIZ("enter", j);
        }
    }

    public void attach(Room room2, DataChannel dataChannel2, Context context) {
        boolean z;
        Boolean bool;
        M12.LIZ(room2, context);
        C09630aP.LIZ(4, "MultiCoHostService", "attach, roomId = " + room2.getId());
        this.isAttached = true;
        this.dataChannel = dataChannel2;
        this.mDataHolder = C31851Ol.LLFII.LIZ();
        this.room = room2;
        if (dataChannel2 == null || (bool = (Boolean) dataChannel2.LIZIZ(Fv2.class)) == null) {
            z = false;
        } else {
            z = bool.booleanValue();
        }
        this.isAnchor = z;
        ILinkMicService LIZ = C11100cm.LIZ(ILinkMicService.class);
        n.LIZIZ(LIZ, "");
        ILinkMicService iLinkMicService = LIZ;
        this.mLinkMicService = iLinkMicService;
        if (iLinkMicService == null) {
            n.LIZ("");
        }
        8dp builder = iLinkMicService.builder();
        if (builder != null) {
            builder.LIZ();
            builder.LIZ(room2);
            TIo LIZ2 = builder.LIZ(context);
            this.mLinkMicManager = LIZ2;
            if (LIZ2 == null) {
                n.LIZ("");
            }
            LIZ2.LIZ(this);
            setEnableSDK(true, "attach");
            TIX tix = new TIX();
            StreamUrl streamUrl = room2.getStreamUrl();
            n.LIZIZ(streamUrl, "");
            tix.LIZ = streamUrl.LIZ();
            this.mLiveConfig = new TIB(true, tix.LIZ(), new C33221Ts(), false, C49701xw.LIZ, 24);
            if (dataChannel2 != null) {
                C18050nz r0 = this.timeOutManager;
                M12.LIZ(dataChannel2);
                r0.LIZIZ = dataChannel2;
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:25:0x0068, code lost:
        if (r3 != null) goto L_0x0070;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x006c, code lost:
        if (r3 != null) goto L_0x0070;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void startCoHostUI(android.view.ViewGroup r20, android.widget.FrameLayout r21, X.AnonymousClass0CH r22) {
        /*
            r19 = this;
            r7 = r19
            r8 = r21
            r3 = r22
            r9 = r20
            X.M12.LIZ(r9, r8, r3)
            r11 = 0
            r7.isDestroyChannel = r11
            X.THu r0 = r7.mLinkMicSession
            if (r0 != 0) goto L_0x001a
            java.lang.String r0 = "startCoHostUI"
            X.THu r0 = r7.ensureSession(r0)
            r7.mLinkMicSession = r0
        L_0x001a:
            com.bytedance.ies.sdk.datachannel.DataChannel r1 = r7.dataChannel
            if (r1 == 0) goto L_0x00fb
            java.lang.Class<X.2AT> r0 = X.AnonymousClass2AT.class
            java.lang.Object r6 = r1.LIZIZ(r0)
            X.Cwu r6 = (X.Cwu) r6
        L_0x0026:
            X.0od r0 = new X.0od
            r0.<init>(r7, r9)
            r9.post(r0)
            com.bytedance.ies.sdk.datachannel.DataChannel r2 = r7.dataChannel
            if (r2 == 0) goto L_0x003c
            java.lang.Class<X.2AT> r1 = X.AnonymousClass2AT.class
            X.1xx r0 = new X.1xx
            r0.<init>(r7, r3, r9, r8)
            r2.LIZ(r3, r1, r0)
        L_0x003c:
            boolean r0 = r7.isAnchor
            r10 = 4
            java.lang.String r5 = "MultiCoHostService"
            if (r0 != 0) goto L_0x0112
            X.THu r0 = r7.mLinkMicSession
            if (r0 == 0) goto L_0x0057
            X.TCR r0 = r0.userManager()
            if (r0 == 0) goto L_0x0057
            java.util.List r0 = r0.LIZJ()
            if (r0 == 0) goto L_0x0057
            int r11 = r0.size()
        L_0x0057:
            com.bytedance.android.livesdkapi.depend.model.live.Room r0 = r7.room
            if (r0 == 0) goto L_0x006e
            X.M12.LIZ(r0)
            com.bytedance.android.livesdk.model.linkSetting.MultiLiveUserSettings r0 = r0.multiLiveUserSettings
            if (r0 == 0) goto L_0x006a
            com.bytedance.android.livesdk.model.linkSetting.CoHost r0 = r0.LIZJ
            if (r0 == 0) goto L_0x006a
            java.util.List r3 = r0.LIZIZ
            if (r3 != 0) goto L_0x0070
        L_0x006a:
            X.Lel r3 = X.Lel.INSTANCE
            if (r3 != 0) goto L_0x0070
        L_0x006e:
            X.Lel r3 = X.Lel.INSTANCE
        L_0x0070:
            com.bytedance.android.livesdkapi.depend.model.live.Room r0 = r7.room
            r12 = 0
            if (r0 == 0) goto L_0x00f8
            com.bytedance.android.livesdkapi.depend.model.live.RoomLinkInfo r0 = r0.getLinkMicInfo()
            if (r0 == 0) goto L_0x00f8
            long r0 = r0.LIZ
        L_0x007e:
            java.lang.String r4 = java.lang.String.valueOf(r11)
            java.lang.String r2 = "startCoHostUI, sdkLinkedSize = "
            java.lang.String r2 = r2.concat(r4)
            X.C09630aP.LIZ((int) r10, (java.lang.String) r5, (java.lang.String) r2)
            java.lang.StringBuilder r4 = new java.lang.StringBuilder
            java.lang.String r2 = "startCoHostUI, roomLinkedList size = "
            r4.<init>(r2)
            int r2 = r3.size()
            r4.append(r2)
            java.lang.String r2 = r4.toString()
            X.C09630aP.LIZ((int) r10, (java.lang.String) r5, (java.lang.String) r2)
            java.lang.String r4 = java.lang.String.valueOf(r0)
            java.lang.String r2 = "startCoHostUI, linkChannelId = "
            java.lang.String r2 = r2.concat(r4)
            X.C09630aP.LIZ((int) r10, (java.lang.String) r5, (java.lang.String) r2)
            if (r11 > 0) goto L_0x0112
            boolean r2 = r3.isEmpty()
            r2 = r2 ^ 1
            if (r2 == 0) goto L_0x0112
            int r2 = (r0 > r12 ? 1 : (r0 == r12 ? 0 : -1))
            if (r2 <= 0) goto L_0x0112
            java.util.ArrayList r4 = new java.util.ArrayList
            r2 = 10
            int r2 = X.9HM.LIZ(r3, r2)
            r4.<init>(r2)
            java.util.Iterator r11 = r3.iterator()
        L_0x00ca:
            boolean r2 = r11.hasNext()
            if (r2 == 0) goto L_0x00fe
            java.lang.Object r10 = r11.next()
            com.bytedance.android.livesdk.model.linkSetting.LinkmicUser r10 = (com.bytedance.android.livesdk.model.linkSetting.LinkmicUser) r10
            X.TEK r12 = new X.TEK
            long r2 = r10.LIZIZ
            java.lang.Long r13 = java.lang.Long.valueOf(r2)
            long r2 = r10.LIZ
            java.lang.Long r14 = java.lang.Long.valueOf(r2)
            java.lang.Long r15 = java.lang.Long.valueOf(r0)
            java.lang.String r2 = r10.LIZJ
            r17 = 0
            r18 = 0
            r16 = r2
            r12.<init>(r13, r14, r15, r16, r17, r18)
            r4.add(r12)
            r2 = 4
            goto L_0x00ca
        L_0x00f8:
            r0 = 0
            goto L_0x007e
        L_0x00fb:
            r6 = 0
            goto L_0x0026
        L_0x00fe:
            java.util.List r4 = (java.util.List) r4
            X.THu r0 = r7.mLinkMicSession
            if (r0 == 0) goto L_0x0112
            X.TCR r1 = r0.userManager()
            if (r1 == 0) goto L_0x0112
            java.util.ArrayList r0 = new java.util.ArrayList
            r0.<init>(r4)
            r1.LIZ(r0)
        L_0x0112:
            X.THu r0 = r7.mLinkMicSession
            if (r0 == 0) goto L_0x011f
            X.TCS r0 = r0.layoutManager()
            if (r0 == 0) goto L_0x011f
            r0.LIZ(r9, r8, r6)
        L_0x011f:
            X.THu r0 = r7.mLinkMicSession
            if (r0 == 0) goto L_0x012c
            X.TCS r0 = r0.layoutManager()
            if (r0 == 0) goto L_0x012c
            r0.LJII()
        L_0x012c:
            java.lang.String r1 = java.lang.String.valueOf(r9)
            java.lang.String r0 = "startCoHostUI, container = "
            java.lang.String r1 = r0.concat(r1)
            r0 = 4
            X.C09630aP.LIZ((int) r0, (java.lang.String) r5, (java.lang.String) r1)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.live.liveinteract.multicohost.service.MultiCoHostServiceImpl.startCoHostUI(android.view.ViewGroup, android.widget.FrameLayout, X.0CH):void");
    }

    public static /* synthetic */ void updateState$default(MultiCoHostServiceImpl multiCoHostServiceImpl, C18010nv r2, boolean z, int i, Object obj) {
        if (obj == null) {
            if ((i & 2) != 0) {
                z = false;
            }
            multiCoHostServiceImpl.updateState(r2, z);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: updateState");
    }

    public void onWindowStateChanged(TCh tCh, TC2 tc2, TC2 tc22, MMF mmf, 2K3 r12) {
        int i;
        TCS layoutManager;
        TCa LIZJ;
        List allLayoutWindows;
        M12.LIZ(tCh, tc2, tc22, mmf);
        if (this.mLinkMicSession == null) {
            C09630aP.LIZ(4, "MultiCoHostService", "onWindowStateChanged, mLinkMicSession = " + this.mLinkMicSession);
            return;
        }
        C09630aP.LIZ(4, "MultiCoHostService", "onWindowStateChanged, window = ".concat(String.valueOf(tCh)));
        C09630aP.LIZ(4, "MultiCoHostService", "onWindowStateChanged, oldState = " + tc2 + ", newState = " + tc22);
        StringBuilder sb = new StringBuilder("onWindowStateChanged, isRoomOwnerWindow = ");
        sb.append(tCh.LJFF());
        C09630aP.LIZ(4, "MultiCoHostService", sb.toString());
        boolean z = this.isAnchor;
        if (!z || tc2 != tc22) {
            if (z) {
                THu tHu = this.mLinkMicSession;
                if (tHu == null || (layoutManager = tHu.layoutManager()) == null || (LIZJ = layoutManager.LIZJ()) == null || (allLayoutWindows = LIZJ.getAllLayoutWindows()) == null) {
                    i = 0;
                } else {
                    i = allLayoutWindows.size();
                }
                C42451mF.LIZ.LIZ().LIZ(tCh, i, getCoHostUser(tCh.LIZLLL()));
            }
            Rect LJI = tCh.LJI();
            C09630aP.LIZ(4, "MultiCoHostService", "onWindowStateChanged, rect = " + LJI + " width=" + LJI.width() + "  height=" + LJI.height());
            C09630aP.LIZ(4, "MultiCoHostService", "onWindowStateChanged, ---------");
            if (!tCh.LJFF() && tCh.LIZJ() == TC2.StateLinked) {
                updateState$default(this, C18010nv.Linked, false, 2, (Object) null);
            }
            C18560oo r1 = new C18560oo(tCh, tc2, tc22);
            THu tHu2 = this.mLinkMicSession;
            if (tHu2 == null) {
                n.LIZIZ();
            }
            dispatchMessage(tHu2, r1);
            return;
        }
        C09630aP.LIZ(4, "MultiCoHostService", "onWindowStateChanged, return, oldState == newState");
    }

    public void onUserListChanged(THu tHu, List<TEK> list, List<TEK> list2, List<TEK> list3, String str) {
        Object obj;
        boolean z;
        DataChannel dataChannel2;
        ArrayList<Long> arrayList;
        List<TEK> list4 = list;
        THu tHu2 = tHu;
        List<TEK> list5 = list3;
        List<TEK> list6 = list2;
        M12.LIZ(tHu2, list4, list6, list5);
        if (!(!n.LIZ(tHu2, this.mLinkMicSession))) {
            C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, before coHostUserMap size = " + this.coHostUserMap.size());
            C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, linkedUsers size = " + list4.size());
            C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, applicants size = " + list6.size());
            C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, invitees size = " + list5.size());
            ArrayList<Cwu> arrayList2 = new ArrayList<>();
            ArrayList arrayList3 = new ArrayList(9HM.LIZ(list4, 10));
            Iterator<T> it = list4.iterator();
            while (it.hasNext()) {
                arrayList3.add(CwZ.LIZ(it.next(), C18270oL.LINKED));
            }
            arrayList2.addAll(arrayList3);
            ArrayList arrayList4 = new ArrayList(9HM.LIZ(list6, 10));
            Iterator<T> it2 = list6.iterator();
            while (it2.hasNext()) {
                arrayList4.add(CwZ.LIZ(it2.next(), C18270oL.APPLIED));
            }
            arrayList2.addAll(arrayList4);
            ArrayList arrayList5 = new ArrayList(9HM.LIZ(list5, 10));
            Iterator<T> it3 = list5.iterator();
            while (it3.hasNext()) {
                arrayList5.add(CwZ.LIZ(it3.next(), C18270oL.INVITED));
            }
            arrayList2.addAll(arrayList5);
            HashMap hashMap = new HashMap();
            hashMap.putAll(this.coHostUserMap);
            for (Cwu cwu : arrayList2) {
                TEK tek = (TEK) cwu.getFirst();
                C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, foreach state = " + cwu.getSecond() + " user = " + tek);
                updateCoHostUserFromLinkUser((TEK) cwu.getFirst(), (C18270oL) cwu.getSecond());
                Ls0.LJI(hashMap).remove(tek.LIZIZ);
            }
            for (Map.Entry entry : hashMap.entrySet()) {
                C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, remove uid = " + ((Number) entry.getKey()).longValue());
                removeUser(((Number) entry.getKey()).longValue());
            }
            C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged, after coHostUserMap size = " + this.coHostUserMap.size());
            for (Map.Entry<Long, C18230oH> value : this.coHostUserMap.entrySet()) {
                C09630aP.LIZ(4, "MultiCoHostService", "onUserListChanged,after user = " + value.getValue());
            }
            Collection<C18230oH> values = this.coHostUserMap.values();
            String str2 = "";
            n.LIZIZ(values, str2);
            for (C18230oH r8 : values) {
                if (r8.LJIILIIL != C18470of.LIZ() && r8.LIZIZ > 0 && !r8.LIZJ()) {
                    if (!r8.LIZ() || r8.LJII <= 0) {
                        this.timeOutManager.LIZ(r8.LJIILIIL);
                    } else {
                        this.timeOutManager.LIZ(C18030nx.USER_LIST, r8.LJIILIIL, r8.LJII / 1000);
                    }
                }
            }
            C31851Ol r0 = this.mDataHolder;
            if (!(r0 == null || (arrayList = r0.LJLLILLLL) == null)) {
                arrayList.clear();
            }
            List<C18230oH> coHostUserList2 = getCoHostUserList();
            if (str != null) {
                str2 = str;
            }
            dispatchMessage(tHu2, new C18540om(coHostUserList2, str2));
            DataChannel dataChannel3 = this.dataChannel;
            if (dataChannel3 != null) {
                obj = dataChannel3.LIZIZ(AnonymousClass2BG.class);
            } else {
                obj = null;
            }
            if (list4.size() == 4) {
                z = true;
            } else {
                z = false;
            }
            C09630aP.LIZ(4, "ToolbarCoHostBehavior", "oldFullState = " + obj + " newFullState = " + z);
            if ((!n.LIZ(obj, Boolean.valueOf(z))) && (dataChannel2 = this.dataChannel) != null) {
                dataChannel2.LIZIZ(AnonymousClass2BG.class, Boolean.valueOf(z));
            }
        }
    }
}
