Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 9de4b0a

Browse files
authored
Fix an unexpected behavior when chat-closed is received. (#693)
1 parent 5980644 commit 9de4b0a

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

talk/owt/sdk/p2p/p2pclient.cc

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,24 +293,43 @@ void P2PClient::OnSignalingMessage(const std::string& message,
293293
rtc::GetIntFromJsonObject(stop_info, "code", &code);
294294
rtc::GetStringFromJsonObject(stop_info, "message", &error);
295295

296+
if (code == kWebrtcIceGatheringPolicyUnsupported) {
297+
auto pcc = that->GetPeerConnectionChannel(remote_id);
298+
std::shared_ptr<LocalStream> stream = pcc->GetLatestLocalStream();
299+
std::function<void()> success_callback =
300+
pcc->GetLatestPublishSuccessCallback();
301+
std::function<void(std::unique_ptr<Exception>)> failure_callback =
302+
pcc->GetLatestPublishFailureCallback();
303+
pcc->SetAbandoned();
304+
{
305+
const std::lock_guard<std::mutex> lock(that->pc_channels_mutex_);
306+
that->pc_channels_.erase(remote_id);
307+
}
308+
309+
auto new_pcc = that->GetPeerConnectionChannel(remote_id);
310+
new_pcc->Publish(stream, success_callback, failure_callback);
311+
return;
312+
}
296313
auto pcc = that->GetPeerConnectionChannel(remote_id);
297-
std::shared_ptr<LocalStream> stream = pcc->GetLatestLocalStream();
298-
std::function<void()> success_callback =
299-
pcc->GetLatestPublishSuccessCallback();
300-
std::function<void(std::unique_ptr<Exception>)> failure_callback =
301-
pcc->GetLatestPublishFailureCallback();
302314
// Don't send stop to remote.
303315
pcc->SetAbandoned();
304-
305316
{
306317
const std::lock_guard<std::mutex> lock(that->pc_channels_mutex_);
307318
that->pc_channels_.erase(remote_id);
308319
}
309320

310-
auto new_pcc = that->GetPeerConnectionChannel(remote_id);
311-
new_pcc->Publish(stream, success_callback, failure_callback);
312321
return;
313322
}
323+
} else if (message.find("\"type\":\"chat-ua\"") != std::string::npos) {
324+
// "chat-ua" is the 1st message of a new connection. If there is an old
325+
// PCC exists, close it and create a new one.
326+
auto pcc = that->GetPeerConnectionChannel(remote_id);
327+
// Don't send stop to remote.
328+
pcc->SetAbandoned();
329+
{
330+
const std::lock_guard<std::mutex> lock(that->pc_channels_mutex_);
331+
that->pc_channels_.erase(remote_id);
332+
}
314333
}
315334
// Secondly dispatch the message to pcc.
316335
auto pcc = that->GetPeerConnectionChannel(remote_id);

0 commit comments

Comments
 (0)