xpweb

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: BSD-3-Clause Imports: 20 Imported by: 0

README

github.com/janeprather/xpweb

Go Reference

An X-Plane 12 web API client package.

This is a work in progress. This repository may be destroyed or have updates force pushed.

Documentation

Overview

Package xpweb provides client functionality for the X-Plane 12 web API.

https://developer.x-plane.com/article/x-plane-web-api/

All use cases will involve instantiating an Client object with the NewClient function. This may return an error if a bad URL has been provided.

client, err := webxp.NewClient(nil)

The default target URL will be http://localhost:8086, however if X-Plane.exe was started with the web service running on a different port, e.g. via a --web_server_port=8088 argument, the appropriate URL may be specified during or after Client instantiation. Additonally, a custom http.RoundTripper may be specified as the transport.

client, err := webxp.NewClient(&webxp.ClientConfig{
	URL:       apiURL,
	Transport: apiTransport,
})

If the calling application will be establishing a websocket connection, then handlers for the result, command update, and dataref update messages received from the websocket service can be specified in the ClientConfig object as well.

handleResult = func(msg *WSMessageResult) {
	output := fmt.Sprintf("request %d (%s) result: %v", msg.ReqID, msg.Req.Type, msg.Success)
	if msg.ErrorMessage != "" {
		output += fmt.Sprintf(" (%s)", msg.ErrorMessage)
	}
	fmt.Println(output)
}

handleDatarefUpdate := func(msg *xpweb.WSMessageDatarefUpdate) {
	var drefUdates []string
	for _, val := range msg.Data {
		drefUdates = append(drefUdates, fmt.Sprintf("  %s: %v\n", val.Dataref.Name, val.Value))
	}
	fmt.Printf("dataref(s) update:\n%s", strings.Join(drefUdates, ""))
}

handleCommandUpdate := func(msg *xpweb.WSMessageCommandUpdate) {
	var cmdUdates []string
	for _, val := range msg.Data {
		cmdUdates = append(cmdUdates, fmt.Sprintf("  %s: %v\n", val.Command.Name, val.IsActive))
	}
	fmt.Printf("command(s) update:\n%s", strings.Join(cmdUdates, ""))
}

client, err := webxp.NewClient(&webxp.ClientConfig{
	CommandUpdateHandler: handleCommandUpdate,
	DatarefUpdateHandler: handleDatarefUpdate,
	ResultHandler:        handleResult,
	URL:                  apiURL,
	Transport:            apiTransport,
})

After instantiation, and after any restart of the simulator, the cache of command and dataref values needs to be reloaded from the simulator. The ID values for commands or datarefs are not guaranteed to remain unchanged from one simulator session to the next.

if err := client.LoadCache(ctx); err != nil {
	return err
}

A significant portion of this package is broken up into REST-specific and websocket-specific functionality. While some of the more agnostic methods are available via the Client object, much of the API functions used by calling applications will be done using either the WSClient or RESTClient objects accessible via the Client object.

xpREST := client.REST
xpWS := client.WS

DatarefValue objects returned from either the REST or websocket service are type-agnostic. They have a Value attribute of any type. If the type of the dataref values is known, a suitable method may be used to return the value as the correct type.

For example, fetching a string value:

acfNameVal, err := client.REST.GetDatarefValue(ctx, "sim/aircraft/view/acf_ui_name")
if err != nil {
	return err
}
fmt.Printf("Loaded Aircraft: %s\n", acfNameVal.GetStringValue())

Will produce output like:

Loaded Aircraft: Cessna Skyhawk (G1000)

Or, fetching other types of values...

numTanksVal, err := client.REST.GetDatarefValue(ctx, "sim/aircraft/overflow/acf_num_tanks")
if err != nil {
	return fmt.Errorf("GetDatarefValue(): %w", err)
}
numTanks := numTanksVal.GetIntValue()
fmt.Printf("Number of tanks: %d\n", numTanks)

fuelVal, err := client.REST.GetDatarefValue(ctx, "sim/flightmodel/weight/m_fuel")
if err != nil {
	return err
}
fuel := fuelVal.GetFloatArrayValue()

