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 "examples/peerconnection/client/defaults.h"
12 
13 #include <stdlib.h>
14 
15 #ifdef WIN32
16 #include <winsock2.h>
17 #else
18 #include <unistd.h>
19 #endif
20 
21 #include "rtc_base/arraysize.h"
22 
23 const char kAudioLabel[] = "audio_label";
24 const char kVideoLabel[] = "video_label";
25 const char kStreamId[] = "stream_id";
26 const uint16_t kDefaultServerPort = 8888;
27 
GetEnvVarOrDefault(const char * env_var_name,const char * default_value)28 std::string GetEnvVarOrDefault(const char* env_var_name,
29                                const char* default_value) {
30   std::string value;
31   const char* env_var = getenv(env_var_name);
32   if (env_var)
33     value = env_var;
34 
35   if (value.empty())
36     value = default_value;
37 
38   return value;
39 }
40 
GetPeerConnectionString()41 std::string GetPeerConnectionString() {
42   return GetEnvVarOrDefault("WEBRTC_CONNECT", "stun:stun.l.google.com:19302");
43 }
44 
GetDefaultServerName()45 std::string GetDefaultServerName() {
46   return GetEnvVarOrDefault("WEBRTC_SERVER", "localhost");
47 }
48 
GetPeerName()49 std::string GetPeerName() {
50   char computer_name[256];
51   std::string ret(GetEnvVarOrDefault("USERNAME", "user"));
52   ret += '@';
53   if (gethostname(computer_name, arraysize(computer_name)) == 0) {
54     ret += computer_name;
55   } else {
56     ret += "host";
57   }
58   return ret;
59 }
60