MetalButtplug/Utils/ButtplugManager.cs

43 lines
1.4 KiB
C#
Raw Normal View History

using System;
using Buttplug.Client;
using Buttplug.Client.Connectors.WebsocketConnector;
namespace MetalButtplug.Utils;
internal static class ButtplugManager {
public static bool enabled = false;
static ButtplugClient client;
public async static void Init() {
ButtplugManager.client = new ButtplugClient("Metal: Hellsinger");
Plugin.Log.LogInfo("Attempting buttplug connection");
try {
var connector = new ButtplugWebsocketConnector(new Uri("ws://localhost:12345"));
await client.ConnectAsync(connector);
Plugin.Log.LogInfo("Connected to buttplug server!");
enabled = true;
} catch(Exception ex) {
Plugin.Log.LogWarning($"Failed to connect: {ex.Message}\nDisabling buttplug integration - Is Intiface running?");
return;
}
client.DeviceAdded += OnDeviceAdd;
client.DeviceRemoved += OnDeviceRemove;
Plugin.Log.LogInfo($"Found devices:");
foreach (ButtplugClientDevice device in client.Devices) {
Plugin.Log.LogInfo($"- ${device.DisplayName}");
}
}
private static void OnDeviceAdd(object sender, DeviceAddedEventArgs e) {
Plugin.Log.LogInfo($"Device added: {e.Device.DisplayName}");
}
private static void OnDeviceRemove(object sender, DeviceRemovedEventArgs e) {
Plugin.Log.LogInfo($"Device removed: {e.Device.DisplayName}");
}
}