Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #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 Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 19 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 20 | int PASCAL wWinMain(HINSTANCE instance, |
| 21 | HINSTANCE prev_instance, |
| 22 | wchar_t* cmd_line, |
| 23 | int cmd_show) { |
Mirko Bonadei | ba5eaee | 2018-09-17 12:20:10 +0200 | [diff] [blame^] | 24 | rtc::WinsockInitializer winsock_init; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 25 | rtc::Win32SocketServer w32_ss; |
| 26 | rtc::Win32Thread w32_thread(&w32_ss); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 27 | rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); |
| 28 | |
| 29 | rtc::WindowsCommandLineArguments win_args; |
| 30 | int argc = win_args.argc(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 31 | char** argv = win_args.argv(); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 32 | |
| 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()) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 48 | RTC_NOTREACHED(); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 49 | return -1; |
| 50 | } |
| 51 | |
| 52 | rtc::InitializeSSL(); |
| 53 | PeerConnectionClient client; |
| 54 | rtc::scoped_refptr<Conductor> conductor( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 55 | new rtc::RefCountedObject<Conductor>(&client, &wnd)); |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 56 | |
| 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 | } |