Browse Source

Added rtcGetRemoteDescription() for the sake of completeness

Paul-Louis Ageneau 4 years ago
parent
commit
cbc027f144
2 changed files with 24 additions and 0 deletions
  1. 1 0
      include/rtc/rtc.h
  2. 23 0
      src/capi.cpp

+ 1 - 0
include/rtc/rtc.h

@@ -122,6 +122,7 @@ RTC_EXPORT int rtcSetRemoteDescription(int pc, const char *sdp, const char *type
 RTC_EXPORT int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
 
 RTC_EXPORT int rtcGetLocalDescription(int pc, char *buffer, int size);
+RTC_EXPORT int rtcGetRemoteDescription(int pc, char *buffer, int size);
 
 RTC_EXPORT int rtcGetLocalAddress(int pc, char *buffer, int size);
 RTC_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size);

+ 23 - 0
src/capi.cpp

@@ -552,6 +552,29 @@ int rtcGetLocalDescription(int pc, char *buffer, int size) {
 	});
 }
 
+int rtcGetRemoteDescription(int pc, char *buffer, int size) {
+	return WRAP({
+		auto peerConnection = getPeerConnection(pc);
+
+		if (size <= 0)
+			return 0;
+
+		if (!buffer)
+			throw std::invalid_argument("Unexpected null pointer for buffer");
+
+		if (auto desc = peerConnection->remoteDescription()) {
+			auto sdp = string(*desc);
+			const char *data = sdp.data();
+			size = std::min(size - 1, int(sdp.size()));
+			std::copy(data, data + size, buffer);
+			buffer[size] = '\0';
+			return size + 1;
+		}
+
+		return RTC_ERR_FAILURE;
+	});
+}
+
 int rtcGetLocalAddress(int pc, char *buffer, int size) {
 	return WRAP({
 		auto peerConnection = getPeerConnection(pc);