Remove usage of rtc::MessageHandler in peer_connection example

Bug: webrtc:9702
Change-Id: I2d688461858d9b6f06a0f7928f3cff7c6a7b7db9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272080
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37813}
This commit is contained in:
Danil Chapovalov
2022-08-17 17:12:29 +02:00
committed by WebRTC LUCI CQ
parent 85b40f0021
commit b9201b0ef4
3 changed files with 11 additions and 17 deletions

View File

@ -693,6 +693,8 @@ if (is_linux || is_chromeos || is_win) {
"../api:scoped_refptr",
"../api/audio:audio_mixer_api",
"../api/audio_codecs:audio_codecs_api",
"../api/task_queue:pending_task_safety_flag",
"../api/units:time_delta",
"../api/video:video_frame",
"../api/video:video_rtp_headers",
"../api/video_codecs:video_codecs_api",

View File

@ -10,6 +10,7 @@
#include "examples/peerconnection/client/peer_connection_client.h"
#include "api/units/time_delta.h"
#include "examples/peerconnection/client/defaults.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@ -18,9 +19,9 @@
namespace {
// This is our magical hangup signal.
const char kByeMessage[] = "BYE";
constexpr char kByeMessage[] = "BYE";
// Delay between server connection retries, in milliseconds
const int kReconnectDelay = 2000;
constexpr webrtc::TimeDelta kReconnectDelay = webrtc::TimeDelta::Seconds(2);
rtc::Socket* CreateClientSocket(int family) {
rtc::Thread* thread = rtc::Thread::Current();
@ -33,9 +34,7 @@ rtc::Socket* CreateClientSocket(int family) {
PeerConnectionClient::PeerConnectionClient()
: callback_(NULL), resolver_(NULL), state_(NOT_CONNECTED), my_id_(-1) {}
PeerConnectionClient::~PeerConnectionClient() {
rtc::Thread::Current()->Clear(this);
}
PeerConnectionClient::~PeerConnectionClient() = default;
void PeerConnectionClient::InitSocketSignals() {
RTC_DCHECK(control_socket_.get() != NULL);
@ -480,16 +479,11 @@ void PeerConnectionClient::OnClose(rtc::Socket* socket, int err) {
} else {
if (socket == control_socket_.get()) {
RTC_LOG(LS_WARNING) << "Connection refused; retrying in 2 seconds";
rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, kReconnectDelay, this,
0);
rtc::Thread::Current()->PostDelayedTask(
SafeTask(safety_.flag(), [this] { DoConnect(); }), kReconnectDelay);
} else {
Close();
callback_->OnDisconnected();
}
}
}
void PeerConnectionClient::OnMessage(rtc::Message* msg) {
// ignore msg; there is currently only one supported message ("retry")
DoConnect();
}

View File

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "api/task_queue/pending_task_safety_flag.h"
#include "rtc_base/net_helpers.h"
#include "rtc_base/physical_socket_server.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
@ -34,8 +35,7 @@ struct PeerConnectionClientObserver {
virtual ~PeerConnectionClientObserver() {}
};
class PeerConnectionClient : public sigslot::has_slots<>,
public rtc::MessageHandler {
class PeerConnectionClient : public sigslot::has_slots<> {
public:
enum State {
NOT_CONNECTED,
@ -65,9 +65,6 @@ class PeerConnectionClient : public sigslot::has_slots<>,
bool SignOut();
// implements the MessageHandler interface
void OnMessage(rtc::Message* msg);
protected:
void DoConnect();
void Close();
@ -126,6 +123,7 @@ class PeerConnectionClient : public sigslot::has_slots<>,
Peers peers_;
State state_;
int my_id_;
webrtc::ScopedTaskSafety safety_;
};
#endif // EXAMPLES_PEERCONNECTION_CLIENT_PEER_CONNECTION_CLIENT_H_