for idx := range numTanks {
	fmt.Printf("Tank %d: %.3f\n", idx, fuel[idx])
}

Would produce output like:

Number of tanks: 2
Tank 0: 2.481
Tank 1: 2.481

Dataref values can be set in their entirety, for example, to reduce fuel in all tanks and apply the entire array of fuel values at once:

for idx, tankFuel := range fuel {
	fuel[idx] = tankFuel / 2
}

err = client.REST.SetDatarefValue(ctx, "sim/flightmodel/weight/m_fuel", fuel)
if err != nil {
	return err
}

Or, for array values, a single element at a specified index may have its value set, for example to halve the fuel in only the first tank:

err = client.REST.SetDatarefElementValue(ctx, "sim/flightmodel/weight/m_fuel", 0, fuel[0] / 2)
if err != nil {
	return err
}

Consants of known dataref names are provided in the github.com/janeprather/xpweb/names/dataref package, and may help avoid repeating string literals and the risk of typos going undetected during lint/build. Note that these will be msising values which are specific to third party aircraft and plugins.

acfNameVal, err := client.REST.GetDatarefValue(ctx, dataref.SimAircraftView_acf_ui_name)

Command activation requires specifying a duration for the command. This can be a zero value for commands which are performed instantly, like turning a switch on, or for a set number of seconds for longer commands like starting an engine.

if err := client.REST.ActivateCommand(ctx, "sim/engines/engage_starters", 2); err != nil {
	return err
}

Constants of known command names are provided in the github.com/janeprather/xpweb/names/command package, and may help avoid repeating string literals and the risk of typos going undetected during lint/build. Note that these will be missing values which are specific to third party aircraft and plugins.

err := client.REST.ActivateCommand(ctx, command.SimElectrical_battery_1_on, 0)

To start using the websocket service, establish a connection.

if err := client.WS.Connect(); err != nil {
	return err
}
defer client.WS.Close()

All outbound websocket requests are instantiated with WSClient.NewReq. One of several methods should be used to apply appropriate type and params to the request.

The chained WSReq instantiation can be finished off with a WSReq.Send call to submit the request.

if err := xpWS.NewReq().DatarefSubscribe(
	xpWS.NewDataref("sim/flightmodel/weight/m_fuel").WithIndexArray([]int{0, 1}),
).Send(); err != nil {
	return err
}

Index

Constants

View Source
const (
	MessageTypeResult             string = "result"
	MessageTypeDatarefSub         string = "dataref_subscribe_values"
	MessageTypeDatarefUpdate      string = "dataref_update_values"
	MessageTypeDatarefUnsub       string = "dataref_unsubscribe_values"
	MessageTypeDatarefSet         string = "dataref_set_values"
	MessageTypeCommandSub         string = "command_subscribe_is_active"
	MessageTypeCommandUnsub       string = "command_unsubscribe_is_active"
	MessageTypeCommandUpdate      string = "command_update_is_active"
	MessageTypeCommandSetIsActive string = "command_set_is_active"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	API struct {
		Versions []string `json:"versions"`
	} `json:"api"`
	XPlane struct {
		Version string `json:"version"`
	} `json:"x-plane"`
}

type Client added in v0.7.0

type Client struct {
	REST *RESTClient
	WS   *WSClient
	// contains filtered or unexported fields
}

Client is an X-Plane Web API client.

func NewClient added in v0.7.0

func NewClient(config *ClientConfig) (client *Client, err error)

NewClient instantiates and returns a pointer to a new Client object.

func (*Client) GetCommandByID added in v0.7.0

func (c *Client) GetCommandByID(id uint64) (cmd *Command)

GetCommandByID returns the Command object with the specified ID value. If no such command is cached, a value of nil will be returned.

func (*Client) GetCommandByName added in v0.7.0

func (c *Client) GetCommandByName(name string) (cmd *Command)

GetCommandByName returns the Command object with the specified name. If no such command is cached, a value of nil will be returned.

