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