Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Latest commit

 

History

History
68 lines (56 loc) · 2.1 KB

README.md

File metadata and controls

68 lines (56 loc) · 2.1 KB

TouchPortalApi

.NET Core NuGet Downloads Stars License

SDK to interface with Touch Portal API through sockets. Sample projects include WebApp, Console, and Worker Services.

Setup

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()
});

Usage

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" });