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 | |
| 11 | #include "webrtc/examples/peerconnection/client/defaults.h" |
| 12 | |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | |
| 16 | #ifdef WIN32 |
| 17 | #include <winsock2.h> |
| 18 | #else |
| 19 | #include <unistd.h> |
| 20 | #endif |
| 21 | |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 22 | #include "webrtc/base/arraysize.h" |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 23 | #include "webrtc/base/common.h" |
| 24 | |
| 25 | const char kAudioLabel[] = "audio_label"; |
| 26 | const char kVideoLabel[] = "video_label"; |
| 27 | const char kStreamLabel[] = "stream_label"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 28 | const uint16_t kDefaultServerPort = 8888; |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 29 | |
| 30 | std::string GetEnvVarOrDefault(const char* env_var_name, |
| 31 | const char* default_value) { |
| 32 | std::string value; |
| 33 | const char* env_var = getenv(env_var_name); |
| 34 | if (env_var) |
| 35 | value = env_var; |
| 36 | |
| 37 | if (value.empty()) |
| 38 | value = default_value; |
| 39 | |
| 40 | return value; |
| 41 | } |
| 42 | |
| 43 | std::string GetPeerConnectionString() { |
| 44 | return GetEnvVarOrDefault("WEBRTC_CONNECT", "stun:stun.l.google.com:19302"); |
| 45 | } |
| 46 | |
| 47 | std::string GetDefaultServerName() { |
| 48 | return GetEnvVarOrDefault("WEBRTC_SERVER", "localhost"); |
| 49 | } |
| 50 | |
| 51 | std::string GetPeerName() { |
| 52 | char computer_name[256]; |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 53 | if (gethostname(computer_name, arraysize(computer_name)) != 0) |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 54 | strcpy(computer_name, "host"); |
| 55 | std::string ret(GetEnvVarOrDefault("USERNAME", "user")); |
| 56 | ret += '@'; |
| 57 | ret += computer_name; |
| 58 | return ret; |
| 59 | } |