init commit
This commit is contained in:
128
desktop_global/VideoReader/ServerConfig.cs
Normal file
128
desktop_global/VideoReader/ServerConfig.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VideoReader
|
||||
{
|
||||
public class ServerConfig
|
||||
{
|
||||
public string SignalingServer { get; set; } = "your-server.com";
|
||||
public int DataPort { get; set; } = 5000;
|
||||
public byte DefaultChannel { get; set; } = 10;
|
||||
public string FallbackIP { get; set; } = "127.0.0.1";
|
||||
public bool UseSSL { get; set; } = true;
|
||||
public string ProfileName { get; set; } = "custom";
|
||||
public Dictionary<string, string> CustomHeaders { get; set; } = new();
|
||||
public int ConnectionTimeout { get; set; } = 10000;
|
||||
public bool EnableHeartbeat { get; set; } = true;
|
||||
public int HeartbeatInterval { get; set; } = 500;
|
||||
}
|
||||
|
||||
public static class ServerConfigManager
|
||||
{
|
||||
private static readonly Dictionary<string, ServerConfig> Profiles = new()
|
||||
{
|
||||
["standard"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "vidser.top",
|
||||
DataPort = 3033,
|
||||
DefaultChannel = 56,
|
||||
FallbackIP = "158.247.241.191",
|
||||
UseSSL = true,
|
||||
ProfileName = "standard"
|
||||
},
|
||||
["samsung"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "s1.cc-vst.online",
|
||||
DataPort = 3234,
|
||||
DefaultChannel = 44,
|
||||
FallbackIP = null,
|
||||
UseSSL = true,
|
||||
ProfileName = "samsung"
|
||||
},
|
||||
["custom"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "your-server.com",
|
||||
DataPort = 5000,
|
||||
DefaultChannel = 10,
|
||||
FallbackIP = "127.0.0.1",
|
||||
UseSSL = true,
|
||||
ProfileName = "custom"
|
||||
},
|
||||
["local"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "localhost",
|
||||
DataPort = 8080,
|
||||
DefaultChannel = 1,
|
||||
FallbackIP = "127.0.0.1",
|
||||
UseSSL = false,
|
||||
ProfileName = "local"
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerConfig GetProfile(string profileName)
|
||||
{
|
||||
return Profiles.TryGetValue(profileName, out var config)
|
||||
? config
|
||||
: Profiles["custom"];
|
||||
}
|
||||
|
||||
public static ServerConfig LoadFromFile(string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
var json = File.ReadAllText(configPath);
|
||||
return JsonSerializer.Deserialize<ServerConfig>(json) ?? Profiles["custom"];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error loading config: {ex.Message}");
|
||||
}
|
||||
return Profiles["custom"];
|
||||
}
|
||||
|
||||
public static void SaveToFile(ServerConfig config, string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error saving config: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetAvailableProfiles()
|
||||
{
|
||||
return new List<string>(Profiles.Keys);
|
||||
}
|
||||
|
||||
public static ServerConfig GetDefault()
|
||||
{
|
||||
// Приоритет: файл конфигурации -> переменная окружения -> custom профиль
|
||||
var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "server-config.json");
|
||||
|
||||
if (File.Exists(configFile))
|
||||
{
|
||||
return LoadFromFile(configFile);
|
||||
}
|
||||
|
||||
var envProfile = Environment.GetEnvironmentVariable("VIDEOREADER_PROFILE");
|
||||
if (!string.IsNullOrEmpty(envProfile) && Profiles.ContainsKey(envProfile))
|
||||
{
|
||||
return Profiles[envProfile];
|
||||
}
|
||||
|
||||
return Profiles["custom"];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user