Adding close_peerconnection signal command
parent
a57d23466a
commit
5cc1dbbc36
|
@ -240,11 +240,16 @@ void Control::OnPeerChannelClosed(const std::string id) {
|
|||
peer->second->ClosePeerConnection();
|
||||
}
|
||||
|
||||
void Control::QueueOnPeerChannelClosed(const std::string id) {
|
||||
void Control::QueueOnPeerChannelClosed(const std::string id, int delay) {
|
||||
|
||||
// close_peerconnection
|
||||
ControlMessageData *data = new ControlMessageData(id, ref_);
|
||||
|
||||
// Call Control::OnPeerDisconnected()
|
||||
webrtc_thread_->PostDelayed(1000, this, MSG_ON_PEER_CHANNEL_CLOSED, data);
|
||||
if (delay==0)
|
||||
webrtc_thread_->Post(this, MSG_ON_PEER_CHANNEL_CLOSED, data);
|
||||
else
|
||||
webrtc_thread_->PostDelayed(delay, this, MSG_ON_PEER_CHANNEL_CLOSED, data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -361,6 +366,9 @@ void Control::OnCommandReceived(const Json::Value& message) {
|
|||
else if (command == "ice_candidate") {
|
||||
AddIceCandidate(peer_id, data);
|
||||
}
|
||||
else if (command == "close_peerconnection") {
|
||||
ClosePeerConnection(peer_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
void Control::OnSignalCommandReceived(const Json::Value& message) {
|
||||
|
@ -568,11 +576,21 @@ void Control::ReceiveAnswerSdp(const std::string& peer_id, const Json::Value& da
|
|||
std::string sdp;
|
||||
|
||||
if (!rtc::GetStringFromJsonObject(data, "sdp", &sdp)) return;
|
||||
if (peers_.find(peer_id) == peers_.end()) return;
|
||||
|
||||
peers_[peer_id]->ReceiveAnswerSdp(sdp);
|
||||
auto peer = peers_.find(peer_id);
|
||||
if (peer == peers_.end()) return;
|
||||
|
||||
peer->second->ReceiveAnswerSdp(sdp);
|
||||
}
|
||||
|
||||
void Control::ClosePeerConnection(const std::string& peer_id, const Json::Value& data) {
|
||||
auto peer = peers_.find(peer_id);
|
||||
if (peer == peers_.end()) return;
|
||||
|
||||
peers_[peer_id]->ClosePeerConnection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Control::DisconnectPeer(const std::string id) {
|
||||
// 1. Close remote data channel (remote_data_channel_)
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
virtual void QueuePeerDisconnect(const std::string id);
|
||||
virtual void QueueOnPeerDisconnected(const std::string id);
|
||||
virtual void OnPeerDisconnected(const std::string id);
|
||||
virtual void QueueOnPeerChannelClosed(const std::string id);
|
||||
virtual void QueueOnPeerChannelClosed(const std::string id, int delay);
|
||||
virtual void OnPeerChannelClosed(const std::string id);
|
||||
virtual void OnPeerMessage(const std::string& id, const char* buffer, const size_t size);
|
||||
virtual void OnPeerWritable(const std::string& id);
|
||||
|
@ -87,6 +87,7 @@ protected:
|
|||
void AddIceCandidate(const std::string& peer_id, const Json::Value& data);
|
||||
void ReceiveOfferSdp(const std::string& peer_id, const Json::Value& data);
|
||||
void ReceiveAnswerSdp(const std::string& peer_id, const Json::Value& data);
|
||||
void ClosePeerConnection(const std::string& peer_id, const Json::Value& data);
|
||||
void DisconnectPeer(const std::string id);
|
||||
|
||||
void OnSignedIn(const Json::Value& data);
|
||||
|
|
|
@ -182,7 +182,10 @@ void PeerControl::OnPeerClosed() {
|
|||
// Both local_data_channel_ and remote_data_channel_ has been closed
|
||||
if (local_data_channel_->state() == webrtc::DataChannelInterface::DataState::kClosed &&
|
||||
remote_data_channel_->state() == webrtc::DataChannelInterface::DataState::kClosed) {
|
||||
observer_->QueueOnPeerChannelClosed(remote_id_);
|
||||
|
||||
// Close local peerconnection
|
||||
observer_->QueueOnPeerChannelClosed(remote_id_, 1000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
virtual void QueuePeerDisconnect(const std::string id) = 0;
|
||||
virtual void QueueOnPeerDisconnected(const std::string id) = 0;
|
||||
virtual void OnPeerDisconnected(const std::string id) = 0;
|
||||
virtual void QueueOnPeerChannelClosed(const std::string id) = 0;
|
||||
virtual void QueueOnPeerChannelClosed(const std::string id, int delay) = 0;
|
||||
virtual void OnPeerChannelClosed(const std::string id) = 0;
|
||||
virtual void OnPeerMessage(const std::string& id, const char* buffer, const size_t size) = 0;
|
||||
virtual void OnPeerWritable(const std::string& id) = 0;
|
||||
|
|
|
@ -54,6 +54,7 @@ Signal::Signal() :
|
|||
client_.set_access_channels(websocketpp::log::alevel::fail);
|
||||
#else
|
||||
client_.clear_access_channels(websocketpp::log::alevel::all);
|
||||
client_.clear_access_channels(websocketpp::log::elevel::all);
|
||||
#endif
|
||||
|
||||
// Initialize ASIO
|
||||
|
|
Loading…
Reference in New Issue