public override void SetUpConnector() { _connector = new ButtplugClientIPCConnector(); _client = new ButtplugClient("Websocket Client", _connector); }
private async void Connect_Click(object sender, System.Windows.RoutedEventArgs e) { Connect.IsEnabled = false; if (_client != null) { await _client.DisconnectAsync(); _client = null; Devices.Clear(); ButtplugConnType.IsEnabled = false; ButtplugConnType_SelectionChanged(this, null); Connect.Content = "Connect"; Connect.IsEnabled = true; return; } IButtplugClientConnector conn = null; switch (((ComboBoxItem)ButtplugConnType.SelectedValue).Content) { case "WebSocket": try { conn = new ButtplugWebsocketConnector(new Uri(ButtplugTarget.Text)); } catch (UriFormatException e1) { MessageBox.Show($"Uri Error: {e1.Message}", "B******g Error", MessageBoxButton.OK, MessageBoxImage.Error); Connect.IsEnabled = true; return; } ButtplugTarget.IsEnabled = false; ButtplugConnType.IsEditable = false; break; case "IPC": ButtplugTarget.IsEnabled = false; ButtplugConnType.IsEditable = false; conn = new ButtplugClientIPCConnector(ButtplugTarget.Text); break; case "Embedded": ButtplugTarget.Text = ""; ButtplugTarget.IsEnabled = false; ButtplugConnType.IsEditable = false; //conn = new ButtplugEmbeddedConnector(new ButtplugServer()); //break; return; default: MessageBox.Show("Invalid Connection type!", "B******g Error", MessageBoxButton.OK, MessageBoxImage.Error); Connect.IsEnabled = true; return; } try { _client = new ButtplugClient("NogasmChart", conn); _client.DeviceAdded += ClientOnDeviceAdded; _client.DeviceRemoved += ClientOnDeviceRemoved; _client.ServerDisconnect += ClientOnServerDisconnect; _client.ErrorReceived += ClientOnErrorReceived; await _client.ConnectAsync(); await _client.StartScanningAsync(); } catch (Exception e1) { MessageBox.Show($"Something went wrong: {e1.Message}", "B******g Error", MessageBoxButton.OK, MessageBoxImage.Error); try { await _client?.DisconnectAsync(); } catch (Exception) { } _client = null; ButtplugConnType.IsEnabled = false; ButtplugConnType_SelectionChanged(this, null); Connect.Content = "Connect"; } Connect.Content = "Disconnect"; Connect.IsEnabled = true; }