Originally a fork of https://github.com/oddbear/TouchPortalSDK, optimized for performance, usability, and good behavior (eg. not crashing on exit). See further details below.
Built based on documentation at Touch Portal Plugin API.
The simplest way of getting started, is to implement the ITouchPortalEventHandler
and use TouchPortalFactory
to create a client.
And then Connect to Touch Portal before sending or receiving events.
public class SamplePlugin : ITouchPortalEventHandler
{
public string PluginId => "Plugin.Id"; //Replace "Plugin.Id" with your unique id.
private readonly ITouchPortalClient _client;
public SamplePlugin()
{
_client = TouchPortalFactory.CreateClient(this);
}
public void Run()
{
_client.Connect();
}
...
More information on the original Wiki, or see the Sample project in this repository.
Drop-in replacement for oddbear's
TouchPortalSDK as of his v0.30.0-beta2, except:
- The
ActionEvent.Data
property, which was an array or key-value pairs, is now aDictionary<string, string>
with each data ID mapped to its corresponding value. See the SamplePllugin.cs changes on this commit for how to update (but now you can alsomessage.Data.TryGetValue("myDataId", out string value)
, for example).
Since oddbear's
TouchPortalSDK v 0.30.0 release version, the paths have diverged further, most notably in the handling of TP Connectors.
- Optimized TP message output by skipping a byte array copy step for appending the terminating newline after each JSON struct.
- Published .NET6 and .NET7 builds.
Both changes affect the feature which parses the "Long" connector ID from the short ID notification events into individual key/value fields (see notes for v0.43.0-mp below).
- Connector data key names are now truncated if
TouchPortalOptions.ActionDataIdSeparator
is set, just like action/connector data keys. - Fix that the "pc_plugin-name_" part wasn't properly stripped from the "actual" connector ID.
- Add TP API v6
parentGroup
parameter for dynamic state creation. - Add static
TouchPortalOptions.ValidateCommandParameters
setting to bypass all parameter validation when creating new Command types.
- Add
ConnectorChangeEvent.Data
property to get Connector data members (structure is identical to Actions).ConnectorChangeEvent
andActionEvent
now have a common base classDataContainerEventBase
. commit - Add
ShortConnectorIdNotification
event. commit - Add
ConnectorUpdateShort()
command to send connector updates based on theirshortId
(from the above notification event).
commit sample - Add
TouchPortalClient.IsConnected
property. TouchPortalClient
now sends theOnCloseEvent()
to the plugin before disconnecting, so the plugin can send any final data updates, etc (unless TP just crashed or quit, of course).ShortConnectorIdNotificationEvent.Data
property will parse all the|setting1=testvalue|setting2=anothervalue
action data pairs from the longconnectorId
string into aDictionary<string, string>
. Also theActualConnectorId
property is available to get the actual connector ID part (before any data=value pairs).
commit- Add static
TouchPortalOptions.ActionDataIdSeparator
option to split action data IDs on a character and only store the last part in the dictionary key (eg. for IDs like<plugin>.<category>.<action>.<data1>
one could split on the period and have much shorter/simpler key lookups). commit
- Does not crash on shutdown. Your plugin code can clean up and shut down properly.
- Benchmarked at around 30-50% better performance/throughput in several areas like JSON de-serialization and actual socket efficiency (removes 2 layers of buffers and reads/writes UTF8 JSON bytes directly).
- Log verbosity at the Info level greatly reduced. Logging in general improved and made more consistent, especially at Debug level.
Working examples at: