Skip to content

Commit

Permalink
android,ios: don't reject promise for getStats (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidliu committed Apr 10, 2024
1 parent a5112e1 commit 5d85486
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ public void receiverGetStats(String receiverId, Promise promise) {

public void senderGetStats(String senderId, Promise promise) {
RtpSender targetSender = null;
for (RtpSender r : peerConnection.getSenders()) {
if (r.id().equals(senderId)) {
targetSender = r;
for (RtpSender s : peerConnection.getSenders()) {
if (s.id().equals(senderId)) {
targetSender = s;
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ public void receiverGetStats(int pcId, String receiverId, Promise promise) {
PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
if (pco == null || pco.getPeerConnection() == null) {
Log.d(TAG, "receiverGetStats() peerConnection is null");
promise.reject(new Exception("PeerConnection ID not found"));
promise.resolve(StringUtils.statsToJSON(new RTCStatsReport(0, new HashMap<>())));
} else {
pco.receiverGetStats(receiverId, promise);
}
Expand All @@ -1258,7 +1258,7 @@ public void senderGetStats(int pcId, String senderId, Promise promise) {
PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
if (pco == null || pco.getPeerConnection() == null) {
Log.d(TAG, "senderGetStats() peerConnection is null");
promise.reject(new Exception("PeerConnection ID not found"));
promise.resolve(StringUtils.statsToJSON(new RTCStatsReport(0, new HashMap<>())));
} else {
pco.senderGetStats(senderId, promise);
}
Expand Down Expand Up @@ -1311,7 +1311,7 @@ public void peerConnectionGetStats(int peerConnectionId, Promise promise) {
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
if (pco == null || pco.getPeerConnection() == null) {
Log.d(TAG, "peerConnectionGetStats() peerConnection is null");
promise.reject(new Exception("PeerConnection ID not found"));
promise.resolve(StringUtils.statsToJSON(new RTCStatsReport(0, new HashMap<>())));
} else {
pco.getStats(promise);
}
Expand Down
15 changes: 10 additions & 5 deletions ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ @implementation WebRTCModule (RTCPeerConnection)
: (RCTPromiseRejectBlock)reject) {
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
if (!peerConnection) {
reject(@"invalid_id", @"PeerConnection ID not found", nil);
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionGetStats()", objectID);
resolve(@"[]");
return;
}

Expand All @@ -370,7 +371,8 @@ @implementation WebRTCModule (RTCPeerConnection)
: (RCTPromiseRejectBlock)reject) {
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
if (!peerConnection) {
reject(@"invalid_id", @"PeerConnection ID not found", nil);
RCTLogWarn(@"PeerConnection %@ not found in receiverGetStats()", pcId);
resolve(@"[]");
return;
}

Expand All @@ -383,7 +385,8 @@ @implementation WebRTCModule (RTCPeerConnection)
}

if (!receiver) {
reject(@"invalid_id", @"Receiver ID not found", nil);
RCTLogWarn(@"RTCRtpReceiver %@ not found in receiverGetStats()", receiverId);
resolve(@"[]");
return;
}

Expand All @@ -400,7 +403,8 @@ @implementation WebRTCModule (RTCPeerConnection)
: (RCTPromiseRejectBlock)reject) {
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
if (!peerConnection) {
reject(@"invalid_id", @"PeerConnection ID not found", nil);
RCTLogWarn(@"PeerConnection %@ not found in senderGetStats()", pcId);
resolve(@"[]");
return;
}

Expand All @@ -413,7 +417,8 @@ @implementation WebRTCModule (RTCPeerConnection)
}

if (!sender) {
reject(@"invalid_id", @"Sender ID not found", nil);
RCTLogWarn(@"RTCRtpSender %@ not found in senderGetStats()", senderId);
resolve(@"[]");
return;
}

Expand Down

0 comments on commit 5d85486

Please sign in to comment.