discord-jadx/app/src/main/java/com/discord/stores/ConnectionTimeStats.java

298 lines
12 KiB
Java

package com.discord.stores;
import c.d.b.a.a;
import com.discord.api.voice.state.VoiceState;
import com.discord.app.AppLog;
import com.discord.gateway.GatewaySocket;
import com.discord.models.domain.ModelAuditLogEntry;
import com.discord.models.domain.ModelPayload;
import com.discord.utilities.analytics.AnalyticsTracker;
import com.discord.utilities.logging.Logger;
import com.discord.utilities.time.Clock;
import d0.o;
import d0.t.g0;
import d0.t.h0;
import d0.t.u;
import d0.z.d.m;
/* compiled from: ConnectionTimeStats.kt */
public final class ConnectionTimeStats {
private final Stat connectionStreamFirstFrame;
private final Stat connectionVideoFirstFrame;
private final Stat gatewayConnection;
private final Stat gatewayHello;
private final Stat mediaEngineConnection;
private Long myUserId;
private final Stat streamConnection;
private final Stat streamFirstFrame;
private final Stat streamRequested;
private final Stat videoFirstFrame;
private final Stat voiceConnection;
/* compiled from: ConnectionTimeStats.kt */
public static final class Stat {
private final Clock clock;
private Long endTime;
private final ConnectionTimeStats owner;
private Long startTime;
private final StatType type;
public Stat(Clock clock, ConnectionTimeStats connectionTimeStats, StatType statType) {
m.checkNotNullParameter(clock, "clock");
m.checkNotNullParameter(connectionTimeStats, "owner");
m.checkNotNullParameter(statType, "type");
this.clock = clock;
this.owner = connectionTimeStats;
this.type = statType;
}
public static /* synthetic */ void end$default(Stat stat, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
z2 = false;
}
stat.end(z2);
}
public static /* synthetic */ void start$default(Stat stat, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
z2 = false;
}
stat.start(z2);
}
public final void clear() {
this.startTime = null;
this.endTime = null;
}
public final Long elapsed() {
Long l = this.startTime;
Long l2 = this.endTime;
if (l == null || l2 == null) {
return null;
}
return Long.valueOf(l2.longValue() - l.longValue());
}
public final void end(boolean z2) {
if (this.endTime == null) {
Long l = this.startTime;
long currentTimeMillis = this.clock.currentTimeMillis();
if (l == null) {
AppLog appLog = AppLog.g;
StringBuilder P = a.P("ConnectionTimeStats: \"");
P.append(this.type);
P.append("\" ended without starting!");
Logger.w$default(appLog, P.toString(), null, 2, null);
return;
}
long longValue = currentTimeMillis - l.longValue();
if (longValue < 0) {
AppLog appLog2 = AppLog.g;
StringBuilder P2 = a.P("ConnectionTimeStats: \"");
P2.append(this.type);
P2.append("\" has a negative time!");
P2.append(u.joinToString$default(h0.mapOf(o.to(this.type.toString(), "type"), o.to(String.valueOf(longValue), "elapsedMs"), o.to(String.valueOf(l.longValue()), "start"), o.to(String.valueOf(currentTimeMillis), "end")).entrySet(), "\n\t", null, null, 0, null, null, 62, null));
Logger.w$default(appLog2, P2.toString(), null, 2, null);
return;
}
this.endTime = Long.valueOf(currentTimeMillis);
StringBuilder P3 = a.P("ConnectionTimeStats: \"");
P3.append(this.type);
P3.append("\" took ");
P3.append(longValue);
P3.append(" ms (");
P3.append(l);
P3.append(" to ");
P3.append(currentTimeMillis);
P3.append(')');
AppLog.i(P3.toString());
ConnectionTimeStats.access$sendAnalyticsEvent(this.owner, this.type);
} else if (!z2) {
AppLog appLog3 = AppLog.g;
StringBuilder P4 = a.P("ConnectionTimeStats: \"");
P4.append(this.type);
P4.append("\" attempting to end while endTime is set!");
Logger.w$default(appLog3, P4.toString(), null, 2, null);
}
}
public final void start(boolean z2) {
if (this.startTime != null) {
if (!z2) {
AppLog appLog = AppLog.g;
StringBuilder P = a.P("ConnectionTimeStats: \"");
P.append(this.type);
P.append("\" attempting to re-start without reset!");
Logger.w$default(appLog, P.toString(), null, 2, null);
}
} else if (this.endTime != null) {
AppLog appLog2 = AppLog.g;
StringBuilder P2 = a.P("ConnectionTimeStats: \"");
P2.append(this.type);
P2.append("\" attempting to re-start while endTime is set!");
Logger.w$default(appLog2, P2.toString(), null, 2, null);
} else {
long currentTimeMillis = this.clock.currentTimeMillis();
this.startTime = Long.valueOf(currentTimeMillis);
StringBuilder P3 = a.P("ConnectionTimeStats: \"");
P3.append(this.type);
P3.append("\" started @ ");
P3.append(currentTimeMillis);
AppLog.i(P3.toString());
}
}
}
/* compiled from: ConnectionTimeStats.kt */
public enum StatType {
GatewayConnection,
GatewayHello,
VoiceConnection,
StreamRequested,
StreamConnection,
MediaEngineConnection,
StreamFirstFrame,
VideoFirstFrame,
ConnectionStreamFirstFrame,
ConnectionVideoFirstFrame
}
public ConnectionTimeStats(Clock clock) {
m.checkNotNullParameter(clock, "clock");
StatType statType = StatType.VideoFirstFrame;
if (!m.areEqual(statType.toString(), "VideoFirstFrame")) {
Logger.e$default(AppLog.g, "ConnectionTimeStats.StatType has been renamed!", null, g0.mapOf(o.to(ModelAuditLogEntry.CHANGE_KEY_NAME, statType.toString())), 2, null);
}
this.gatewayConnection = new Stat(clock, this, StatType.GatewayConnection);
this.gatewayHello = new Stat(clock, this, StatType.GatewayHello);
this.voiceConnection = new Stat(clock, this, StatType.VoiceConnection);
this.streamRequested = new Stat(clock, this, StatType.StreamRequested);
this.streamConnection = new Stat(clock, this, StatType.StreamConnection);
this.streamFirstFrame = new Stat(clock, this, StatType.StreamFirstFrame);
this.videoFirstFrame = new Stat(clock, this, statType);
this.mediaEngineConnection = new Stat(clock, this, StatType.MediaEngineConnection);
this.connectionVideoFirstFrame = new Stat(clock, this, StatType.ConnectionVideoFirstFrame);
this.connectionStreamFirstFrame = new Stat(clock, this, StatType.ConnectionStreamFirstFrame);
}
public static final /* synthetic */ Stat access$getConnectionStreamFirstFrame$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.connectionStreamFirstFrame;
}
public static final /* synthetic */ Stat access$getConnectionVideoFirstFrame$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.connectionVideoFirstFrame;
}
public static final /* synthetic */ Stat access$getGatewayConnection$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.gatewayConnection;
}
public static final /* synthetic */ Stat access$getGatewayHello$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.gatewayHello;
}
public static final /* synthetic */ Stat access$getMediaEngineConnection$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.mediaEngineConnection;
}
public static final /* synthetic */ Stat access$getStreamConnection$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.streamConnection;
}
public static final /* synthetic */ Stat access$getStreamFirstFrame$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.streamFirstFrame;
}
public static final /* synthetic */ Stat access$getStreamRequested$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.streamRequested;
}
public static final /* synthetic */ Stat access$getVideoFirstFrame$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.videoFirstFrame;
}
public static final /* synthetic */ Stat access$getVoiceConnection$p(ConnectionTimeStats connectionTimeStats) {
return connectionTimeStats.voiceConnection;
}
public static final /* synthetic */ void access$sendAnalyticsEvent(ConnectionTimeStats connectionTimeStats, StatType statType) {
connectionTimeStats.sendAnalyticsEvent(statType);
}
private final void clear(boolean z2) {
if (!z2) {
this.gatewayConnection.clear();
this.gatewayHello.clear();
}
this.voiceConnection.clear();
this.streamRequested.clear();
this.streamConnection.clear();
this.streamFirstFrame.clear();
this.videoFirstFrame.clear();
this.mediaEngineConnection.clear();
this.connectionVideoFirstFrame.clear();
this.connectionStreamFirstFrame.clear();
}
public static /* synthetic */ void clear$default(ConnectionTimeStats connectionTimeStats, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
z2 = false;
}
connectionTimeStats.clear(z2);
}
private final void sendAnalyticsEvent(StatType statType) {
AnalyticsTracker.INSTANCE.videoEventTimes(statType.toString(), this.gatewayConnection.elapsed(), this.gatewayHello.elapsed(), this.voiceConnection.elapsed(), this.streamRequested.elapsed(), this.streamConnection.elapsed(), this.streamFirstFrame.elapsed(), this.videoFirstFrame.elapsed(), this.mediaEngineConnection.elapsed(), this.connectionVideoFirstFrame.elapsed(), this.connectionStreamFirstFrame.elapsed());
}
public final void addListener(GatewaySocket gatewaySocket) {
m.checkNotNullParameter(gatewaySocket, "socket");
gatewaySocket.getListeners().add(new ConnectionTimeStats$addListener$1(this));
}
public final void addListener(StoreMediaEngine storeMediaEngine) {
m.checkNotNullParameter(storeMediaEngine, "storeMediaEngine");
storeMediaEngine.getListeners().add(new ConnectionTimeStats$addListener$4(this));
}
public final void addListener(StoreRtcConnection storeRtcConnection) {
m.checkNotNullParameter(storeRtcConnection, "rtcConnection");
storeRtcConnection.getListeners().add(new ConnectionTimeStats$addListener$2(this));
}
public final void addListener(StoreStreamRtcConnection storeStreamRtcConnection) {
m.checkNotNullParameter(storeStreamRtcConnection, "streamRtcConnection");
storeStreamRtcConnection.getListeners().add(new ConnectionTimeStats$addListener$3(this));
}
public final void handleApplicationStreamUpdate(long j, Integer num) {
this.streamFirstFrame.start(true);
}
public final void handleConnectionOpen(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
clear$default(this, false, 1, null);
this.myUserId = Long.valueOf(modelPayload.getMe().i());
}
public final void handleStreamWatch(String str) {
m.checkNotNullParameter(str, "streamKey");
Stat.start$default(this.streamRequested, false, 1, null);
}
public final void handleVideoStreamUpdate(long j, Integer num, int i, int i2, int i3) {
if (i2 != 0) {
this.videoFirstFrame.start(true);
}
}
public final void handleVoiceStateUpdate(VoiceState voiceState) {
m.checkNotNullParameter(voiceState, "voiceState");
long m = voiceState.m();
Long l = this.myUserId;
if (l != null && m == l.longValue() && voiceState.a() == null) {
clear(true);
}
}
}