-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cc
75 lines (61 loc) · 2.27 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright 2017-2018 Julien Chavanton
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "examples/rtc_gw/conductor.h"
#include "examples/rtc_gw/flagdefs.h"
#include "examples/rtc_gw/peer_connection_listener.h"
#include "rtc_base/ssladapter.h"
#include "rtc_base/thread.h"
class CustomSocketServer : public rtc::PhysicalSocketServer {
public:
explicit CustomSocketServer() : conductor_(NULL), client_(NULL) {}
virtual ~CustomSocketServer() {}
void SetMessageQueue(rtc::MessageQueue* queue) override {
message_queue_ = queue;
}
void set_client(PeerConnectionListener* client) { client_ = client; }
void set_conductor(Conductor* conductor) { conductor_ = conductor; }
virtual bool Wait(int cms, bool process_io) override {
conductor_->SendMessage();
return rtc::PhysicalSocketServer::Wait(10/*cms == -1 ? 1 : cms*/, process_io);
}
protected:
rtc::MessageQueue* message_queue_;
Conductor* conductor_;
PeerConnectionListener* client_;
};
int main(int argc, char* argv[]) {
printf("starting ...\n ");
rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
rtc::FlagList::Print(NULL, false);
if (FLAG_help) {
rtc::FlagList::Print(NULL, false);
return 0;
}
// Abort if the user specifies a port that is outside the allowed
// range [1, 65535].
if ((FLAG_port < 1) || (FLAG_port > 65535)) {
printf("Error: %i is not a valid port.\n", FLAG_port);
return -1;
}
printf("listening[%s]\n", FLAG_listen);
CustomSocketServer socket_server;
rtc::AutoSocketServerThread thread(&socket_server);
rtc::InitializeSSL();
// Must be constructed after we set the socketserver.
PeerConnectionListener client;
rtc::scoped_refptr<Conductor> conductor(new rtc::RefCountedObject<Conductor>(&client));
socket_server.set_client(&client);
socket_server.set_conductor(conductor);
conductor->StartListen(FLAG_listen, FLAG_port);
thread.Run();
rtc::CleanupSSL();
return 0;
}