blob: bd69be95317df685b1a76628f04165beb54546a0 [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
11#include "webrtc/examples/peerconnection/client/conductor.h"
12#include "webrtc/examples/peerconnection/client/flagdefs.h"
13#include "webrtc/examples/peerconnection/client/main_wnd.h"
14#include "webrtc/examples/peerconnection/client/peer_connection_client.h"
kjellanderc3771cc2017-06-30 13:42:44 -070015#include "webrtc/rtc_base/checks.h"
16#include "webrtc/rtc_base/ssladapter.h"
17#include "webrtc/rtc_base/win32socketinit.h"
18#include "webrtc/rtc_base/win32socketserver.h"
Donald E Curtisa8736442015-08-05 15:48:13 -070019
20int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
21 wchar_t* cmd_line, int cmd_show) {
22 rtc::EnsureWinsockInit();
nisse7eaa4ea2017-05-08 05:25:41 -070023 rtc::Win32SocketServer w32_ss;
24 rtc::Win32Thread w32_thread(&w32_ss);
Donald E Curtisa8736442015-08-05 15:48:13 -070025 rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
26
27 rtc::WindowsCommandLineArguments win_args;
28 int argc = win_args.argc();
29 char **argv = win_args.argv();
30
31 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
32 if (FLAG_help) {
33 rtc::FlagList::Print(NULL, false);
34 return 0;
35 }
36
37 // Abort if the user specifies a port that is outside the allowed
38 // range [1, 65535].
39 if ((FLAG_port < 1) || (FLAG_port > 65535)) {
40 printf("Error: %i is not a valid port.\n", FLAG_port);
41 return -1;
42 }
43
44 MainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
45 if (!wnd.Create()) {
nissec80e7412017-01-11 05:56:46 -080046 RTC_NOTREACHED();
Donald E Curtisa8736442015-08-05 15:48:13 -070047 return -1;
48 }
49
50 rtc::InitializeSSL();
51 PeerConnectionClient client;
52 rtc::scoped_refptr<Conductor> conductor(
53 new rtc::RefCountedObject<Conductor>(&client, &wnd));
54
55 // Main loop.
56 MSG msg;
57 BOOL gm;
58 while ((gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
59 if (!wnd.PreTranslateMessage(&msg)) {
60 ::TranslateMessage(&msg);
61 ::DispatchMessage(&msg);
62 }
63 }
64
65 if (conductor->connection_active() || client.is_connected()) {
66 while ((conductor->connection_active() || client.is_connected()) &&
67 (gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
68 if (!wnd.PreTranslateMessage(&msg)) {
69 ::TranslateMessage(&msg);
70 ::DispatchMessage(&msg);
71 }
72 }
73 }
74
75 rtc::CleanupSSL();
76 return 0;
77}