APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:造梦次元
版本号:1.1.73
包名称:com.ideaflow.zmcy

MD5 校验值:290b0e4cd89c7a20355df0a13ec24559

反编译源代码说明

WebSocketClient.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package com.ideaflow.zmcy.tools;

import com.huawei.hms.push.constant.RemoteMessageConst;
import com.ideaflow.zmcy.App;
import com.ideaflow.zmcy.common.CommonApp;
import com.ideaflow.zmcy.entity.User;
import com.ideaflow.zmcy.mmkv.UserConfigMMKV;
import com.ideaflow.zmcy.statistic.AppLifecycleReporter;
import com.jstudio.jkit.LogKit;
import com.umeng.analytics.pro.aw;
import com.umeng.analytics.pro.bm;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.Metadata;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.Job;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;

@Metadata(d1 = {"\u0000l\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010!\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\u0003\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0005\bÆ\u0002\u0018\u00002\u00020\u00012\u00020\u0002B\u0007\b\u0002¢\u0006\u0002\u0010\u0003J\u000e\u0010\u0018\u001a\u00020\u00192\u0006\u0010\u001a\u001a\u00020\u0001J\b\u0010\u001b\u001a\u00020\u0019H\u0002J\u0010\u0010\u001c\u001a\u00020\u001d2\u0006\u0010\u001e\u001a\u00020\u0005H\u0002J\b\u0010\u001f\u001a\u00020\u0019H\u0002J \u0010 \u001a\u00020\u00192\u0006\u0010\u0016\u001a\u00020\u00172\u0006\u0010!\u001a\u00020\u00072\u0006\u0010\"\u001a\u00020\u0005H\u0016J \u0010#\u001a\u00020\u00192\u0006\u0010\u0016\u001a\u00020\u00172\u0006\u0010!\u001a\u00020\u00072\u0006\u0010\"\u001a\u00020\u0005H\u0016J\"\u0010$\u001a\u00020\u00192\u0006\u0010\u0016\u001a\u00020\u00172\u0006\u0010%\u001a\u00020&2\b\u0010'\u001a\u0004\u0018\u00010(H\u0016J\u0018\u0010)\u001a\u00020\u00192\u0006\u0010\u0016\u001a\u00020\u00172\u0006\u0010*\u001a\u00020\u0005H\u0016J\u0018\u0010)\u001a\u00020\u00192\u0006\u0010\u0016\u001a\u00020\u00172\u0006\u0010+\u001a\u00020,H\u0016J\u0018\u0010-\u001a\u00020\u00192\u0006\u0010\u0016\u001a\u00020\u00172\u0006\u0010'\u001a\u00020(H\u0016J\b\u0010.\u001a\u00020\u0019H\u0016J\b\u0010/\u001a\u00020\u0019H\u0016J\u0010\u00100\u001a\u00020\u00192\b\u00101\u001a\u0004\u0018\u000102J\u000e\u00103\u001a\u00020\u00192\u0006\u0010\u001a\u001a\u00020\u0001J\u0010\u00104\u001a\u00020\u00192\u0006\u00105\u001a\u00020\u0005H\u0002J\b\u00106\u001a\u00020\u0019H\u0002R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\n\u001a\b\u0012\u0004\u0012\u00020\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u001b\u0010\f\u001a\u00020\r8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b\u0010\u0010\u0011\u001a\u0004\b\u000e\u0010\u000fR\u0010\u0010\u0012\u001a\u0004\u0018\u00010\u0013X\u0082\u000e¢\u0006\u0002\n\u0000R\u0016\u0010\u0014\u001a\n \u0015*\u0004\u0018\u00010\u00050\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u0016\u001a\u0004\u0018\u00010\u0017X\u0082\u000e¢\u0006\u0002\n\u0000¨\u00067"}, d2 = {"Lcom/ideaflow/zmcy/tools/WebSocketClient;", "Lokhttp3/WebSocketListener;", "Lcom/ideaflow/zmcy/statistic/AppLifecycleReporter;", "()V", "CONNECT_URL", "", "connectionState", "", "enable", "", "listeners", "", "okhttpClient", "Lokhttp3/OkHttpClient;", "getOkhttpClient", "()Lokhttp3/OkHttpClient;", "okhttpClient$delegate", "Lkotlin/Lazy;", "pingPongJob", "Lkotlinx/coroutines/Job;", RemoteMessageConst.Notification.TAG, "kotlin.jvm.PlatformType", "webSocket", "Lokhttp3/WebSocket;", "addListener", "", "webSocketListener", "closeConnection", "createRequest", "Lokhttp3/Request;", "uid", "newConnection", "onClosed", "code", "reason", "onClosing", "onFailure", bm.aM, "", "response", "Lokhttp3/Response;", "onMessage", "text", "bytes", "Lokio/ByteString;", "onOpen", "onSessionClosed", "onSessionStarted", "onUserChanged", aw.m, "Lcom/ideaflow/zmcy/entity/User;", "removeListener", "sendMessage", "content", "startPingPongJob", "1.1.73-20240523_yybRelease"}, k = 1, mv = {1, 9, 0}, xi = 48)
public final class WebSocketClient extends WebSocketListener implements AppLifecycleReporter {
    private static final String CONNECT_URL;
    public static final WebSocketClient INSTANCE;
    private static int connectionState;
    private static boolean enable;
    private static List<WebSocketListener> listeners;

    private static final Lazy okhttpClient;
    private static Job pingPongJob;
    private static final String tag;
    private static WebSocket webSocket;

    private WebSocketClient() {
    }

