-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModules.cs
More file actions
57 lines (54 loc) · 2.06 KB
/
Copy pathModules.cs
File metadata and controls
57 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Microsoft.AspNetCore.SignalR;
using PylonStream.Services;
using PylonStream.Hubs;
namespace PylonStream
{
public static class Modules
{
public static AppConfig Config { get; set; } = new AppConfig();
public static LogService SystemLogger { get; set; } = new LogService("System");
public static CameraManager CameraMgr { get; set; } = new CameraManager();
public static MediaMTXManager MediaMTXMgr { get; set; } = new MediaMTXManager();
public static IHubContext<StreamHub>? WebHubContext { get; set; }
public static Microsoft.AspNetCore.Builder.WebApplication? WebApp { get; set; }
public static readonly object ConfigLock = new object();
public static string GetServerIP()
{
lock (ConfigLock)
{
if (!string.IsNullOrEmpty(Config.SelectedInterfaceIp) && Config.SelectedInterfaceIp != "Auto")
{
return Config.SelectedInterfaceIp;
}
}
try
{
using (var socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, 0))
{
socket.Connect("8.8.8.8", 65530);
var endPoint = socket.LocalEndPoint as System.Net.IPEndPoint;
if (endPoint != null)
{
return endPoint.Address.ToString();
}
}
}
catch
{
try
{
var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
}
catch { }
}
return "127.0.0.1";
}
}
}