func (*Client) GetCommandID added in v0.7.0

func (c *Client) GetCommandID(name string) (id uint64)

GetCommandID returns the ID of the Command with the specified name. If no such command is found, a value of zero is returned.

func (*Client) GetCommandName added in v0.7.0

func (c *Client) GetCommandName(id uint64) (name string)

GetCommandName returns the name of the Command with the specified ID. If no such command is found, an empty string value is returned.

func (*Client) GetDatarefByID added in v0.7.0

func (c *Client) GetDatarefByID(id uint64) (dref *Dataref)

GetDatarefByID returns the Dataref object with the specified ID. If no such dataref is cached, a value of nil will be returned.

func (*Client) GetDatarefByName added in v0.7.0

func (c *Client) GetDatarefByName(name string) (dref *Dataref)

GetDatarefByName returns the Dataref object with the specified name. If no such dataref is cached, a value of nil will be returned.

func (*Client) GetDatarefID added in v0.7.0

func (c *Client) GetDatarefID(name string) (id uint64)

GetDatarefID returns the ID of the Dataref with the specified name. If no such dataref is found, an value of zero is returned.

func (*Client) GetDatarefName added in v0.7.0

func (c *Client) GetDatarefName(id uint64) (name string)

GetDatarefName returns the name of the Dataref with the specified ID. If no such dataref is found, an empty string value is returned.

func (*Client) LoadCache added in v0.7.0

func (c *Client) LoadCache(ctx context.Context) error

type ClientConfig added in v0.7.0

type ClientConfig struct {
	// An optional URL.  If unspecified, http://localhost:8086 will be used.
	URL string
	// An optional http.RoundTripper which will be used to perform the HTTP requests.  If left
	// unspecified, the http.DefaultTransport will be used.
	Transport http.RoundTripper
	// The handler function for command update messages received from the websocket service.
	CommandUpdateHandler CommandUpdateHandler
	// The handler function for dataref update messages received from the websocket service.
	DatarefUpdateHandler DatarefUpdateHandler
	// The handler function for result messages received from the websocket service.
	ResultHandler ResultHandler
}

ClientConfig is a structure which may optionall be passed to NewClient().

type Command added in v0.4.0

type Command struct {
	// The ID of the command.  This may change between simulator sessions, but will remain static
	// within any given session, including across aircraft loads and unloads.
	ID uint64 `json:"id"`
	// The fully qualified name of the command, as used by the simulator and plugins.
	Name string `json:"name"`
	// The human readable description of what the command does.
	Description string `json:"description"`
}

Dataref is a definition of a command provided by the simulator.

type CommandStatus added in v0.7.0

type CommandStatus struct {
	Command  *Command
	IsActive bool
}

CommandStatus contains the active status of a Command.

type CommandUpdateHandler added in v0.7.0

type CommandUpdateHandler func(*WSMessageCommandUpdate)

CommandUpdateHandler is a function which performs some action for any incoming WSMessageCommandUpdate sent by the websocket service.

type Dataref

type Dataref struct {
	// The ID of the dataref.  This may change between simulator sessions, but will remain static
	// within any given session, including across aircraft loads and unloads.
	ID uint64 `json:"id"`
	// The fully qualified name of the dataref, as used by the simulator and plugins.
	Name string `json:"name"`
	// The type of the dataref value(s).
	ValueType ValueType `json:"value_type"`
}

Dataref is a definition of a dataref provided by the simulator.

type DatarefUpdateHandler added in v0.7.0

type DatarefUpdateHandler func(*WSMessageDatarefUpdate)

DatarefUpdateHandler is a function which performs some action for any incoming WSMessageDatarefUpdate sent by the websocket service.

type DatarefValue

type DatarefValue struct {
	Dataref *Dataref
	Value   any
}

