client

package
v0.0.0-...-351e1a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientMessageTypeNames

func ClientMessageTypeNames() []string

func NewPairMessage

func NewPairMessage(id string) *pairMessage

NewPairMessage provides a ready to go client.pairMessage that can be sent to TouchPortal as a part of the plugin registration flow.

func NewStateUpdateMessage

func NewStateUpdateMessage(id string, value string) *stateUpdateMessage

NewStateUpdateMessage provides a ready to go client.stateUpdateMessage that can be sent to TouchPortal.

Types

type ActionMessage

type ActionMessage struct {
	Message
	PluginID string          `json:"pluginId"`
	ActionID string          `json:"actionId"`
	Data     json.RawMessage `json:"data"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) AddMessageHandler

func (c *Client) AddMessageHandler(msgType ClientMessageType, handler func(e interface{}))

func (*Client) Close

func (c *Client) Close()

func (*Client) Dispatch

func (c *Client) Dispatch(mType ClientMessageType, event interface{})

func (*Client) Ready

func (c *Client) Ready() <-chan bool

func (*Client) Run

func (c *Client) Run(ctx context.Context)

func (*Client) SendMessage

func (c *Client) SendMessage(m interface{}) error

SendMessage will send a JSON serialised version of the passed interface{} to TouchPortal, returning an error if it was unable to complete the task

func (*Client) SetMessageProcessor

func (c *Client) SetMessageProcessor(msgType ClientMessageType, processor func(msg json.RawMessage) (interface{}, error))

SetMessageProcessor lets you use your own handling of incoming message types. Your provided processor function should turn the provided raw JSON into the interface you're expecting - probably a struct of some sort.

type ClientMessageType

type ClientMessageType int
const (
	MessageTypeAction ClientMessageType = iota
	MessageTypeClosePlugin
	MessageTypeInfo
	MessageTypePair
	MessageTypeSettings
	MessageTypeStateUpdate
)

func ClientMessageTypeString

func ClientMessageTypeString(s string) (ClientMessageType, error)

ClientMessageTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ClientMessageTypeValues

func ClientMessageTypeValues() []ClientMessageType

ClientMessageTypeValues returns all values of the enum

func ParseClientMessageType

func ParseClientMessageType(s string) (ClientMessageType, error)

func (ClientMessageType) IsAClientMessageType

func (i ClientMessageType) IsAClientMessageType() bool

IsAClientMessageType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ClientMessageType) MarshalJSON

func (i ClientMessageType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ClientMessageType

func (ClientMessageType) MarshalText

func (i ClientMessageType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ClientMessageType

func (ClientMessageType) MarshalYAML

func (i ClientMessageType) MarshalYAML() (interface{}, error)

MarshalYAML implements a YAML Marshaler for ClientMessageType

func (*ClientMessageType) Scan

func (i *ClientMessageType) Scan(value interface{}) error

func (ClientMessageType) String

func (i ClientMessageType) String() string

func (*ClientMessageType) UnmarshalJSON

func (i *ClientMessageType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ClientMessageType

func (*ClientMessageType) UnmarshalText

func (i *ClientMessageType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ClientMessageType

func (*ClientMessageType) UnmarshalYAML

func (i *ClientMessageType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements a YAML Unmarshaler for ClientMessageType

func (ClientMessageType) Value

func (i ClientMessageType) Value() (driver.Value, error)

type ClosePluginMessage

type ClosePluginMessage struct {
	Message
	PluginID string `json:"pluginId"`
}

type InfoMessage

type InfoMessage struct {
	Message
	Version       string          `json:"tpVersionString"`
	VersionCode   int             `json:"tpVersionCode"`
	SdkVersion    int             `json:"sdkVersion"`
	PluginVersion int             `json:"pluginVersion"`
	Settings      json.RawMessage `json:"settings"`
}

type Message

type Message struct {
	Type ClientMessageType `json:"type"`
}

type SettingsMessage

type SettingsMessage struct {
	Message
	RawValues json.RawMessage `json:"values"`
	Values    map[string]interface{}
}

type Socket

type Socket struct {
	// contains filtered or unexported fields
}

func NewSocket

func NewSocket(c net.Conn) *Socket

func (*Socket) Close

func (s *Socket) Close()

Close will close the underlying communication socket

func (*Socket) GetMessage

func (s *Socket) GetMessage() ([]byte, error)

GetMessage reads a single line from the connection. It blocks for a duration but plays nice and returns after the a 300ms deadline so you can handle graceful shutdowns.

func (*Socket) SendMessage

func (s *Socket) SendMessage(m []byte) error

SendMessage is a blocking call to send a message out via the socket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL