Documentation
¶
Overview ¶
Package plugin provides an event based sdk of the TouchPortal api.
Index ¶
- func ParsepluginEvent(s string) (pluginEvent, error)
- type Plugin
- func (p *Plugin) Done() <-chan bool
- func (p *Plugin) OnAction(handler func(event client.ActionMessage), actionID string)
- func (p *Plugin) OnClosePlugin(handler func(event client.ClosePluginMessage))
- func (p *Plugin) OnInfo(handler func(event client.InfoMessage))
- func (p *Plugin) Register() error
- func (p *Plugin) Settings(s interface{})
- func (p *Plugin) UpdateState(id string, value string) error
- type SettingsUpdated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParsepluginEvent ¶
Types ¶
type Plugin ¶
type Plugin struct { ID string TouchPortalVersion string SdkVersion int PluginVersion int // contains filtered or unexported fields }
func NewPluginWithClient ¶
NewPluginWithClient creates, initialises and returns a TouchPortal plugin instance allowing the usage of a custom client instance
func (*Plugin) Done ¶
Done provides an unbuffered, blocking, channel that can be used to verify that the Plugin has finished it's run and cleaned up used resources.
func (*Plugin) OnAction ¶
func (p *Plugin) OnAction(handler func(event client.ActionMessage), actionID string)
OnAction allows the registration of an event handler to the "action" TouchPortal message. The matching of the actionId parameter to the one sent by TouchPortal is handled for you and your passed handler function will only be executed if it matches.
func (*Plugin) OnClosePlugin ¶
func (p *Plugin) OnClosePlugin(handler func(event client.ClosePluginMessage))
OnClosePlugin allows the registration of an event handler to the "closePlugin" TouchPortal message. A default handler is already in place to close down the plugin itself but you may wish to add an additional hook so you can carry out other shutdown tasks.
func (*Plugin) OnInfo ¶
func (p *Plugin) OnInfo(handler func(event client.InfoMessage))
OnInfo allows the registration of an event handler to the "info" TouchPortal message. As the "info" message is only sent as a part of the registration process it is necessary to register any custom handlers before plugin.Register function is called.
func (*Plugin) Register ¶
Register asks the TouchPortal plugin instance to handle the registration process with TouchPortal. It ensures that any settings are synced to the SDK and registers a handler that allows the SDK to deal with shutdown requests.
func (*Plugin) Settings ¶
func (p *Plugin) Settings(s interface{})
Settings allows you to provide a reference to a struct that will be populated by TouchPortal when the plugin registers itself or a settings update occurs.
It works in a similar way to standard json Marshal/Unmarshal and is even driven by the same struct tags.
Currently only string and int types are supported
type settings struct { Host string `json:"Host"` Port int `json:"Port,string"` } func main() { p := NewPlugin(...) s := &settings{} p.Settings(s) p.Register() // p will now contain any settings that TouchPortal returned }
Interestingly it's important to note that TouchPortal string encodes both string and integer values so when Unmarshaling to an int you will need to ensure you mark it as ",string" as shown above.
type SettingsUpdated ¶
type SettingsUpdated interface {
IsUpdated()
}
SettingsUpdated implemented on the struct you use to power your plugins settings will allow you to be made aware when the settings have been updated by TouchPortal.