DatarefValue is a type-agnostic object containing a dataref value. The ValueType attribute may be checked if necessary, and an appropriate method may be called to return the typed value.

  • float - DatarefValue.GetFloatValue
  • double - DatarefValue.GetFloatValue
  • int - DatarefValue.GetIntValue
  • int_array - DatarefValue.GetIntArrayValue
  • float_array - DatarefValue.GetFloatArrayValue
  • data - DatarefValue.GetByteArrayValue or DatarefValue.GetStringValue

func (*DatarefValue) GetByteArrayValue

func (v *DatarefValue) GetByteArrayValue() []byte

GetByteArrayValue returns a byte slice representation of a data dataref value.

func (*DatarefValue) GetFloatArrayValue

func (v *DatarefValue) GetFloatArrayValue() []float64

GetFloatArrayValue returns a float slice dataref value.

func (*DatarefValue) GetFloatValue

func (v *DatarefValue) GetFloatValue() float64

GetFloatValue returns a float32 dataref value.

func (*DatarefValue) GetIntArrayValue

func (v *DatarefValue) GetIntArrayValue() []int

GetIntArrayValue returns an int slice dataref value.

func (*DatarefValue) GetIntValue

func (v *DatarefValue) GetIntValue() int

GetIntValue returns an int dataref value.

func (*DatarefValue) GetStringValue

func (v *DatarefValue) GetStringValue() string

GetStringValue returns a string representation of a data dataref value.

type ErrorResponse

type ErrorResponse struct {
	ErrorCode    string `json:"error_code"`
	ErrorMessage string `json:"error_message"`
}

ErrorResponse is an error response received from the API.

func (ErrorResponse) Error added in v0.4.0

func (e ErrorResponse) Error() string

Error allows ErrorResponse to implement the error interface.

type RESTClient added in v0.7.0

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

RestClient provides functions and attributes related to REST API operations.

func (*RESTClient) ActivateCommand added in v0.7.0

func (c *RESTClient) ActivateCommand(ctx context.Context, name string, duration float64) error

ActivateCommand runs a command for a fixed duration. A zero duration will cause the command to be triggered on and off immediately but not be held down. The maximum duration is 10 seconds.

func (*RESTClient) GetCapabilities added in v0.7.0

func (c *RESTClient) GetCapabilities(ctx context.Context) (*Capabilities, error)

func (*RESTClient) GetCommands added in v0.7.0

func (c *RESTClient) GetCommands(ctx context.Context) ([]*Command, error)

GetCommands fetches and returns a list of available commands from the simulator.

func (*RESTClient) GetCommandsCount added in v0.7.0

func (c *RESTClient) GetCommandsCount(ctx context.Context) (int, error)

GetCommandsCount returns the number of total commands available.

func (*RESTClient) GetDatarefValue added in v0.7.0

func (c *RESTClient) GetDatarefValue(ctx context.Context, name string) (*DatarefValue, error)

GetDatarefValue returns a type-agnostic DatarefValue object containing the value of the dataref with the specified name.

func (*RESTClient) GetDatarefs added in v0.7.0

func (c *RESTClient) GetDatarefs(ctx context.Context) ([]*Dataref, error)

GetDatarefs fetches and returns a list of available datarefs from the simulator.

func (*RESTClient) GetDatarefsCount added in v0.7.0

func (c *RESTClient) GetDatarefsCount(ctx context.Context) (int, error)

GetDatarefsCount returns the number of total datarefs available.

func (*RESTClient) SetDatarefElementValue added in v0.7.0

func (c *RESTClient) SetDatarefElementValue(
	ctx context.Context,
	name string,
	index int,
	value any,
) error

SetDatarefElementValue applies the specified value to the specified element index of the specified array type dataref.

func (*RESTClient) SetDatarefValue added in v0.7.0

func (c *RESTClient) SetDatarefValue(ctx context.Context, name string, value any) error

SetDatarefValue applies the specified value to the specified dataref.

type ResultHandler added in v0.7.0

type ResultHandler func(*WSMessageResult)

ResultHandler is a function which performs some action for a given WSMessageResult sent back from the websocket service.

type ValueType

type ValueType string

ValueType is a string representing a dataref value type which may be provided by the simulator.

const (
	ValueTypeFloat      ValueType = "float"
	ValueTypeDouble     ValueType = "double"
	ValueTypeInt        ValueType = "int"
	ValueTypeIntArray   ValueType = "int_array"
	ValueTypeFloatArray ValueType = "float_array"
	ValueTypeData       ValueType = "data"
)

type WSClient added in v0.7.0

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

XPWebsocketClient provides functions and attributes related to Websocket API operations.

func (*WSClient) Close added in v0.7.0

func (xpc *WSClient) Close()

WSClose closes an established websocket connection.

func (*WSClient) Connect added in v0.7.0

func (xpc *WSClient) Connect() (err error)

WSConnect establishes a websocket connection to the web API. If an application calls this function, it must read from the channel returned by XPClient.Messages() to avoid a deadlock.

func (*WSClient) NewCommand added in v0.7.0

func (wsc *WSClient) NewCommand(name string, isActive bool) *WSCommand

NewCommand behaves like NewWSCommand except that it takes a command name as an argument and uses the Client object's loaded command cache to map the command name to its ID value. If the command does not exist, an ID value of 0 will be used and a websocket request containing the returned value should fail.

func (*WSClient) NewDataref added in v0.7.0

func (wsc *WSClient) NewDataref(name string) *WSDataref

NewDataref behaves like NewWSDataref except that it takes a dataref name as the argument and uses the Client object's loaded dataref cache to map the dataref name to its ID value. If the dataref does not exist, an ID value of 0 will be used and a websocket request containing the returned value should fail.

func (*WSClient) NewDatarefValue added in v0.7.0

func (wsc *WSClient) NewDatarefValue(name string, value any) *WSDatarefValue

NewWSDatarefValue behaves like NewWSDatarefValue except that it takes a dataref name as the argument and uses the Client object's loaded dataref cache to map the dataref name to its ID value. If the dataref does not exist, an ID value of 0 will be used and a websocket request containing the returned value should fail.

func (*WSClient) NewReq added in v0.7.0

func (wsc *WSClient) NewReq() *WSReq

NewReq instantiates a new websocket request object having the next available request ID. Type and params are not set, and an appropriate method should be called to apply them.

For example:

xpWS.NewReq().CommandSetIsActive(
	xpWS.NewCommand("sim/electrical/battery_1_on", true).WithDuration(0),
)

func (*WSClient) Send added in v0.7.0

func (c *WSClient) Send(req *WSReq) error

SendToWS marshals the specified object into JSON and sends it over the websocket connection.

type WSCommand added in v0.7.0

type WSCommand struct {
	ID       uint64   `json:"id"`
	IsActive bool     `json:"is_active"`
	Duration *float64 `json:"duration,omitempty"`
}

WSCommand is a structure which is included in websocket requests to set whether a command is active. It is easiest to instantiate a WSCommand object using [WithCommand] or [Client.WithCommand].

func NewWSCommand added in v0.7.0

func NewWSCommand(id uint64, isActive bool) *WSCommand

NewWSCommand returns a WSCommand which can be passed to be passed to [NewWSReqCommandSetIsActive], and which will apply the command for an indefinite period. To perform an instant toggle of the command (e.g. a button press) or set a duration (e.g. pressing a starter button), use the [WithCommand.Timed] method on the returned value.

Indefinite:

WithCommand(id, true)

Instant:

WithCommand(id, true).WithDuration(0)

For a set number of seconds:

WithCommand(id, true).WithDuration(2.5)

func (*WSCommand) WithDuration added in v0.7.0

func (c *WSCommand) WithDuration(duration float64) *WSCommand

WithDuration applies a duration to the WSCommand object. It returns a pointer to the WSCommand object so that it can be chained with WSCommand instantiation. A value of zero makes it an immediate toggle (e.g. pressing and releasing a button right away). A positive value sets the number of seconds to wait between reverting the active value.

type WSCommandStatusMap added in v0.7.0

type WSCommandStatusMap map[uint64]*CommandStatus

WSCommandStatusMap is a structure of the data included in a command_update_is_active message from the websocket service.

func (*WSCommandStatusMap) UnmarshalJSON added in v0.7.0

func (m *WSCommandStatusMap) UnmarshalJSON(data []byte) error

UnmarshalJSON handles converting data from the JSON data into the desired structure.

type WSDataref added in v0.7.0

type WSDataref struct {
	ID    uint64 `json:"id"`
	Index any    `json:"index,omitempty"`
}

WSDataref is a structure which is included in a websocket requests to sub/unsub datarefs. It is easiest to instantiate a WSDataref object using WithDataref() or WithDatarefIndex().

func NewWSDataref added in v0.7.0

func NewWSDataref(id uint64) *WSDataref

NewWSDataref returns a pointer to a WSDataref object with the specified dataref ID value.

func (*WSDataref) WithIndex added in v0.7.0

func (d *WSDataref) WithIndex(index int) *WSDataref

WithIndex applies the specified single index to the WSDataref object. It returns a pointer to the WSDataref so that it can be chained with WSDataref instantiation.

func (*WSDataref) WithIndexArray added in v0.7.0

func (d *WSDataref) WithIndexArray(indexes []int) *WSDataref

WithIndexArray applies the specified slice of index values to the WSDataref object. It returns a pointer to the WSDataref so that it can be chained with WSDataref instantiation.

type WSDatarefValue added in v0.7.0

type WSDatarefValue struct {
	ID    uint64 `json:"id"`
	Value any    `json:"value"`
	Index *int   `json:"index,omitempty"`
}

WSDataref is a structure which is included in a websocket requests to sub/unsub datarefs. It is easiest to instantiate a WSDataref object using WithDataref() or WithDatarefIndex().

func NewWSDatarefValue added in v0.7.0

func NewWSDatarefValue(id uint64, value any) *WSDatarefValue

WithDataref returns a pointer to a WSDataref object with the specified dataref ID value.

func (*WSDatarefValue) WithIndex added in v0.7.0

func (d *WSDatarefValue) WithIndex(index int) *WSDatarefValue

WithIndex applies the specified single index to the WSDataref object. It returns a pointer to the WSDataref so that it can be chained with WSDataref instantiation.

type WSDatarefValuesMap added in v0.7.0

type WSDatarefValuesMap map[uint64]*DatarefValue

func (*WSDatarefValuesMap) UnmarshalJSON added in v0.7.0

func (m *WSDatarefValuesMap) UnmarshalJSON(data []byte) error

type WSMessageCommandUpdate added in v0.7.0

type WSMessageCommandUpdate struct {
	Type string `json:"type"`
	Data WSCommandStatusMap
}

WSMessageCommandUpdate is the structure of a command_update_is_active message from the websocket service.

func (WSMessageCommandUpdate) GetType added in v0.7.0

func (m WSMessageCommandUpdate) GetType() string

type WSMessageDatarefUpdate added in v0.7.0

type WSMessageDatarefUpdate struct {
	Type string             `json:"type"`
	Data WSDatarefValuesMap `json:"data"`
}

func (WSMessageDatarefUpdate) GetType added in v0.7.0

func (m WSMessageDatarefUpdate) GetType() string

type WSMessageResult added in v0.7.0

type WSMessageResult struct {
	ReqID        uint64 `json:"req_id"`
	Type         string `json:"type"`
	Success      bool   `json:"success"`
	ErrorCode    string `json:"error_code"`
	ErrorMessage string `json:"error_message"`
	Req          *WSReq `json:"-"`
}

func (WSMessageResult) GetType added in v0.7.0

func (m WSMessageResult) GetType() string

type WSReq added in v0.7.0

type WSReq struct {
	ReqID  uint64 `json:"req_id"`
	Type   string `json:"type"`
	Params any    `json:"params"`
	// contains filtered or unexported fields
}

