SDK to interface with Touch Portal API through sockets. Sample projects include WebApp, Console, and Worker Services.
Configure your options/DI:
services.Configure<TouchPortalApiOptions>((options) => {
options.ServerIp = "127.0.0.1";
options.ServerPort = 12136;
options.PluginId = "TouchPortal.SnoopPlugin";
});
Startup the listener and pair to Touch Portal:
Task.WhenAll(new Task[] {
messageProcessor.Listen(),
messageProcessor.TryPairAsync()
});
Use or add to your class constructor for DI for the services you want to use:
// Our services, can be retrieved through DI in constructors
var messageProcessor = app.ApplicationServices.GetRequiredService<IMessageProcessor>();
Setup your event handlers that you want to use:
// On Plugin Connect Event
messageProcessor.OnConnectEventHandler += () => {
Console.WriteLine($"{DateTime.Now} Plugin Connected to TouchPortal");
};
// On Action Event
messageProcessor.OnActionEvent += (actionId, dataList) => {
Console.WriteLine($"{DateTime.Now} Action Event Fired.");
foreach (var o in dataList) {
Console.WriteLine($"Id: {o.Id} Value: {o.Value}");
}
};
// On List Change Event
messageProcessor.OnListChangeEventHandler += (actionId, value) => {
Console.WriteLine($"{DateTime.Now} Choice Event Fired.");
};
// On Plugin Disconnect
messageProcessor.OnCloseEventHandler += () => {
Console.Write($"{DateTime.Now} Plugin Quit Command");
};
Update a state:
messageProcessor.UpdateState(new StateUpdate() { Id = obj[0].Id, Value = "Off" });