private void RunGui(ObsWebSocketClientSettings settings) { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(formFactory(settings)); }
/// <summary> /// Connects to the OBS WebSocket server /// </summary> /// <returns></returns> public void Connect(ObsWebSocketClientSettings settings) { if (obsWebSocket.IsConnected) { obsWebSocket.Disconnect(); } obsWebSocket.Connect($"ws://{settings.IpAddress}:{settings.Port}", settings.Password ?? ""); }
public async Task OnExecuteAsync() { ObsWebSocketClientSettings settings = await ReadSettings().ConfigureAwait(false); logger.LogInformation("Try to connect using Address: {IpAddress}:{Port}", settings.IpAddress, settings.Port); try { await client.ConnectAsync(settings).ConfigureAwait(false); logger.LogInformation("Connected"); } catch (Exception ex) { logger.LogError("Cannot connect: {Message}", ex.Message); } /* Suscribe the client. */ subscriber.Subscribe("OBS", async command => { logger.LogTrace("Received command: {Command}", command); if (command == "**START") { await client.StartRecordingAsync(); } else if (command == "**STOP") { await client.StopRecordingAsync(); } else if (string.IsNullOrEmpty(command)) { await client.ChangeSceneAsync(command); } }); if (!NoGui) { logger.LogInformation("Runnig with GUI"); ConsoleWindowController.Hide(); RunGui(settings); /* Save if running GUI. */ await settingsRepository.SaveAsync(settings); } else { logger.LogInformation("Runnig without GUI"); Console.ReadKey(); } }
private async Task <ObsWebSocketClientSettings> ReadSettings() { ObsWebSocketClientSettings settings = (await settingsRepository.LoadAsync().ConfigureAwait(false)) ?? new ObsWebSocketClientSettings(); if (!string.IsNullOrEmpty(IpAddress)) { settings.IpAddress = IpAddress; } if (Port.HasValue) { settings.Port = Port.Value; } if (!string.IsNullOrEmpty(Password)) { settings.Password = Password; } return(settings); }
/// <summary> /// Connects to the OBS WebSocket server /// </summary> /// <returns></returns> public async Task ConnectAsync(ObsWebSocketClientSettings settings) { // At least this won't block the main thread if using from GUI await Task.WhenAny(Task.Run(() => obsWebSocket.Connect($"ws://{settings.IpAddress}:{settings.Port}", "")), Task.Delay(3000)); }
// TODO: Refactor this Injection public ConfigurationForm(ObsWebSocketClientSettings settings, ObsWebSocketClient client) { InitializeComponent(); this.settings = settings ?? new ObsWebSocketClientSettings(); this.client = client; }
public async Task SaveAsync(ObsWebSocketClientSettings settings) { string json = JsonConvert.SerializeObject(settings); await File.WriteAllTextAsync(@".\settings.json", json).ConfigureAwait(false); // Maybe AppData is a better location, but... }