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