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

545 lines
25 KiB
Java

package com.discord.stores;
import c.a.r.j;
import c.a.r.w;
import c.d.b.a.a;
import com.discord.app.App;
import com.discord.app.AppLog;
import com.discord.models.domain.ModelApplicationStream;
import com.discord.models.domain.ModelPayload;
import com.discord.models.domain.StreamCreateOrUpdate;
import com.discord.models.domain.StreamServerUpdate;
import com.discord.rtcconnection.MediaSinkWantsManager;
import com.discord.rtcconnection.RtcConnection;
import com.discord.rtcconnection.VideoMetadata;
import com.discord.rtcconnection.mediaengine.MediaEngine;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import com.discord.utilities.debug.DebugPrintBuilder;
import com.discord.utilities.debug.DebugPrintable;
import com.discord.utilities.debug.DebugPrintableCollection;
import com.discord.utilities.logging.Logger;
import com.discord.utilities.networking.NetworkMonitor;
import com.discord.utilities.ssl.SecureSocketsLayerUtils;
import com.discord.utilities.systemlog.SystemLogUtils;
import com.discord.utilities.time.Clock;
import d0.z.d.m;
import java.util.Map;
import javax.net.ssl.SSLSocketFactory;
import kotlin.NoWhenBranchMatchedException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreStreamRtcConnection.kt */
public final class StoreStreamRtcConnection extends StoreV2 implements DebugPrintable {
public static final Companion Companion = new Companion(null);
public static final float MAX_STREAM_VOLUME = 300.0f;
private static int instanceCounter;
private final StoreAnalytics analyticsStore;
private final Clock clock;
private final long debugDisplayId;
private final Dispatcher dispatcher;
private final DebugPrintableCollection dpc;
private final Logger logger;
private final String loggingTag;
private final StoreMediaEngine mediaEngineStore;
private NetworkMonitor networkMonitor;
private final ObservationDeck observationDeck;
private RtcConnection rtcConnection;
private String sessionId;
private State state;
private final StoreRtcConnection storeRtcConnection;
private final StoreStream storeStream;
private Long streamOwner;
private float streamVolume;
private final StoreUser userStore;
/* compiled from: StoreStreamRtcConnection.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: StoreStreamRtcConnection.kt */
public final class RtcConnectionListener extends RtcConnection.b {
public final /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
RtcConnection.AnalyticsEvent.values();
int[] iArr = new int[5];
$EnumSwitchMapping$0 = iArr;
iArr[RtcConnection.AnalyticsEvent.VIDEO_STREAM_ENDED.ordinal()] = 1;
iArr[RtcConnection.AnalyticsEvent.MEDIA_SESSION_JOINED.ordinal()] = 2;
}
}
public RtcConnectionListener() {
}
@Override // com.discord.rtcconnection.RtcConnection.b, com.discord.rtcconnection.RtcConnection.c
public void onAnalyticsEvent(RtcConnection.AnalyticsEvent analyticsEvent, Map<String, Object> map) {
m.checkNotNullParameter(analyticsEvent, "event");
m.checkNotNullParameter(map, "properties");
int ordinal = analyticsEvent.ordinal();
if (ordinal == 3) {
StoreStreamRtcConnection.access$getDispatcher$p(StoreStreamRtcConnection.this).schedule(new StoreStreamRtcConnection$RtcConnectionListener$onAnalyticsEvent$1(this, map));
} else if (ordinal == 4) {
StoreStreamRtcConnection.access$getAnalyticsStore$p(StoreStreamRtcConnection.this).trackMediaSessionJoined(map);
}
}
@Override // com.discord.rtcconnection.RtcConnection.b, com.discord.rtcconnection.RtcConnection.c
public void onMediaSessionIdReceived() {
StoreStreamRtcConnection.access$getDispatcher$p(StoreStreamRtcConnection.this).schedule(new StoreStreamRtcConnection$RtcConnectionListener$onMediaSessionIdReceived$1(this));
}
@Override // com.discord.rtcconnection.RtcConnection.b, com.discord.rtcconnection.RtcConnection.c
public void onQualityUpdate(RtcConnection.Quality quality) {
m.checkNotNullParameter(quality, "quality");
StoreStreamRtcConnection.access$getDispatcher$p(StoreStreamRtcConnection.this).schedule(new StoreStreamRtcConnection$RtcConnectionListener$onQualityUpdate$1(this, quality));
}
@Override // com.discord.rtcconnection.RtcConnection.b, com.discord.rtcconnection.RtcConnection.c
public void onStateChange(RtcConnection.StateChange stateChange) {
m.checkNotNullParameter(stateChange, "stateChange");
StoreStreamRtcConnection.access$getDispatcher$p(StoreStreamRtcConnection.this).schedule(new StoreStreamRtcConnection$RtcConnectionListener$onStateChange$1(this, stateChange));
}
@Override // com.discord.rtcconnection.RtcConnection.b, com.discord.rtcconnection.RtcConnection.c
public void onVideoMetadata(VideoMetadata videoMetadata) {
m.checkNotNullParameter(videoMetadata, "metadata");
StoreStreamRtcConnection.access$getDispatcher$p(StoreStreamRtcConnection.this).schedule(new StoreStreamRtcConnection$RtcConnectionListener$onVideoMetadata$1(this, videoMetadata));
}
@Override // com.discord.rtcconnection.RtcConnection.b, com.discord.rtcconnection.RtcConnection.c
public void onVideoStream(long j, Integer num) {
StoreStreamRtcConnection.access$getDispatcher$p(StoreStreamRtcConnection.this).schedule(new StoreStreamRtcConnection$RtcConnectionListener$onVideoStream$1(this, j, num));
}
}
/* compiled from: StoreStreamRtcConnection.kt */
public static final class State {
private final RtcConnection.Quality connectionQuality;
private final String mediaSessionId;
private final RtcConnection rtcConnection;
private final RtcConnection.State rtcConnectionState;
public State(RtcConnection.State state, RtcConnection.Quality quality, String str, RtcConnection rtcConnection) {
m.checkNotNullParameter(state, "rtcConnectionState");
this.rtcConnectionState = state;
this.connectionQuality = quality;
this.mediaSessionId = str;
this.rtcConnection = rtcConnection;
}
public static /* synthetic */ State copy$default(State state, RtcConnection.State state2, RtcConnection.Quality quality, String str, RtcConnection rtcConnection, int i, Object obj) {
if ((i & 1) != 0) {
state2 = state.rtcConnectionState;
}
if ((i & 2) != 0) {
quality = state.connectionQuality;
}
if ((i & 4) != 0) {
str = state.mediaSessionId;
}
if ((i & 8) != 0) {
rtcConnection = state.rtcConnection;
}
return state.copy(state2, quality, str, rtcConnection);
}
public final RtcConnection.State component1() {
return this.rtcConnectionState;
}
public final RtcConnection.Quality component2() {
return this.connectionQuality;
}
public final String component3() {
return this.mediaSessionId;
}
public final RtcConnection component4() {
return this.rtcConnection;
}
public final State copy(RtcConnection.State state, RtcConnection.Quality quality, String str, RtcConnection rtcConnection) {
m.checkNotNullParameter(state, "rtcConnectionState");
return new State(state, quality, str, rtcConnection);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof State)) {
return false;
}
State state = (State) obj;
return m.areEqual(this.rtcConnectionState, state.rtcConnectionState) && m.areEqual(this.connectionQuality, state.connectionQuality) && m.areEqual(this.mediaSessionId, state.mediaSessionId) && m.areEqual(this.rtcConnection, state.rtcConnection);
}
public final RtcConnection.Quality getConnectionQuality() {
return this.connectionQuality;
}
public final String getMediaSessionId() {
return this.mediaSessionId;
}
public final RtcConnection getRtcConnection() {
return this.rtcConnection;
}
public final RtcConnection.State getRtcConnectionState() {
return this.rtcConnectionState;
}
public int hashCode() {
RtcConnection.State state = this.rtcConnectionState;
int i = 0;
int hashCode = (state != null ? state.hashCode() : 0) * 31;
RtcConnection.Quality quality = this.connectionQuality;
int hashCode2 = (hashCode + (quality != null ? quality.hashCode() : 0)) * 31;
String str = this.mediaSessionId;
int hashCode3 = (hashCode2 + (str != null ? str.hashCode() : 0)) * 31;
RtcConnection rtcConnection = this.rtcConnection;
if (rtcConnection != null) {
i = rtcConnection.hashCode();
}
return hashCode3 + i;
}
public String toString() {
StringBuilder L = a.L("State(rtcConnectionState=");
L.append(this.rtcConnectionState);
L.append(", connectionQuality=");
L.append(this.connectionQuality);
L.append(", mediaSessionId=");
L.append(this.mediaSessionId);
L.append(", rtcConnection=");
L.append(this.rtcConnection);
L.append(")");
return L.toString();
}
}
public StoreStreamRtcConnection(StoreMediaEngine storeMediaEngine, StoreUser storeUser, StoreStream storeStream, Dispatcher dispatcher, Clock clock, StoreAnalytics storeAnalytics, StoreRtcConnection storeRtcConnection, ObservationDeck observationDeck, Logger logger, DebugPrintableCollection debugPrintableCollection) {
m.checkNotNullParameter(storeMediaEngine, "mediaEngineStore");
m.checkNotNullParameter(storeUser, "userStore");
m.checkNotNullParameter(storeStream, "storeStream");
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(clock, "clock");
m.checkNotNullParameter(storeAnalytics, "analyticsStore");
m.checkNotNullParameter(storeRtcConnection, "storeRtcConnection");
m.checkNotNullParameter(observationDeck, "observationDeck");
m.checkNotNullParameter(logger, "logger");
m.checkNotNullParameter(debugPrintableCollection, "dpc");
this.mediaEngineStore = storeMediaEngine;
this.userStore = storeUser;
this.storeStream = storeStream;
this.dispatcher = dispatcher;
this.clock = clock;
this.analyticsStore = storeAnalytics;
this.storeRtcConnection = storeRtcConnection;
this.observationDeck = observationDeck;
this.logger = logger;
this.dpc = debugPrintableCollection;
this.state = new State(new RtcConnection.State.d(false), null, null, this.rtcConnection);
this.streamVolume = 300.0f;
StringBuilder L = a.L("StoreStreamRtcConnection ");
int i = instanceCounter + 1;
instanceCounter = i;
L.append(i);
String sb = L.toString();
this.loggingTag = sb;
this.debugDisplayId = debugPrintableCollection.add(this, sb);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreStreamRtcConnection(StoreMediaEngine storeMediaEngine, StoreUser storeUser, StoreStream storeStream, Dispatcher dispatcher, Clock clock, StoreAnalytics storeAnalytics, StoreRtcConnection storeRtcConnection, ObservationDeck observationDeck, Logger logger, DebugPrintableCollection debugPrintableCollection, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(storeMediaEngine, storeUser, storeStream, dispatcher, clock, storeAnalytics, storeRtcConnection, (i & 128) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 256) != 0 ? AppLog.g : logger, (i & 512) != 0 ? SystemLogUtils.INSTANCE.getDebugPrintables$app_productionBetaRelease() : debugPrintableCollection);
}
public static final /* synthetic */ StoreAnalytics access$getAnalyticsStore$p(StoreStreamRtcConnection storeStreamRtcConnection) {
return storeStreamRtcConnection.analyticsStore;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreStreamRtcConnection storeStreamRtcConnection) {
return storeStreamRtcConnection.dispatcher;
}
public static final /* synthetic */ RtcConnection access$getRtcConnection$p(StoreStreamRtcConnection storeStreamRtcConnection) {
return storeStreamRtcConnection.rtcConnection;
}
public static final /* synthetic */ StoreStream access$getStoreStream$p(StoreStreamRtcConnection storeStreamRtcConnection) {
return storeStreamRtcConnection.storeStream;
}
public static final /* synthetic */ Long access$getStreamOwner$p(StoreStreamRtcConnection storeStreamRtcConnection) {
return storeStreamRtcConnection.streamOwner;
}
public static final /* synthetic */ float access$getStreamVolume$p(StoreStreamRtcConnection storeStreamRtcConnection) {
return storeStreamRtcConnection.streamVolume;
}
public static final /* synthetic */ void access$handleMediaSessionIdReceived(StoreStreamRtcConnection storeStreamRtcConnection) {
storeStreamRtcConnection.handleMediaSessionIdReceived();
}
public static final /* synthetic */ void access$handleQualityUpdate(StoreStreamRtcConnection storeStreamRtcConnection, RtcConnection.Quality quality) {
storeStreamRtcConnection.handleQualityUpdate(quality);
}
public static final /* synthetic */ void access$handleVideoStreamEndedAnalyticsEvent(StoreStreamRtcConnection storeStreamRtcConnection, Map map) {
storeStreamRtcConnection.handleVideoStreamEndedAnalyticsEvent(map);
}
public static final /* synthetic */ void access$setRtcConnection$p(StoreStreamRtcConnection storeStreamRtcConnection, RtcConnection rtcConnection) {
storeStreamRtcConnection.rtcConnection = rtcConnection;
}
public static final /* synthetic */ void access$setStreamOwner$p(StoreStreamRtcConnection storeStreamRtcConnection, Long l) {
storeStreamRtcConnection.streamOwner = l;
}
public static final /* synthetic */ void access$setStreamVolume$p(StoreStreamRtcConnection storeStreamRtcConnection, float f) {
storeStreamRtcConnection.streamVolume = f;
}
@StoreThread
private final RtcConnection createRtcConnection(long j, Long l, long j2, String str, String str2, long j3, String str3) {
destroyRtcConnection();
RtcConnection.Metadata rtcConnectionMetadata = this.storeRtcConnection.getRtcConnectionMetadata();
String str4 = null;
Long l2 = rtcConnectionMetadata != null ? rtcConnectionMetadata.f2085c : null;
if (l2 != null && l2.longValue() == j2) {
str4 = rtcConnectionMetadata.b;
}
MediaEngine mediaEngine = this.mediaEngineStore.getMediaEngine();
Logger logger = this.logger;
Clock clock = this.clock;
RtcConnection.d.b bVar = new RtcConnection.d.b(j3);
NetworkMonitor networkMonitor = this.networkMonitor;
if (networkMonitor == null) {
m.throwUninitializedPropertyAccessException("networkMonitor");
}
RtcConnection rtcConnection = new RtcConnection(l, j2, str, true, str2, j, mediaEngine, logger, clock, bVar, networkMonitor, null, null, str4, false, this.loggingTag, str3, 6144);
rtcConnection.c(new RtcConnectionListener());
return rtcConnection;
}
@StoreThread
private final void destroyRtcConnection() {
if (this.rtcConnection != null) {
recordBreadcrumb("destroying stream rtc connection");
updateRtcConnection(null);
this.state = State.copy$default(this.state, null, null, null, null, 9, null);
markChanged();
}
}
@StoreThread
private final void handleMediaSessionIdReceived() {
RtcConnection rtcConnection = this.rtcConnection;
this.state = State.copy$default(this.state, null, null, rtcConnection != null ? rtcConnection.H : null, null, 11, null);
markChanged();
}
@StoreThread
private final void handleQualityUpdate(RtcConnection.Quality quality) {
this.state = State.copy$default(this.state, null, quality, null, null, 13, null);
markChanged();
}
@StoreThread
private final void handleVideoStreamEndedAnalyticsEvent(Map<String, Object> map) {
this.analyticsStore.trackVideoStreamEnded(map);
}
private final void loge(String str, Throwable th, Map<String, String> map) {
this.logger.e(this.loggingTag, str, th, map);
}
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: com.discord.stores.StoreStreamRtcConnection */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void loge$default(StoreStreamRtcConnection storeStreamRtcConnection, String str, Throwable th, Map map, int i, Object obj) {
if ((i & 2) != 0) {
th = null;
}
if ((i & 4) != 0) {
map = null;
}
storeStreamRtcConnection.loge(str, th, map);
}
private final void logi(String str, Throwable th) {
this.logger.i(this.loggingTag, str, th);
}
public static /* synthetic */ void logi$default(StoreStreamRtcConnection storeStreamRtcConnection, String str, Throwable th, int i, Object obj) {
if ((i & 2) != 0) {
th = null;
}
storeStreamRtcConnection.logi(str, th);
}
private final void logw(String str) {
Logger.w$default(this.logger, this.loggingTag, str, null, 4, null);
}
private final void recordBreadcrumb(String str) {
this.logger.recordBreadcrumb(str, this.loggingTag);
}
@StoreThread
private final void updateRtcConnection(RtcConnection rtcConnection) {
RtcConnection rtcConnection2 = this.rtcConnection;
if (rtcConnection2 != null) {
rtcConnection2.e();
}
this.rtcConnection = rtcConnection;
this.state = State.copy$default(this.state, null, null, null, rtcConnection, 7, null);
markChanged();
}
@Override // com.discord.utilities.debug.DebugPrintable
public void debugPrint(DebugPrintBuilder debugPrintBuilder) {
m.checkNotNullParameter(debugPrintBuilder, "dp");
debugPrintBuilder.appendKeyValue("sessionId", this.sessionId);
debugPrintBuilder.appendKeyValue("streamOwner", this.streamOwner);
debugPrintBuilder.appendKeyValue("streamVolume", Float.valueOf(this.streamVolume));
debugPrintBuilder.appendKeyValue("state", this.state);
debugPrintBuilder.appendKeyValue("rtcConnection", (DebugPrintable) this.rtcConnection);
}
public final void finalize() {
this.dpc.remove(this.debugDisplayId);
}
public final State getState() {
return this.state;
}
public final float getStreamVolume() {
return this.streamVolume;
}
@StoreThread
public final void handleConnectionOpen(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
this.sessionId = modelPayload.getSessionId();
}
@StoreThread
public final void handleStreamCreate(StreamCreateOrUpdate streamCreateOrUpdate) {
Long l;
m.checkNotNullParameter(streamCreateOrUpdate, "streamCreate");
ModelApplicationStream decodeStreamKey = ModelApplicationStream.Companion.decodeStreamKey(streamCreateOrUpdate.getStreamKey());
long id2 = this.userStore.getMeInternal$app_productionBetaRelease().getId();
String str = this.sessionId;
if (str != null) {
RtcConnection rtcConnection = this.rtcConnection;
if (rtcConnection != null && rtcConnection.M == decodeStreamKey.getChannelId()) {
RtcConnection rtcConnection2 = this.rtcConnection;
if (m.areEqual(rtcConnection2 != null ? rtcConnection2.N : null, str)) {
return;
}
}
if (decodeStreamKey instanceof ModelApplicationStream.GuildStream) {
l = Long.valueOf(((ModelApplicationStream.GuildStream) decodeStreamKey).getGuildId());
} else if (decodeStreamKey instanceof ModelApplicationStream.CallStream) {
l = null;
} else {
throw new NoWhenBranchMatchedException();
}
long channelId = decodeStreamKey.getChannelId();
String rtcServerId = streamCreateOrUpdate.getRtcServerId();
m.checkNotNull(rtcServerId);
updateRtcConnection(createRtcConnection(id2, l, channelId, str, rtcServerId, decodeStreamKey.getOwnerId(), streamCreateOrUpdate.getStreamKey()));
this.streamOwner = Long.valueOf(decodeStreamKey.getOwnerId());
}
}
@StoreThread
public final void handleStreamDelete() {
RtcConnection rtcConnection = this.rtcConnection;
if (rtcConnection != null) {
rtcConnection.t(null, null);
}
destroyRtcConnection();
this.streamOwner = null;
}
@StoreThread
public final void handleStreamRtcConnectionStateChange(RtcConnection.State state) {
Long l;
m.checkNotNullParameter(state, "state");
if (m.areEqual(state, RtcConnection.State.f.a) && (l = this.streamOwner) != null) {
long longValue = l.longValue();
RtcConnection rtcConnection = this.rtcConnection;
if (rtcConnection != null) {
rtcConnection.v(longValue, this.streamVolume);
}
}
this.state = State.copy$default(this.state, state, null, null, null, 12, null);
markChanged();
}
@StoreThread
public final void handleStreamServerUpdate(StreamServerUpdate streamServerUpdate) {
m.checkNotNullParameter(streamServerUpdate, "streamServerUpdate");
App.a aVar = App.j;
SSLSocketFactory sSLSocketFactory = null;
if (!App.i) {
sSLSocketFactory = SecureSocketsLayerUtils.createSocketFactory$default(null, 1, null);
}
StringBuilder L = a.L("Voice stream update, connect to server w/ endpoint: ");
L.append(streamServerUpdate.getEndpoint());
recordBreadcrumb(L.toString());
RtcConnection rtcConnection = this.rtcConnection;
if (rtcConnection == null) {
loge$default(this, "handleStreamServerUpdate() rtcConnection is null.", null, null, 6, null);
} else {
rtcConnection.s(new w(rtcConnection, streamServerUpdate.getEndpoint(), streamServerUpdate.getToken(), sSLSocketFactory));
}
}
public final void init(NetworkMonitor networkMonitor) {
m.checkNotNullParameter(networkMonitor, "networkMonitor");
this.networkMonitor = networkMonitor;
}
public final Observable<RtcConnection.Quality> observeConnectionQuality() {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStreamRtcConnection$observeConnectionQuality$1(this), 14, null);
}
public final Observable<RtcConnection> observeRtcConnection() {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStreamRtcConnection$observeRtcConnection$1(this), 14, null);
}
public final Observable<Float> observeStreamVolume() {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreStreamRtcConnection$observeStreamVolume$1(this), 14, null);
}
public final void updateFocusedParticipant(Long l) {
MediaSinkWantsManager mediaSinkWantsManager;
RtcConnection rtcConnection = this.rtcConnection;
if (rtcConnection != null && (mediaSinkWantsManager = rtcConnection.E) != null) {
mediaSinkWantsManager.b(new j(mediaSinkWantsManager, l));
}
}
public final void updateStreamVolume(float f) {
this.dispatcher.schedule(new StoreStreamRtcConnection$updateStreamVolume$1(this, f));
}
}