blob: 25dde1ef6585d82578a79f45452bea4b6d616fef [file] [log] [blame]
Donald E Curtisa8736442015-08-05 15:48:13 -07001/*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "examples/peerconnection/client/conductor.h"
12#include "examples/peerconnection/client/flagdefs.h"
13#include "examples/peerconnection/client/main_wnd.h"
14#include "examples/peerconnection/client/peer_connection_client.h"
15#include "rtc_base/checks.h"
16#include "rtc_base/ssladapter.h"
17#include "rtc_base/win32socketinit.h"
18#include "rtc_base/win32socketserver.h"
Donald E Curtisa8736442015-08-05 15:48:13 -070019
Yves Gerey665174f2018-06-19 15:03:05 +020020int PASCAL wWinMain(HINSTANCE instance,
21 HINSTANCE prev_instance,
22 wchar_t* cmd_line,
23 int cmd_show) {
Mirko Bonadeiba5eaee2018-09-17 12:20:10 +020024 rtc::WinsockInitializer winsock_init;
nisse7eaa4ea2017-05-08 05:25:41 -070025 rtc::Win32SocketServer w32_ss;
26 rtc::Win32Thread w32_thread(&w32_ss);
Donald E Curtisa8736442015-08-05 15:48:13 -070027 rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
28
29 rtc::WindowsCommandLineArguments win_args;
30 int argc = win_args.argc();
Yves Gerey665174f2018-06-19 15:03:05 +020031 char** argv = win_args.argv();
Donald E Curtisa8736442015-08-05 15:48:13 -070032
33 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
34 if (FLAG_help) {
35 rtc::FlagList::Print(NULL, false);
36 return 0;
37 }
38
39 // Abort if the user specifies a port that is outside the allowed
40 // range [1, 65535].
41 if ((FLAG_port < 1) || (FLAG_port > 65535)) {
42 printf("Error: %i is not a valid port.\n", FLAG_port);
43 return -1;
44 }
45
46 MainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
47 if (!wnd.Create()) {
nissec80e7412017-01-11 05:56:46 -080048 RTC_NOTREACHED();
Donald E Curtisa8736442015-08-05 15:48:13 -070049 return -1;
50 }
51
52 rtc::InitializeSSL();
53 PeerConnectionClient client;
54 rtc::scoped_refptr<Conductor> conductor(
Yves Gerey665174f2018-06-19 15:03:05 +020055 new rtc::RefCountedObject<Conductor>(&client, &wnd));
Donald E Curtisa8736442015-08-05 15:48:13 -070056
57 // Main loop.
58 MSG msg;
59 BOOL gm;
60 while ((gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
61 if (!wnd.PreTranslateMessage(&msg)) {
62 ::TranslateMessage(&msg);
63 ::DispatchMessage(&msg);
64 }
65 }
66
67 if (conductor->connection_active() || client.is_connected()) {
68 while ((conductor->connection_active() || client.is_connected()) &&
69 (gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
70 if (!wnd.PreTranslateMessage(&msg)) {
71 ::TranslateMessage(&msg);
72 ::DispatchMessage(&msg);
73 }
74 }
75 }
76
77 rtc::CleanupSSL();
78 return 0;
79}