瀏覽代碼

Fixed local and remote address getters with libjuice

Paul-Louis Ageneau 5 年之前
父節點
當前提交
3f52aa3d56
共有 2 個文件被更改,包括 14 次插入2 次删除
  1. 5 2
      src/icetransport.cpp
  2. 9 0
      test/main.cpp

+ 5 - 2
src/icetransport.cpp

@@ -135,14 +135,16 @@ void IceTransport::gatherLocalCandidates() {
 
 std::optional<string> IceTransport::getLocalAddress() const {
 	char str[JUICE_MAX_ADDRESS_STRING_LEN];
-	if (juice_get_selected_addresses(mAgent.get(), str, JUICE_MAX_ADDRESS_STRING_LEN, NULL, 0)) {
+	if (juice_get_selected_addresses(mAgent.get(), str, JUICE_MAX_ADDRESS_STRING_LEN, NULL, 0) ==
+	    0) {
 		return std::make_optional(string(str));
 	}
 	return nullopt;
 }
 std::optional<string> IceTransport::getRemoteAddress() const {
 	char str[JUICE_MAX_ADDRESS_STRING_LEN];
-	if (juice_get_selected_addresses(mAgent.get(), NULL, 0, str, JUICE_MAX_ADDRESS_STRING_LEN)) {
+	if (juice_get_selected_addresses(mAgent.get(), NULL, 0, str, JUICE_MAX_ADDRESS_STRING_LEN) ==
+	    0) {
 		return std::make_optional(string(str));
 	}
 	return nullopt;
@@ -495,6 +497,7 @@ std::optional<string> IceTransport::getLocalAddress() const {
 	}
 	return nullopt;
 }
+
 std::optional<string> IceTransport::getRemoteAddress() const {
 	NiceCandidate *local = nullptr;
 	NiceCandidate *remote = nullptr;

+ 9 - 0
test/main.cpp

@@ -113,6 +113,15 @@ int main(int argc, char **argv) {
 
 	this_thread::sleep_for(3s);
 
+	if (auto addr = pc1->localAddress())
+		cout << "Local address 1:  " << *addr << endl;
+	if (auto addr = pc1->remoteAddress())
+		cout << "Remote address 1: " << *addr << endl;
+	if (auto addr = pc2->localAddress())
+		cout << "Local address 2:  " << *addr << endl;
+	if (auto addr = pc2->remoteAddress())
+		cout << "Remote address 2: " << *addr << endl;
+
 	if (dc1->isOpen() && dc2->isOpen()) {
 		pc1->close();
 		pc2->close();