798 lines
32 KiB
Java
798 lines
32 KiB
Java
package c.a.q.n0;
|
|
|
|
import androidx.annotation.AnyThread;
|
|
import androidx.core.app.NotificationCompat;
|
|
import c0.z.d.m;
|
|
import c0.z.d.o;
|
|
import com.discord.models.domain.ModelAuditLogEntry;
|
|
import com.discord.rtcconnection.socket.io.Opcodes;
|
|
import com.discord.rtcconnection.socket.io.Payloads;
|
|
import com.discord.utilities.debug.DebugPrintBuilder;
|
|
import com.discord.utilities.debug.DebugPrintable;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.discord.utilities.networking.Backoff;
|
|
import com.discord.utilities.rest.SendUtils;
|
|
import com.discord.utilities.time.Clock;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import e0.e0.k.h;
|
|
import e0.x;
|
|
import java.lang.reflect.Type;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
import java.util.concurrent.TimeUnit;
|
|
import javax.net.ssl.SSLSocketFactory;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import okhttp3.Request;
|
|
import okhttp3.Response;
|
|
import okhttp3.WebSocket;
|
|
import okhttp3.WebSocketListener;
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public final class a extends WebSocketListener implements DebugPrintable {
|
|
public static int i;
|
|
public static final Type j = new C0041a().getType();
|
|
public static final b k = new b(null);
|
|
public c A;
|
|
public boolean B;
|
|
public final String C;
|
|
public final String D;
|
|
public final SSLSocketFactory E;
|
|
public final Logger F;
|
|
public final c.a.q.c G;
|
|
public final Clock H;
|
|
public final String I;
|
|
public final String l;
|
|
public final Gson m = new c.i.d.e().a();
|
|
public final Timer n = new Timer();
|
|
public final Backoff o;
|
|
public final CopyOnWriteArraySet<d> p;
|
|
public int q;
|
|
|
|
/* renamed from: r reason: collision with root package name */
|
|
public WebSocket f225r;
|
|
public String s;
|
|
public String t;
|
|
public Long u;
|
|
public boolean v;
|
|
|
|
/* renamed from: w reason: collision with root package name */
|
|
public b f226w;
|
|
|
|
/* renamed from: x reason: collision with root package name */
|
|
public Long f227x;
|
|
|
|
/* renamed from: y reason: collision with root package name */
|
|
public TimerTask f228y;
|
|
|
|
/* renamed from: z reason: collision with root package name */
|
|
public Long f229z;
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
/* renamed from: c.a.q.n0.a$a reason: collision with other inner class name */
|
|
public static final class C0041a extends TypeToken<Map<String, ? extends Integer>> {
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class b {
|
|
public b(DefaultConstructorMarker defaultConstructorMarker) {
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public enum c {
|
|
DISCONNECTED,
|
|
CONNECTING,
|
|
IDENTIFYING,
|
|
RESUMING,
|
|
CONNECTED,
|
|
RECONNECTING
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public interface d {
|
|
void a(String str, String str2);
|
|
|
|
void b(boolean z2, Integer num, String str);
|
|
|
|
void c(String str, List<Integer> list);
|
|
|
|
void d(String str);
|
|
|
|
void e(long j, int i, int i2, List<Payloads.Stream> list);
|
|
|
|
void f(Map<String, Integer> map);
|
|
|
|
void g(long j);
|
|
|
|
void h();
|
|
|
|
void i();
|
|
|
|
void j(long j);
|
|
|
|
void k(int i, int i2, String str, List<Payloads.Stream> list);
|
|
|
|
void onConnecting();
|
|
|
|
void onSpeaking(long j, int i, boolean z2);
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class e extends o implements Function1<WebSocket, Unit> {
|
|
public static final e i = new e();
|
|
|
|
public e() {
|
|
super(1);
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public Unit invoke(WebSocket webSocket) {
|
|
WebSocket webSocket2 = webSocket;
|
|
m.checkNotNullParameter(webSocket2, "it");
|
|
webSocket2.e(1000, "Force Close");
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class f extends o implements Function1<WebSocket, Unit> {
|
|
public static final f i = new f();
|
|
|
|
public f() {
|
|
super(1);
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public Unit invoke(WebSocket webSocket) {
|
|
WebSocket webSocket2 = webSocket;
|
|
m.checkNotNullParameter(webSocket2, "it");
|
|
webSocket2.e(SendUtils.MAX_MESSAGE_CHARACTER_COUNT_PREMIUM, "close reason");
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class g extends TimerTask {
|
|
public final /* synthetic */ a i;
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
/* renamed from: c.a.q.n0.a$g$a reason: collision with other inner class name */
|
|
public static final class C0042a extends o implements Function0<Unit> {
|
|
public final /* synthetic */ g this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public C0042a(g gVar) {
|
|
super(0);
|
|
this.this$0 = gVar;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public Unit mo17invoke() {
|
|
a.a(this.this$0.i, true, null, "The connection timed out. Did not receive OP_HELLO in time.");
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
public g(a aVar) {
|
|
this.i = aVar;
|
|
}
|
|
|
|
@Override // java.util.TimerTask, java.lang.Runnable
|
|
public void run() {
|
|
this.i.m(new C0042a(this));
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class h extends o implements Function0<Unit> {
|
|
public final /* synthetic */ int $code;
|
|
public final /* synthetic */ String $reason;
|
|
public final /* synthetic */ WebSocket $webSocket;
|
|
public final /* synthetic */ a this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public h(a aVar, WebSocket webSocket, int i, String str) {
|
|
super(0);
|
|
this.this$0 = aVar;
|
|
this.$webSocket = webSocket;
|
|
this.$code = i;
|
|
this.$reason = str;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public Unit mo17invoke() {
|
|
if (!(!m.areEqual(this.$webSocket, this.this$0.f225r))) {
|
|
a.a(this.this$0, true, Integer.valueOf(this.$code), this.$reason);
|
|
}
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class i extends o implements Function0<Unit> {
|
|
public final /* synthetic */ Throwable $t;
|
|
public final /* synthetic */ WebSocket $webSocket;
|
|
public final /* synthetic */ a this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public i(a aVar, WebSocket webSocket, Throwable th) {
|
|
super(0);
|
|
this.this$0 = aVar;
|
|
this.$webSocket = webSocket;
|
|
this.$t = th;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public Unit mo17invoke() {
|
|
if (!(!m.areEqual(this.$webSocket, this.this$0.f225r))) {
|
|
a aVar = this.this$0;
|
|
StringBuilder O = c.d.b.a.a.O("An error with the websocket occurred: ");
|
|
O.append(this.$t.getMessage());
|
|
a.a(aVar, true, null, O.toString());
|
|
}
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class j extends o implements Function0<Unit> {
|
|
public final /* synthetic */ Payloads.Incoming $message;
|
|
public final /* synthetic */ WebSocket $webSocket;
|
|
public final /* synthetic */ a this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public j(a aVar, WebSocket webSocket, Payloads.Incoming incoming) {
|
|
super(0);
|
|
this.this$0 = aVar;
|
|
this.$webSocket = webSocket;
|
|
this.$message = incoming;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public Unit mo17invoke() {
|
|
boolean z2 = true;
|
|
if (!(!m.areEqual(this.$webSocket, this.this$0.f225r))) {
|
|
switch (this.$message.getOpcode()) {
|
|
case 2:
|
|
a aVar = this.this$0;
|
|
Object c2 = aVar.m.c(this.$message.getData(), Payloads.Ready.class);
|
|
m.checkNotNullExpressionValue(c2, "gson.fromJson(message.da…yloads.Ready::class.java)");
|
|
Payloads.Ready ready = (Payloads.Ready) c2;
|
|
aVar.o.succeed();
|
|
long currentTimeMillis = aVar.H.currentTimeMillis();
|
|
Long l = aVar.f229z;
|
|
long longValue = currentTimeMillis - (l != null ? l.longValue() : 0);
|
|
aVar.i("[READY] took " + longValue + " ms");
|
|
aVar.G.a();
|
|
for (d dVar : aVar.p) {
|
|
m.checkNotNullExpressionValue(dVar, "it");
|
|
dVar.k(ready.getPort(), ready.getSsrc(), ready.getIp(), ready.getStreams());
|
|
}
|
|
break;
|
|
case 3:
|
|
a aVar2 = this.this$0;
|
|
aVar2.n(3, String.valueOf(aVar2.H.currentTimeMillis()));
|
|
break;
|
|
case 4:
|
|
a aVar3 = this.this$0;
|
|
Object c3 = aVar3.m.c(this.$message.getData(), Payloads.Description.class);
|
|
m.checkNotNullExpressionValue(c3, "gson.fromJson(message.da….Description::class.java)");
|
|
Payloads.Description description = (Payloads.Description) c3;
|
|
aVar3.G.a();
|
|
for (d dVar2 : aVar3.p) {
|
|
m.checkNotNullExpressionValue(dVar2, "it");
|
|
dVar2.c(description.getMode(), description.getSecretKey());
|
|
dVar2.a(description.getAudioCodec(), description.getVideoCodec());
|
|
String mediaSessionId = description.getMediaSessionId();
|
|
if (mediaSessionId != null) {
|
|
dVar2.d(mediaSessionId);
|
|
}
|
|
}
|
|
aVar3.B = true;
|
|
break;
|
|
case 5:
|
|
a aVar4 = this.this$0;
|
|
Object c4 = aVar4.m.c(this.$message.getData(), Payloads.Speaking.class);
|
|
m.checkNotNullExpressionValue(c4, "gson.fromJson(message.da…ads.Speaking::class.java)");
|
|
Payloads.Speaking speaking = (Payloads.Speaking) c4;
|
|
if (!(speaking.getUserId() == null || speaking.getSpeaking() == null)) {
|
|
Integer speaking2 = speaking.getSpeaking();
|
|
if (speaking2 == null || speaking2.intValue() != 1) {
|
|
z2 = false;
|
|
}
|
|
aVar4.G.a();
|
|
for (d dVar3 : aVar4.p) {
|
|
m.checkNotNullExpressionValue(dVar3, "it");
|
|
dVar3.onSpeaking(speaking.getUserId().longValue(), speaking.getSsrc(), z2);
|
|
}
|
|
break;
|
|
}
|
|
case 6:
|
|
a aVar5 = this.this$0;
|
|
Object c5 = aVar5.m.c(this.$message.getData(), Long.TYPE);
|
|
m.checkNotNullExpressionValue(c5, "gson.fromJson(message.data, Long::class.java)");
|
|
long longValue2 = ((Number) c5).longValue();
|
|
long currentTimeMillis2 = aVar5.H.currentTimeMillis();
|
|
long j = currentTimeMillis2 - longValue2;
|
|
aVar5.h("got heartbeat ack after " + j + " ms");
|
|
aVar5.f227x = Long.valueOf(currentTimeMillis2);
|
|
aVar5.v = true;
|
|
aVar5.G.a();
|
|
for (d dVar4 : aVar5.p) {
|
|
m.checkNotNullExpressionValue(dVar4, "it");
|
|
dVar4.g(j);
|
|
}
|
|
break;
|
|
case 7:
|
|
case 10:
|
|
case 11:
|
|
default:
|
|
a aVar6 = this.this$0;
|
|
StringBuilder O = c.d.b.a.a.O("unknown opcode: ");
|
|
O.append(this.$message.getOpcode());
|
|
aVar6.i(O.toString());
|
|
break;
|
|
case 8:
|
|
a aVar7 = this.this$0;
|
|
Object c6 = aVar7.m.c(this.$message.getData(), Payloads.Hello.class);
|
|
m.checkNotNullExpressionValue(c6, "gson.fromJson(message.da…yloads.Hello::class.java)");
|
|
Payloads.Hello hello = (Payloads.Hello) c6;
|
|
TimerTask timerTask = aVar7.f228y;
|
|
if (timerTask != null) {
|
|
timerTask.cancel();
|
|
}
|
|
aVar7.i("[HELLO] raw: " + hello);
|
|
aVar7.u = Long.valueOf(hello.getHeartbeatIntervalMs());
|
|
aVar7.q = hello.getServerVersion();
|
|
aVar7.f226w.cancel();
|
|
aVar7.v = true;
|
|
aVar7.k();
|
|
break;
|
|
case 9:
|
|
this.this$0.o.succeed();
|
|
break;
|
|
case 12:
|
|
a aVar8 = this.this$0;
|
|
Object c7 = aVar8.m.c(this.$message.getData(), Payloads.Video.class);
|
|
m.checkNotNullExpressionValue(c7, "gson.fromJson(message.da…yloads.Video::class.java)");
|
|
Payloads.Video video = (Payloads.Video) c7;
|
|
if (video.getUserId() != null) {
|
|
aVar8.G.a();
|
|
for (d dVar5 : aVar8.p) {
|
|
m.checkNotNullExpressionValue(dVar5, "it");
|
|
dVar5.e(video.getUserId().longValue(), video.getAudioSsrc(), video.getVideoSsrc(), video.getStreams());
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
case 13:
|
|
a aVar9 = this.this$0;
|
|
Object c8 = aVar9.m.c(this.$message.getData(), Payloads.ClientDisconnect.class);
|
|
m.checkNotNullExpressionValue(c8, "gson.fromJson(message.da…ntDisconnect::class.java)");
|
|
Payloads.ClientDisconnect clientDisconnect = (Payloads.ClientDisconnect) c8;
|
|
aVar9.G.a();
|
|
for (d dVar6 : aVar9.p) {
|
|
m.checkNotNullExpressionValue(dVar6, "it");
|
|
dVar6.j(clientDisconnect.getUserId());
|
|
}
|
|
break;
|
|
case 14:
|
|
a aVar10 = this.this$0;
|
|
Object c9 = aVar10.m.c(this.$message.getData(), Payloads.SessionUpdate.class);
|
|
m.checkNotNullExpressionValue(c9, "gson.fromJson(message.da…essionUpdate::class.java)");
|
|
Payloads.SessionUpdate sessionUpdate = (Payloads.SessionUpdate) c9;
|
|
aVar10.G.a();
|
|
for (d dVar7 : aVar10.p) {
|
|
m.checkNotNullExpressionValue(dVar7, "it");
|
|
String mediaSessionId2 = sessionUpdate.getMediaSessionId();
|
|
if (mediaSessionId2 != null) {
|
|
dVar7.d(mediaSessionId2);
|
|
}
|
|
}
|
|
break;
|
|
case 15:
|
|
a aVar11 = this.this$0;
|
|
Gson gson = aVar11.m;
|
|
JsonElement data = this.$message.getData();
|
|
Type type = a.j;
|
|
Objects.requireNonNull(gson);
|
|
Object d = data == null ? null : gson.d(new c.i.d.q.x.a(data), type);
|
|
m.checkNotNullExpressionValue(d, "gson.fromJson(message.data, MEDIA_SINK_WANTS_TYPE)");
|
|
Map<String, Integer> map = (Map) d;
|
|
aVar11.G.a();
|
|
for (d dVar8 : aVar11.p) {
|
|
m.checkNotNullExpressionValue(dVar8, "it");
|
|
dVar8.f(map);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class k extends o implements Function0<Unit> {
|
|
public final /* synthetic */ WebSocket $webSocket;
|
|
public final /* synthetic */ a this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public k(a aVar, WebSocket webSocket) {
|
|
super(0);
|
|
this.this$0 = aVar;
|
|
this.$webSocket = webSocket;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public Unit mo17invoke() {
|
|
boolean z2 = true;
|
|
if (!(!m.areEqual(this.$webSocket, this.this$0.f225r))) {
|
|
a aVar = this.this$0;
|
|
c cVar = aVar.A;
|
|
if (cVar == c.CONNECTING) {
|
|
aVar.G.a();
|
|
for (d dVar : aVar.p) {
|
|
m.checkNotNullExpressionValue(dVar, "it");
|
|
dVar.i();
|
|
}
|
|
} else if (cVar == c.RECONNECTING) {
|
|
String str = aVar.t;
|
|
String str2 = aVar.s;
|
|
String str3 = aVar.D;
|
|
Long l = aVar.f227x;
|
|
if (l != null && aVar.H.currentTimeMillis() - l.longValue() > 60000) {
|
|
z2 = false;
|
|
}
|
|
if (str == null || str2 == null || !aVar.B || !z2) {
|
|
StringBuilder O = c.d.b.a.a.O("Cannot resume connection. resumable: ");
|
|
O.append(aVar.B);
|
|
O.append(" -- isHeartbeatRecentEnough: ");
|
|
O.append(z2);
|
|
aVar.f(false, 4801, O.toString());
|
|
} else {
|
|
aVar.i("[RESUME] resuming session. serverId=" + str2 + " sessionId=" + str);
|
|
aVar.G.a();
|
|
for (d dVar2 : aVar.p) {
|
|
m.checkNotNullExpressionValue(dVar2, "it");
|
|
dVar2.h();
|
|
}
|
|
aVar.A = c.RESUMING;
|
|
aVar.n(7, new Payloads.Resume(str3, str, str2));
|
|
}
|
|
}
|
|
a aVar2 = this.this$0;
|
|
aVar2.A = c.CONNECTED;
|
|
long currentTimeMillis = aVar2.H.currentTimeMillis();
|
|
Long l2 = this.this$0.f229z;
|
|
long longValue = currentTimeMillis - (l2 != null ? l2.longValue() : 0);
|
|
a aVar3 = this.this$0;
|
|
StringBuilder O2 = c.d.b.a.a.O("[CONNECTED] to ");
|
|
O2.append(this.this$0.C);
|
|
aVar3.i(O2.toString());
|
|
a aVar4 = this.this$0;
|
|
aVar4.G.a();
|
|
for (d dVar3 : aVar4.p) {
|
|
m.checkNotNullExpressionValue(dVar3, "it");
|
|
dVar3.g(longValue / ((long) 2));
|
|
}
|
|
}
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: RtcControlSocket.kt */
|
|
public static final class l extends o implements Function1<WebSocket, Unit> {
|
|
public static final l i = new l();
|
|
|
|
public l() {
|
|
super(1);
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public Unit invoke(WebSocket webSocket) {
|
|
WebSocket webSocket2 = webSocket;
|
|
m.checkNotNullParameter(webSocket2, "it");
|
|
webSocket2.e(SendUtils.MAX_MESSAGE_CHARACTER_COUNT_PREMIUM, "reconnecting");
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
public a(String str, String str2, SSLSocketFactory sSLSocketFactory, Logger logger, c.a.q.c cVar, Clock clock, String str3) {
|
|
m.checkNotNullParameter(str, "endpoint");
|
|
m.checkNotNullParameter(str2, "token");
|
|
m.checkNotNullParameter(logger, "logger");
|
|
m.checkNotNullParameter(cVar, "mediaEngineThreadExecutor");
|
|
m.checkNotNullParameter(clock, "clock");
|
|
m.checkNotNullParameter(str3, "loggingTagPrefix");
|
|
this.C = str;
|
|
this.D = str2;
|
|
this.E = sSLSocketFactory;
|
|
this.F = logger;
|
|
this.G = cVar;
|
|
this.H = clock;
|
|
this.I = str3;
|
|
StringBuilder S = c.d.b.a.a.S(str3, "->RtcControlSocket ");
|
|
int i2 = i + 1;
|
|
i = i2;
|
|
S.append(i2);
|
|
String sb = S.toString();
|
|
this.l = sb;
|
|
this.o = new Backoff(1000, 5000, 3, false, new Backoff.TimerScheduler(sb, cVar), 8, null);
|
|
this.p = new CopyOnWriteArraySet<>();
|
|
this.q = 3;
|
|
this.f226w = new b(this);
|
|
this.A = c.DISCONNECTED;
|
|
}
|
|
|
|
public static final void a(a aVar, boolean z2, Integer num, String str) {
|
|
aVar.A = c.DISCONNECTED;
|
|
if ((num != null && num.intValue() == 4004) || ((num != null && num.intValue() == 4015) || ((num != null && num.intValue() == 4011) || (num != null && num.intValue() == 4006)))) {
|
|
aVar.f(true, num, str);
|
|
} else if (aVar.o.hasReachedFailureThreshold()) {
|
|
aVar.j("[WS CLOSED] Backoff exceeded. Resetting.");
|
|
aVar.f(z2, num, str);
|
|
} else {
|
|
aVar.b(null);
|
|
String L = c.d.b.a.a.L(new Object[]{Double.valueOf(((double) aVar.o.fail(new c(aVar, z2, num, str))) / 1000.0d)}, 1, "%.2f", "java.lang.String.format(this, *args)");
|
|
aVar.j("`[WS CLOSED] (" + z2 + ", " + num + ", " + str + ") retrying in " + L + " seconds.");
|
|
}
|
|
}
|
|
|
|
public final void b(Function1<? super WebSocket, Unit> function1) {
|
|
this.o.cancel();
|
|
this.f226w.cancel();
|
|
TimerTask timerTask = this.f228y;
|
|
if (timerTask != null) {
|
|
timerTask.cancel();
|
|
}
|
|
WebSocket webSocket = this.f225r;
|
|
if (!(webSocket == null || function1 == null)) {
|
|
function1.invoke(webSocket);
|
|
}
|
|
this.f225r = null;
|
|
}
|
|
|
|
public final void c() {
|
|
this.G.a();
|
|
i("[CLOSE]");
|
|
b(e.i);
|
|
this.s = null;
|
|
this.t = null;
|
|
this.B = false;
|
|
this.A = c.DISCONNECTED;
|
|
this.G.a();
|
|
for (d dVar : this.p) {
|
|
m.checkNotNullExpressionValue(dVar, "it");
|
|
dVar.b(false, 1000, "Force Close");
|
|
}
|
|
}
|
|
|
|
public final boolean d() {
|
|
this.G.a();
|
|
if (this.A != c.DISCONNECTED) {
|
|
j("Cannot start a new connection, connection state is not disconnected");
|
|
return false;
|
|
}
|
|
this.A = c.CONNECTING;
|
|
e();
|
|
this.G.a();
|
|
for (d dVar : this.p) {
|
|
m.checkNotNullExpressionValue(dVar, "it");
|
|
dVar.onConnecting();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override // com.discord.utilities.debug.DebugPrintable
|
|
public void debugPrint(DebugPrintBuilder debugPrintBuilder) {
|
|
m.checkNotNullParameter(debugPrintBuilder, "dp");
|
|
debugPrintBuilder.appendKeyValue("serverId", this.s);
|
|
debugPrintBuilder.appendKeyValue("sessionId", this.t);
|
|
debugPrintBuilder.appendKeyValue("heartbeatInterval", this.u);
|
|
debugPrintBuilder.appendKeyValue("lastHeartbeatAckTime", this.f227x);
|
|
debugPrintBuilder.appendKeyValue("connectionStartTime", this.f229z);
|
|
debugPrintBuilder.appendKeyValue("connectionState", this.A);
|
|
debugPrintBuilder.appendKeyValue("resumable", Boolean.valueOf(this.B));
|
|
}
|
|
|
|
public final void e() {
|
|
StringBuilder O = c.d.b.a.a.O("[CONNECT] ");
|
|
O.append(this.C);
|
|
i(O.toString());
|
|
if (this.f225r != null) {
|
|
this.F.e(this.l, "Connect called with already existing websocket", null, null);
|
|
b(f.i);
|
|
return;
|
|
}
|
|
this.f229z = Long.valueOf(this.H.currentTimeMillis());
|
|
TimerTask timerTask = this.f228y;
|
|
if (timerTask != null) {
|
|
timerTask.cancel();
|
|
}
|
|
g gVar = new g(this);
|
|
this.f228y = gVar;
|
|
this.n.schedule(gVar, 20000);
|
|
x.a aVar = new x.a();
|
|
aVar.a(1, TimeUnit.MINUTES);
|
|
SSLSocketFactory sSLSocketFactory = this.E;
|
|
if (sSLSocketFactory != null) {
|
|
h.a aVar2 = e0.e0.k.h.f2994c;
|
|
aVar.b(sSLSocketFactory, e0.e0.k.h.a.n());
|
|
}
|
|
String G = c.d.b.a.a.G(new StringBuilder(), this.C, "?v=5");
|
|
i("attempting WSS connection with " + G);
|
|
x xVar = new x(aVar);
|
|
Request.a aVar3 = new Request.a();
|
|
aVar3.f(G);
|
|
this.f225r = xVar.g(aVar3.a(), this);
|
|
}
|
|
|
|
public final void f(boolean z2, Integer num, String str) {
|
|
j("[DISCONNECT] (" + z2 + ", " + num + ", " + str + ')');
|
|
b(null);
|
|
this.s = null;
|
|
this.t = null;
|
|
this.B = false;
|
|
this.A = c.DISCONNECTED;
|
|
this.G.a();
|
|
for (d dVar : this.p) {
|
|
m.checkNotNullExpressionValue(dVar, "it");
|
|
dVar.b(z2, num, str);
|
|
}
|
|
}
|
|
|
|
public final void g(long j2, String str, boolean z2) {
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_REASON);
|
|
this.G.a();
|
|
if (this.f225r != null) {
|
|
i("Performing an immediate heartbeat on existing socket: " + str);
|
|
this.f226w.cancel();
|
|
b bVar = new b(this);
|
|
this.f226w = bVar;
|
|
this.n.schedule(bVar, j2);
|
|
} else if (!z2) {
|
|
i("Immediate heartbeat requested, but is disconnected and a reset was not requested: " + str);
|
|
} else if (this.o.isPending() && this.f225r == null) {
|
|
i("Connection backoff reset Immediate heartbeat when socket was disconnected.");
|
|
this.o.succeed();
|
|
l(false, 4802, "Reset backoff.");
|
|
}
|
|
}
|
|
|
|
public final void h(String str) {
|
|
Logger.d$default(this.F, this.l, str, null, 4, null);
|
|
}
|
|
|
|
public final void i(String str) {
|
|
Logger.i$default(this.F, this.l, str, null, 4, null);
|
|
}
|
|
|
|
public final void j(String str) {
|
|
Logger.w$default(this.F, this.l, str, null, 4, null);
|
|
}
|
|
|
|
public final void k() {
|
|
if (this.v) {
|
|
this.v = false;
|
|
n(3, String.valueOf(this.H.currentTimeMillis()));
|
|
Long l2 = this.u;
|
|
if (l2 != null) {
|
|
b bVar = new b(this);
|
|
this.f226w = bVar;
|
|
this.n.schedule(bVar, l2.longValue());
|
|
return;
|
|
}
|
|
j("onHeartbeatInterval called when heartbeatInterval was null");
|
|
return;
|
|
}
|
|
b(d.i);
|
|
String L = c.d.b.a.a.L(new Object[]{Double.valueOf(((double) this.o.fail(new e(this))) / 1000.0d)}, 1, "%.2f", "java.lang.String.format(this, *args)");
|
|
j("[ACK TIMEOUT] reconnecting in " + L + " seconds.");
|
|
}
|
|
|
|
public final void l(boolean z2, Integer num, String str) {
|
|
i("[RECONNECT] wasFatal=" + z2 + " code=" + num + " reason=" + str);
|
|
b(l.i);
|
|
this.A = c.RECONNECTING;
|
|
e();
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARNING: Unknown variable types count: 1 */
|
|
@AnyThread
|
|
public final void m(Function0<Unit> function0) {
|
|
c.a.q.c cVar = this.G;
|
|
if (function0 != null) {
|
|
function0 = new f(function0);
|
|
}
|
|
cVar.k.execute((Runnable) function0);
|
|
}
|
|
|
|
public final void n(int i2, Object obj) {
|
|
WebSocket webSocket = this.f225r;
|
|
if (webSocket == null) {
|
|
StringBuilder O = c.d.b.a.a.O("opcode() websocket null. opcode: ");
|
|
O.append(Opcodes.INSTANCE.getNameOf(i2));
|
|
this.F.e(this.l, O.toString(), null, null);
|
|
return;
|
|
}
|
|
try {
|
|
String m = this.m.m(new Payloads.Outgoing(i2, obj));
|
|
h("sending (" + Opcodes.INSTANCE.getNameOf(i2) + "): " + m);
|
|
m.checkNotNullExpressionValue(m, "json");
|
|
webSocket.a(m);
|
|
} catch (Exception unused) {
|
|
j("exception sending opcode: " + i2 + " and payload: " + obj);
|
|
}
|
|
}
|
|
|
|
@Override // okhttp3.WebSocketListener
|
|
public void onClosed(WebSocket webSocket, int i2, String str) {
|
|
m.checkNotNullParameter(webSocket, "webSocket");
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_REASON);
|
|
super.onClosed(webSocket, i2, str);
|
|
m(new h(this, webSocket, i2, str));
|
|
}
|
|
|
|
@Override // okhttp3.WebSocketListener
|
|
public void onClosing(WebSocket webSocket, int i2, String str) {
|
|
m.checkNotNullParameter(webSocket, "webSocket");
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_REASON);
|
|
((e0.e0.n.d) webSocket).e(i2, str);
|
|
}
|
|
|
|
@Override // okhttp3.WebSocketListener
|
|
public void onFailure(WebSocket webSocket, Throwable th, Response response) {
|
|
m.checkNotNullParameter(webSocket, "webSocket");
|
|
m.checkNotNullParameter(th, "t");
|
|
super.onFailure(webSocket, th, response);
|
|
m(new i(this, webSocket, th));
|
|
}
|
|
|
|
@Override // okhttp3.WebSocketListener
|
|
public void onMessage(WebSocket webSocket, String str) {
|
|
m.checkNotNullParameter(webSocket, "webSocket");
|
|
m.checkNotNullParameter(str, NotificationCompat.MessagingStyle.Message.KEY_TEXT);
|
|
Payloads.Incoming incoming = (Payloads.Incoming) c.i.a.f.e.o.c.r0(Payloads.Incoming.class).cast(this.m.g(str, Payloads.Incoming.class));
|
|
super.onMessage(webSocket, str);
|
|
StringBuilder O = c.d.b.a.a.O("received (");
|
|
O.append(Opcodes.INSTANCE.getNameOf(incoming.getOpcode()));
|
|
O.append("): ");
|
|
O.append(incoming);
|
|
h(O.toString());
|
|
m(new j(this, webSocket, incoming));
|
|
}
|
|
|
|
@Override // okhttp3.WebSocketListener
|
|
public void onOpen(WebSocket webSocket, Response response) {
|
|
m.checkNotNullParameter(webSocket, "webSocket");
|
|
m.checkNotNullParameter(response, "response");
|
|
super.onOpen(webSocket, response);
|
|
m(new k(this, webSocket));
|
|
}
|
|
}
|