    static {
        WebSocketClient webSocketClient = new WebSocketClient();
        INSTANCE = webSocketClient;
        tag = "WebSocketClient";
        CONNECT_URL = BuildToolKitKt.isTestEnvironment() ? "wss://cyapi-t.ideaflow.pro/ws" : "wss://cyapi.ideaflow.pro/ws";
        listeners = new ArrayList();
        okhttpClient = LazyKt.lazy(new Function0<OkHttpClient>() {
            @Override
            public final OkHttpClient invoke() {
                return new OkHttpClient.Builder().connectTimeout(15L, TimeUnit.SECONDS).readTimeout(10L, TimeUnit.SECONDS).writeTimeout(10L, TimeUnit.SECONDS).build();
            }
        });
        enable = true;
        webSocketClient.startPingPongJob();
    }

    public final OkHttpClient getOkhttpClient() {
        return (OkHttpClient) okhttpClient.getValue();
    }

    public final Request createRequest(String uid) {
        return new Request.Builder().url(CONNECT_URL + "?uid=" + uid).build();
    }

    public final void onUserChanged(User user) {
        String id = user != null ? user.getId() : null;
        if (id == null || id.length() == 0) {
            closeConnection();
        } else {
            newConnection();
        }
    }

    public final void newConnection() {
        ((App) CommonApp.INSTANCE.obtain()).runTask(Dispatchers.getIO(), new WebSocketClient$newConnection$1(this, null));
    }

    public final void closeConnection() {
        ((App) CommonApp.INSTANCE.obtain()).runTask(Dispatchers.getIO(), new WebSocketClient$closeConnection$1(null));
    }

    @Override
    public void onSessionStarted() {
        enable = true;
        if (connectionState == 0) {
            User user = UserConfigMMKV.INSTANCE.getUser();
            String id = user != null ? user.getId() : null;
            if (id == null || id.length() == 0) {
                return;
            }
            newConnection();
        }
    }

    @Override
    public void onSessionClosed() {
        enable = false;
        closeConnection();
    }

    public final void sendMessage(String content) {
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "send: " + content);
        WebSocket webSocket2 = webSocket;
        if (webSocket2 != null) {
            webSocket2.send(content);
        }
    }

    private final void startPingPongJob() {
        if (CommonKitKt.isRunning(pingPongJob)) {
            return;
        }
        pingPongJob = ((App) CommonApp.INSTANCE.obtain()).runTask(Dispatchers.getIO(), new WebSocketClient$startPingPongJob$1(null));
    }

    public final void addListener(WebSocketListener webSocketListener) {
        Intrinsics.checkNotNullParameter(webSocketListener, "webSocketListener");
        if (listeners.contains(webSocketListener)) {
            return;
        }
        listeners.add(webSocketListener);
    }

    public final void removeListener(WebSocketListener webSocketListener) {
        Intrinsics.checkNotNullParameter(webSocketListener, "webSocketListener");
        if (listeners.contains(webSocketListener)) {
            return;
        }
        listeners.remove(webSocketListener);
    }

    @Override
    public void onOpen(WebSocket webSocket2, Response response) {
        Intrinsics.checkNotNullParameter(webSocket2, "webSocket");
        Intrinsics.checkNotNullParameter(response, "response");
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "onOpen");
        connectionState = 1;
        Iterator<T> it = listeners.iterator();
        while (it.hasNext()) {
            ((WebSocketListener) it.next()).onOpen(webSocket2, response);
        }
    }

    @Override
    public void onMessage(WebSocket webSocket2, String text) {
        Intrinsics.checkNotNullParameter(webSocket2, "webSocket");
        Intrinsics.checkNotNullParameter(text, "text");
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "onMessage text: " + text);
        Iterator<T> it = listeners.iterator();
        while (it.hasNext()) {
            ((WebSocketListener) it.next()).onMessage(webSocket2, text);
        }
    }

    @Override
    public void onMessage(WebSocket webSocket2, ByteString bytes) {
        Intrinsics.checkNotNullParameter(webSocket2, "webSocket");
        Intrinsics.checkNotNullParameter(bytes, "bytes");
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "onMessage ByteString");
        Iterator<T> it = listeners.iterator();
        while (it.hasNext()) {
            ((WebSocketListener) it.next()).onMessage(webSocket2, bytes);
        }
    }

    @Override
    public void onClosing(WebSocket webSocket2, int code, String reason) {
        Intrinsics.checkNotNullParameter(webSocket2, "webSocket");
        Intrinsics.checkNotNullParameter(reason, "reason");
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "onClosing");
        connectionState = 0;
        Iterator<T> it = listeners.iterator();
        while (it.hasNext()) {
            ((WebSocketListener) it.next()).onClosing(webSocket2, code, reason);
        }
    }

    @Override
    public void onClosed(WebSocket webSocket2, int code, String reason) {
        Intrinsics.checkNotNullParameter(webSocket2, "webSocket");
        Intrinsics.checkNotNullParameter(reason, "reason");
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "onClosed");
        connectionState = 0;
        Iterator<T> it = listeners.iterator();
        while (it.hasNext()) {
            ((WebSocketListener) it.next()).onClosed(webSocket2, code, reason);
        }
    }

    @Override
    public void onFailure(WebSocket webSocket2, Throwable t, Response response) {
        Intrinsics.checkNotNullParameter(webSocket2, "webSocket");
        Intrinsics.checkNotNullParameter(t, "t");
        LogKit.Companion companion = LogKit.INSTANCE;
        String tag2 = tag;
        Intrinsics.checkNotNullExpressionValue(tag2, "tag");
        companion.d(tag2, "onFailure: " + t.getMessage());
        connectionState = 0;
        Iterator<T> it = listeners.iterator();
        while (it.hasNext()) {
            ((WebSocketListener) it.next()).onFailure(webSocket2, t, response);
        }
    }
}