智慧城市 v1.2.1版本的 MD5 值为:d4aeacb5153a2710d0b6882be5dd2b15
以下内容为反编译后的 RongRtcStatMagr.java 源代码,内容仅作参考
package cn.rongcloud.rtc.stat;
import android.os.Build;
import android.os.HandlerThread;
import android.text.TextUtils;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
import cn.rongcloud.rtc.base.RCRTCLiveRole;
import cn.rongcloud.rtc.base.RCRTCMediaType;
import cn.rongcloud.rtc.base.RTCErrorCode;
import cn.rongcloud.rtc.core.MediaStream;
import cn.rongcloud.rtc.core.MediaStreamTrack;
import cn.rongcloud.rtc.engine.RTCEngineImpl;
import cn.rongcloud.rtc.signal.SignalManager;
import cn.rongcloud.rtc.utils.DeviceUtils;
import cn.rongcloud.rtc.utils.FinLog;
import cn.rongcloud.rtc.webrtc.IStreamResource;
import cn.rongcloud.rtc.webrtc.RTCConnectionHolder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public enum RongRtcStatMagr {
instance;
private static final String TAG = "RongRtcStatMagr";
public static final int WHAT_ADD_PUBLISH = 1;
public static final int WHAT_ADD_RECEIVE = 3;
public static final int WHAT_RELEASE = 5;
public static final int WHAT_REMOVE_PUBLISH = 2;
public static final int WHAT_REMOVE_RECEIVE = 4;
private RTCConnectionHolder mConnectionHolder;
private StatHandler mHandler;
private RCRTCLiveRole mRole;
private String mRoomId;
public void addPublish(List<RongRtcStatForm> list) {
sendMsg(1, list);
}
public void addReceive(List<RongRtcStatForm> list) {
sendMsg(3, list);
}
public void removePublish(List<String> list) {
sendMsg(2, list);
}
public void removeReceive(List<String> list) {
sendMsg(4, list);
}
public String getRoomId() {
return this.mRoomId;
}
public void start(String str, RCRTCLiveRole rCRTCLiveRole) {
this.mRoomId = str;
this.mRole = rCRTCLiveRole;
if (TextUtils.isEmpty(str)) {
return;
}
reportR1();
}
public void setRTCConnectionHolder(RTCConnectionHolder rTCConnectionHolder) {
this.mConnectionHolder = rTCConnectionHolder;
StatHandler statHandler = this.mHandler;
if (statHandler != null) {
statHandler.setRTCConnectionHolder(rTCConnectionHolder);
}
}
public void release() {
StatHandler statHandler = this.mHandler;
if (statHandler != null) {
statHandler.sendEmptyMessage(5);
this.mHandler.getLooper().quitSafely();
}
this.mHandler = null;
this.mRoomId = null;
this.mConnectionHolder = null;
}
private void sendMsg(int i, Object obj) {
if (TextUtils.isEmpty(this.mRoomId)) {
FinLog.e(TAG, "sendMsg RoomId is Null, what=" + i);
return;
}
if (this.mHandler == null) {
HandlerThread handlerThread = new HandlerThread(TAG);
handlerThread.start();
StatHandler statHandler = new StatHandler(handlerThread.getLooper(), this.mRoomId, this.mRole);
this.mHandler = statHandler;
RTCConnectionHolder rTCConnectionHolder = this.mConnectionHolder;
if (rTCConnectionHolder != null) {
statHandler.setRTCConnectionHolder(rTCConnectionHolder);
}
}
this.mHandler.obtainMessage(i, obj).sendToTarget();
}
public void reportR1() {
setRTCUserState("R1\t5.1.7.1\t5.1.3\tAndroid\t" + Build.BRAND + DeviceUtils.getBuildModel() + "\t" + Build.VERSION.RELEASE + "\t-1\t-1\t" + RTCEngineImpl.getInstance().getClientId() + "\t" + this.mRole.getType());
}
public void reportSubscribe(Map<MediaStream, MediaStreamTrack> map) {
if (map == null || map.isEmpty()) {
return;
}
ArrayList arrayList = new ArrayList(map.size());
Set<MediaStream> keySet = map.keySet();
ArrayList arrayList2 = new ArrayList();
for (MediaStream mediaStream : keySet) {
RongRtcStatForm rongRtcStatForm = new RongRtcStatForm(map.get(mediaStream).id(), mediaStream.getId(), RCRTCMediaType.VIDEO.getDescription().equalsIgnoreCase(map.get(mediaStream).kind()) ? RCRTCMediaType.VIDEO : RCRTCMediaType.AUDIO);
arrayList2.add(rongRtcStatForm);
arrayList.add(rongRtcStatForm.trackId);
}
onReportR2(true, true, arrayList);
addReceive(arrayList2);
}
public void reportSubStream(String str, String str2, RCRTCMediaType rCRTCMediaType) {
RongRtcStatForm rongRtcStatForm = new RongRtcStatForm(str, str2, rCRTCMediaType);
ArrayList arrayList = new ArrayList();
arrayList.add(rongRtcStatForm);
ArrayList arrayList2 = new ArrayList();
arrayList2.add(str);
onReportR2(true, true, arrayList2);
addReceive(arrayList);
}
public void reportSubscribe(List<RongRtcStatForm> list) {
ArrayList arrayList = new ArrayList();
for (RongRtcStatForm rongRtcStatForm : list) {
arrayList.add(rongRtcStatForm.trackId);
}
onReportR2(true, true, arrayList);
addReceive(list);
}
public void reportUnSubscribe(List<? extends IStreamResource> list) {
List<String> parseRongRTCStream = parseRongRTCStream(true, false, list);
if (parseRongRTCStream != null) {
removeReceive(parseRongRTCStream);
}
}
public void reportPublish(boolean z, List<? extends IStreamResource> list) {
List<String> parseRongRTCStream = parseRongRTCStream(false, z, list);
if (parseRongRTCStream != null) {
if (z) {
ArrayList arrayList = new ArrayList();
for (IStreamResource iStreamResource : list) {
arrayList.add(new RongRtcStatForm(iStreamResource.getStreamId(), iStreamResource.getMediaType()));
}
addPublish(arrayList);
return;
}
removePublish(parseRongRTCStream);
}
}
private List<String> parseRongRTCStream(boolean z, boolean z2, List<? extends IStreamResource> list) {
if (list == null || list.isEmpty()) {
return null;
}
ArrayList arrayList = new ArrayList();
for (IStreamResource iStreamResource : list) {
arrayList.add(iStreamResource.getStreamId() + "_" + iStreamResource.getMediaType().getDescription());
}
onReportR2(z, z2, arrayList);
return arrayList;
}
private void onReportR2(boolean z, boolean z2, List<String> list) {
if (list == null || list.isEmpty()) {
return;
}
if (TextUtils.isEmpty(this.mRoomId)) {
FinLog.e(TAG, "reportR2 RoomId is Null");
return;
}
StringBuilder sb = new StringBuilder();
sb.append("R2");
sb.append("\t");
sb.append(z ? "subscribe" : "publish");
sb.append("\t");
sb.append(z2 ? "begin" : "end");
sb.append("\r");
for (String str : list) {
sb.append(str);
sb.append("\t");
}
sb.deleteCharAt(sb.length() - 1);
sb.append("\r");
sb.append(this.mRole.getType());
setRTCUserState(sb.toString());
}
private void setRTCUserState(String str) {
SignalManager.getInstance().setRTCUserState(this.mRoomId, str, new IRCRTCResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFailed(RTCErrorCode rTCErrorCode) {
FinLog.e(RongRtcStatMagr.TAG, "setRTCUserState Failed: " + rTCErrorCode.getValue());
}
});
}
}