WSReq is an object containing the payload of a websocket request. A WSReq object is easiest to instantiate using the function appropriate for the type of request being made.

  • [WSClient.NewWSReqCommandSetIsActive] (command_set_is_active)
  • [WSClient.NewWSReqDatarefSubscribe] (dataref_subscribe_values)
  • [WSClient.NewWSReqDatarefUnsubscribe] (dataref_unsubscribe_values, specified datarefs)
  • [WSClient.NewWSReqDatarefUnsubscribeAll] (dataref_unsubscribe_values, all datarefs)

func (*WSReq) CommandSetIsActive added in v0.7.0

func (r *WSReq) CommandSetIsActive(cmds ...*WSCommand) *WSReq

CommandSetIsActive applies a type of command_set_is_active and appropriate params to the WSReq object. It returns a pointer to the WSReq object so that it can be chained with WSReq instantiation. Pointers to one or more WSCommand objects should be passed as args.

func (*WSReq) CommandSubscribe added in v0.7.0

func (r *WSReq) CommandSubscribe(cmdNames ...string) *WSReq

CommandSubscribe applies a type of command_subscribe_is_active and appropriate params to the WSReq object. It returns a pointer to the WSReq object so that it can be chained with WSReq instantiation. Command name values should be passed as args.

func (*WSReq) CommandUnsubscribe added in v0.7.0

func (r *WSReq) CommandUnsubscribe(cmdNames ...string) *WSReq

CommandUnsubscribe applies a type of command_unsubscribe_is_active and appropriate params to the WSReq object. It returns a pointer to the WSReq object so that it can be chained with WSReq instantiation. Command name values should be passed as args.

func (*WSReq) CommandUnsubscribeAll added in v0.7.0

func (r *WSReq) CommandUnsubscribeAll() *WSReq

DatarefUnsubscribeAll applies a type of command_unsubscribe_is_active and a params value which will unsubscribe from all currently subscribed datarefs. It returns a pointer to the WSReq object so that it ican be chained with WSReq instantiation.

func (*WSReq) DatarefSet added in v0.7.0

func (r *WSReq) DatarefSet(datarefs ...*WSDatarefValue) *WSReq

DatarefSet applies a type of dataref_set_values and appropriate params to the WSReq object. It returns a pointer to the WSReq object so that it can be chained with WSReq instantiation. Pointers to one or more WSDatarefValue objects should be passed as args.

func (*WSReq) DatarefSubscribe added in v0.7.0

func (r *WSReq) DatarefSubscribe(datarefs ...*WSDataref) *WSReq

DatarefSubscribe applies a type of dataref_subscribe_values and appropriate params to the WSReq object. It returns a pointer to the WSReq object so that it can be chained with WSReq instantiation. Pointers to one or more WSDataref objects should be passed as args.

func (*WSReq) DatarefUnsubscribe added in v0.7.0

func (r *WSReq) DatarefUnsubscribe(datarefs ...*WSDataref) *WSReq

DatarefUnsubscribe applies a type of dataref_unsubscribe_values and appropriate params to the WSReq object. It returns a pointer to the WSReq object so that it can be chained with WSReq instantiation. Pointers to one or more WSDataref objects should be passed as args.

func (*WSReq) DatarefUnsubscribeAll added in v0.7.0

func (r *WSReq) DatarefUnsubscribeAll() *WSReq

DatarefUnsubscribeAll applies a type of dataref_unsubscribe_values and a params value which will unsubscribe from all currently subscribed datarefs. It returns a pointer to the WSReq object so that it ican be chained with WSReq instantiation.

func (*WSReq) Send added in v0.7.0

func (r *WSReq) Send() error

Send submits the WSReq object to the websocket service.

Directories

Path Synopsis
cmd
test-client command
names
command
Package command provides known names as string constants to limit repetition of string literals and the risk of typos that can't be caught during lint/compile.
Package command provides known names as string constants to limit repetition of string literals and the risk of typos that can't be caught during lint/compile.
dataref
Package dataref provides known names as string constants to limit repetition of string literals and the risk of typos that can't be caught during lint/compile.
Package dataref provides known names as string constants to limit repetition of string literals and the risk of typos that can't be caught during lint/compile.

Jump to

Keyboard shortcuts

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