8000 fix: fix unable to get username/credential when parsing iceServers co… · sujeking/flutter-webrtc@9ea1e85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ea1e85

Browse files
committed
fix: fix unable to get username/credential when parsing iceServers containing urls
1 parent 7d1b135 commit 9ea1e85

File tree

1 file changed

+15
-49
lines changed

1 file changed

+15
-49
lines changed

common/cpp/src/flutter_webrtc_base.cc

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -175,43 +175,24 @@ bool FlutterWebRTCBase::CreateIceServers(const EncodableList &iceServersArray,
175175
for (size_t i = 0; i < size; i++) {
176176
IceServer &ice_server = ice_servers[i];
177177
EncodableMap iceServerMap = GetValue<EncodableMap>(iceServersArray[i]);
178-
bool hasUsernameAndCredential =
179-
iceServerMap.find(EncodableValue("username")) != iceServerMap.end() &&
180-
iceServerMap.find(EncodableValue("credential")) != iceServerMap.end();
178+
179+
if (iceServerMap.find(EncodableValue("username")) != iceServerMap.end()) {;
180+
ice_server.username = GetValue<std::string>(
181+
iceServerMap.find(EncodableValue("username"))->second);
182+
}
183+
if (iceServerMap.find(EncodableValue("credential")) != iceServerMap.end()) {
184+
ice_server.password = GetValue<std::string>(
185+
iceServerMap.find(EncodableValue("credential"))->second);
186+
}
187+
181188
auto it = iceServerMap.find(EncodableValue("url"));
182189
if (it != iceServerMap.end() && TypeIs<std::string>(it->second)) {
183-
if (hasUsernameAndCredential) {
184-
std::string username =
185-
GetValue<std::string>(iceServerMap.find(EncodableValue("username"))->second);
186-
std::string credential =
187-
GetValue<std::string>(iceServerMap.find(EncodableValue("credential"))
188-
->second);
189-
std::string uri = GetValue<std::string>(it->second);
190-
ice_server.username = username;
191-
ice_server.password = credential;
192-
ice_server.uri = uri;
193-
} else {
194-
std::string uri = GetValue<std::string>(it->second);
195-
ice_server.uri = uri;
196-
}
190+
ice_server.uri = GetValue<std::string>(it->second);
197191
}
198192
it = iceServerMap.find(EncodableValue("urls"));
199193
if (it != iceServerMap.end()) {
200194
if (TypeIs<std::string>(it->second)) {
201-
if (hasUsernameAndCredential) {
202-
std::string username = GetValue<std::string>(iceServerMap.find(EncodableValue("username"))
203-
->second);
204-
std::string credential =
205-
GetValue<std::string>(iceServerMap.find(EncodableValue("credential"))
206-
->second);
207-
std::string uri = GetValue<std::string>(it->second);
208-
ice_server.username = username;
209-
ice_server.password = credential;
210-
ice_server.uri = uri;
211-
} else {
212-
std::string uri = GetValue<std::string>(it->second);
213-
ice_server.uri = uri;
214-
}
195+
ice_server.uri = GetValue<std::string>(it->second);
215196
}
216197
if (TypeIs<EncodableList>(it->second)) {
217198
const EncodableList urls = GetValue<EncodableList>(it->second);
@@ -221,25 +202,10 @@ bool FlutterWebRTCBase::CreateIceServers(const EncodableList &iceServersArray,
221202
std::string value;
222203
auto it2 = map.find(EncodableValue("url"));
223204
if (it2 != map.end()) {
224-
value = GetValue<std::string>(it2->second);
225-
if (hasUsernameAndCredential) {
226-
std::string username =
227-
GetValue<std::string>(iceServerMap.find(EncodableValue("username"))
228-
->second);
229-
std::string credential =
230-
GetValue<std::string>(iceServerMap.find(EncodableValue("credential"))
231-
->second);
232-
ice_server.username = username;
233-
ice_server.password = credential;
234-
ice_server.uri = value;
235-
} else {
236-
ice_server.uri = value;
237-
}
205+
ice_server.uri = GetValue<std::string>(it2->second);
238206
}
239-
}
240-
else if (TypeIs<std::string>(url)) {
241-
std::string urlString = GetValue<std::string>(url);
242-
ice_server.uri = urlString;
207+
} else if (TypeIs<std::string>(url)) {
208+
ice_server.uri = GetValue<std::string>(url);
243209
}
244210
}
245211
}

0 commit comments

Comments
 (0)
0