buttplug

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: ISC Imports: 10 Imported by: 3

README

go-buttplug

builds.sr.ht status Go Reference

A Go library for the Intiface Websocket API, which wraps the buttplug.io protocol.

Example

See package intiface's example.

Documentation

Overview

Package buttplug provides Go wrappers around the Intiface API, which is a wrapper around the buttplug.io specifications.

Most people should use package intiface instead. This package only supplies the messages and the Websocket implementation, but intiface allows those to automatically interact with the Intiface server.

Index

Constants

View Source
const Version = 2

Version is the buttplug.io schema version.

Variables

This section is empty.

Functions

func RegisterMessage

func RegisterMessage(new func() Message)

RegisterMessage registers a new message type. It call the constructor once to know the message type.

Types

type BatteryLevelCmd

type BatteryLevelCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
}

Requests that a BatteryLevel be retreived.

func (*BatteryLevelCmd) MessageID

func (b *BatteryLevelCmd) MessageID() ID

MessageID implements Message.

func (*BatteryLevelCmd) MessageType

func (b *BatteryLevelCmd) MessageType() MessageType

MessageType implements Message.

func (*BatteryLevelCmd) SetMessageID

func (b *BatteryLevelCmd) SetMessageID(id ID)

SetMessageID implements Message.

type BatteryLevelReading

type BatteryLevelReading struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Battery Level
	BatteryLevel float64 `json:"BatteryLevel"`
}

Returns a BatteryLevel read from a device.

func (*BatteryLevelReading) MessageID

func (b *BatteryLevelReading) MessageID() ID

MessageID implements Message.

func (*BatteryLevelReading) MessageType

func (b *BatteryLevelReading) MessageType() MessageType

MessageType implements Message.

func (*BatteryLevelReading) SetMessageID

func (b *BatteryLevelReading) SetMessageID(id ID)

SetMessageID implements Message.

type Broadcaster added in v0.0.2

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

Broadcaster is used for creating multiple event loops on the same Buttplug server. A zero-value Broadcaster instance is a valid instance.

func NewBroadcaster added in v0.0.2

func NewBroadcaster() *Broadcaster

NewBroadcaster creates a new broadcaster.

func (*Broadcaster) Listen added in v0.0.2

func (b *Broadcaster) Listen() <-chan Message

Listen returns a newly subscribed Op channel.

func (*Broadcaster) Start added in v0.0.2

func (b *Broadcaster) Start(src <-chan Message)

Start starts the broadcaster.

func (*Broadcaster) Subscribe added in v0.0.2

func (b *Broadcaster) Subscribe(ch chan<- Message)

Subscribe subscribes the given channel

type DeviceAdded

type DeviceAdded struct {
	// Used for non-direct-reply messages that can only be sent from server to
	// client, using the reserved system message Id of 0.
	ID SystemID `json:"Id"`
	// Name of the device
	DeviceName DeviceName `json:"DeviceName"`
	// Index used for referencing the device in device messages.
	DeviceIndex    DeviceIndex     `json:"DeviceIndex"`
	DeviceMessages json.RawMessage `json:"DeviceMessages"`
}

Notifies client that a device of a certain type has been added to the server.

func (*DeviceAdded) MessageID

func (d *DeviceAdded) MessageID() ID

MessageID implements Message.

func (*DeviceAdded) MessageType

func (d *DeviceAdded) MessageType() MessageType

MessageType implements Message.

func (*DeviceAdded) SetMessageID

func (d *DeviceAdded) SetMessageID(id ID)

SetMessageID implements Message.

type DeviceIndex

type DeviceIndex int // [0, max]

Index used for referencing the device in device messages.

type DeviceIndexMessage

type DeviceIndexMessage struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
}

type DeviceList

type DeviceList struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Array of device ids and names.
	Devices []struct {
		// Name of the device
		DeviceName DeviceName `json:"DeviceName"`
		// Index used for referencing the device in device messages.
		DeviceIndex    DeviceIndex     `json:"DeviceIndex"`
		DeviceMessages json.RawMessage `json:"DeviceMessages"`
	} `json:"Devices"`
}

List of all available devices known to the system.

func (*DeviceList) MessageID

func (d *DeviceList) MessageID() ID

MessageID implements Message.

func (*DeviceList) MessageType

func (d *DeviceList) MessageType() MessageType

MessageType implements Message.

func (*DeviceList) SetMessageID

func (d *DeviceList) SetMessageID(id ID)

SetMessageID implements Message.

type DeviceMessages

type DeviceMessages []string

A list of the messages a device will accept on this server implementation.

type DeviceMessagesEx

type DeviceMessagesEx struct {
	// Attributes for device message that have no attributes.
	StopDeviceCmd *NullMessageAttributes `json:"StopDeviceCmd,omitempty"`
	// Attributes for device messages.
	VibrateCmd *GenericMessageAttributes `json:"VibrateCmd,omitempty"`
	// Attributes for device messages.
	LinearCmd *GenericMessageAttributes `json:"LinearCmd,omitempty"`
	// Attributes for device messages.
	RotateCmd *GenericMessageAttributes `json:"RotateCmd,omitempty"`
	// Attributes for device message that have no attributes.
	LovenseCmd *NullMessageAttributes `json:"LovenseCmd,omitempty"`
	// Attributes for device message that have no attributes.
	VorzeA10CycloneCmd *NullMessageAttributes `json:"VorzeA10CycloneCmd,omitempty"`
	// Attributes for device message that have no attributes.
	KiirooCmd *NullMessageAttributes `json:"KiirooCmd,omitempty"`
	// Attributes for device message that have no attributes.
	SingleMotorVibrateCmd *NullMessageAttributes `json:"SingleMotorVibrateCmd,omitempty"`
	// Attributes for device message that have no attributes.
	FleshlightLaunchFW12Cmd *NullMessageAttributes `json:"FleshlightLaunchFW12Cmd,omitempty"`
	// Attributes for device message that have no attributes.
	BatteryLevelCmd *NullMessageAttributes `json:"BatteryLevelCmd,omitempty"`
	// Attributes for device message that have no attributes.
	RSSILevelCmd *NullMessageAttributes `json:"RSSILevelCmd,omitempty"`
	// Attributes for raw device messages.
	RawReadCmd *RawMessageAttributes `json:"RawReadCmd,omitempty"`
	// Attributes for raw device messages.
	RawWriteCmd *RawMessageAttributes `json:"RawWriteCmd,omitempty"`
	// Attributes for raw device messages.
	RawSubscribeCmd *RawMessageAttributes `json:"RawSubscribeCmd,omitempty"`
	// Attributes for raw device messages.
	RawUnsubscribeCmd *RawMessageAttributes `json:"RawUnsubscribeCmd,omitempty"`
}

A list of the messages a device will accept on this server implementation.

type DeviceName

type DeviceName string

Name of the device

type DeviceRemoved

type DeviceRemoved struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
}

Notifies client that a device of a certain type has been removed from the server.

func (*DeviceRemoved) MessageID

func (d *DeviceRemoved) MessageID() ID

MessageID implements Message.

func (*DeviceRemoved) MessageType

func (d *DeviceRemoved) MessageType() MessageType

MessageType implements Message.

func (*DeviceRemoved) SetMessageID

func (d *DeviceRemoved) SetMessageID(id ID)

SetMessageID implements Message.

type DialError

type DialError struct {
	Err error
}

DialError is emitted if the Websocket fails to dial.

func (*DialError) Error

func (err *DialError) Error() string

Error implements error.

func (*DialError) Unwrap

func (err *DialError) Unwrap() error

Unwrap returns err.Err.

type Error

type Error struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID           ID      `json:"Id"`
	ErrorMessage string  `json:"ErrorMessage"`
	ErrorCode    float64 `json:"ErrorCode"`
}

Signifies the server encountered an error while processing the message indicated by the id.

func (*Error) Error

func (e *Error) Error() string

Error makes the Error message implement the error interface.

func (*Error) MessageID

func (e *Error) MessageID() ID

MessageID implements Message.

func (*Error) MessageType

func (e *Error) MessageType() MessageType

MessageType implements Message.

func (*Error) SetMessageID

func (e *Error) SetMessageID(id ID)

SetMessageID implements Message.

type FeatureCount

type FeatureCount int // [1, max]

Number of features on device.

type FleshlightLaunchFW12Cmd

type FleshlightLaunchFW12Cmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Speed at which to move to designated position.
	Speed int `json:"Speed"`
	// Position to which to move Fleshlight.
	Position int `json:"Position"`
}

Sends speed and position command to the Fleshlight Launch Device denoted by the device index.

func (*FleshlightLaunchFW12Cmd) MessageID

func (f *FleshlightLaunchFW12Cmd) MessageID() ID

MessageID implements Message.

func (*FleshlightLaunchFW12Cmd) MessageType

func (f *FleshlightLaunchFW12Cmd) MessageType() MessageType

MessageType implements Message.

func (*FleshlightLaunchFW12Cmd) SetMessageID

func (f *FleshlightLaunchFW12Cmd) SetMessageID(id ID)

SetMessageID implements Message.

type GenericMessageAttributes

type GenericMessageAttributes struct {
	// Number of features on device.
	FeatureCount *FeatureCount `json:"FeatureCount,omitempty"`
	// Specifies granularity of each feature on the device.
	StepCount *[]int `json:"StepCount,omitempty"`
}

Attributes for device messages.

type ID

type ID int // [0, 4294967295]

User-set id for the message. 0 denotes system message and is reserved.

func (ID) IsServerEvent

func (id ID) IsServerEvent() bool

IsServerEvent returns true if ID is 0, indicating that it's an event from the server or an internal event.

type IDMessage

type IDMessage struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Message types that are expected to have an Id and nothing else.

type InternalError

type InternalError struct {
	// ID is 0 if the error is a background event loop error, or non-0 if it's
	// an event associated with a command.
	ID ID
	// Err is the error.
	Err error
	// Fatal is true if a reconnection is needed.
	Fatal bool
}

InternalError is a pseudo-message that is sent over the event channel on background errors.

func (*InternalError) Error

func (e *InternalError) Error() string

Error implements error.

func (*InternalError) MessageID

func (e *InternalError) MessageID() ID

MessageID returns 0.

func (*InternalError) MessageType

func (e *InternalError) MessageType() MessageType

MessageType implements Message.

func (*InternalError) SetMessageID

func (e *InternalError) SetMessageID(id ID)

SetMessageID panics.

func (*InternalError) Unwrap added in v0.0.3

func (e *InternalError) Unwrap() error

Unwrap returns e.Err.

type KiirooCmd

type KiirooCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Command to send to Kiiroo device.
	Command string `json:"Command"`
}

Sends a raw byte string to a Kiiroo Onyx/Pearl device.

func (*KiirooCmd) MessageID

func (k *KiirooCmd) MessageID() ID

MessageID implements Message.

func (*KiirooCmd) MessageType

func (k *KiirooCmd) MessageType() MessageType

MessageType implements Message.

func (*KiirooCmd) SetMessageID

func (k *KiirooCmd) SetMessageID(id ID)

SetMessageID implements Message.

type LinearCmd

type LinearCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Device linear movement times (milliseconds) and positions (floating
	// point, 0 < x < 1) keyed on linear actuator number, stepping will be
	// device specific.
	Vectors []struct {
		// Linear actuator number.
		Index int `json:"Index"`
		// Linear movement time in milliseconds.
		Duration float64 `json:"Duration"`
		// Linear movement position (floating point, 0 < x < 1), stepping will be
		// device specific.
		Position float64 `json:"Position"`
	} `json:"Vectors"`
}

Sends a linear movement command to a device that supports linear movements.

func (*LinearCmd) MessageID

func (l *LinearCmd) MessageID() ID

MessageID implements Message.

func (*LinearCmd) MessageType

func (l *LinearCmd) MessageType() MessageType

MessageType implements Message.

func (*LinearCmd) SetMessageID

func (l *LinearCmd) SetMessageID(id ID)

SetMessageID implements Message.

type Log

type Log struct {
	// Used for non-direct-reply messages that can only be sent from server to
	// client, using the reserved system message Id of 0.
	ID SystemID `json:"Id"`
	// Log level of message.
	LogLevel string `json:"LogLevel"`
	// Log message from server.
	LogMessage string `json:"LogMessage"`
}

Log message from the server.

func (*Log) MessageID

func (l *Log) MessageID() ID

MessageID implements Message.

func (*Log) MessageType

func (l *Log) MessageType() MessageType

MessageType implements Message.

func (*Log) SetMessageID

func (l *Log) SetMessageID(id ID)

SetMessageID implements Message.

type LovenseCmd

type LovenseCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Command to send to Lovense device.
	Command string `json:"Command"`
}

Sends a command string to a Lovense device. Command string will be verified by sender.

func (*LovenseCmd) MessageID

func (l *LovenseCmd) MessageID() ID

MessageID implements Message.

func (*LovenseCmd) MessageType

func (l *LovenseCmd) MessageType() MessageType

MessageType implements Message.

func (*LovenseCmd) SetMessageID

func (l *LovenseCmd) SetMessageID(id ID)

SetMessageID implements Message.

type Message

type Message interface {
	// MessageID returns the message's ID, or 0 if the message is a system
	// message.
	MessageID() ID
	// SetMessageID sets the message ID field. This is used for sending.
	SetMessageID(ID)
	// MessageType returns the message's type (object key).
	MessageType() MessageType
}

Message is an interface ethat all messages will satisfy. All types that are inside MessageType will implement the interface. Inside this type declaration lists all types that will satisfy the interface.

These types satisfy this interface:

  • OK
  • Error
  • Ping
  • Test
  • DeviceList
  • DeviceAdded
  • DeviceRemoved
  • RequestDeviceList
  • StopDeviceCmd
  • StopAllDevices
  • StartScanning
  • StopScanning
  • ScanningFinished
  • RequestLog
  • Log
  • RequestServerInfo
  • ServerInfo
  • FleshlightLaunchFW12Cmd
  • LovenseCmd
  • SingleMotorVibrateCmd
  • KiirooCmd
  • RawReadCmd
  • RawWriteCmd
  • RawSubscribeCmd
  • RawUnsubscribeCmd
  • RawReading
  • VorzeA10CycloneCmd
  • VibrateCmd
  • RotateCmd
  • LinearCmd
  • BatteryLevelCmd
  • BatteryLevelReading
  • RSSILevelCmd
  • RSSILevelReading

type MessageType

type MessageType string

MessageType identifies a message type in a Messages object. It is also the object key in the Messages object.

const (
	OKMessage                      MessageType = "Ok"
	ErrorMessage                   MessageType = "Error"
	PingMessage                    MessageType = "Ping"
	TestMessage                    MessageType = "Test"
	DeviceListMessage              MessageType = "DeviceList"
	DeviceAddedMessage             MessageType = "DeviceAdded"
	DeviceRemovedMessage           MessageType = "DeviceRemoved"
	RequestDeviceListMessage       MessageType = "RequestDeviceList"
	StopDeviceCmdMessage           MessageType = "StopDeviceCmd"
	StopAllDevicesMessage          MessageType = "StopAllDevices"
	StartScanningMessage           MessageType = "StartScanning"
	StopScanningMessage            MessageType = "StopScanning"
	ScanningFinishedMessage        MessageType = "ScanningFinished"
	RequestLogMessage              MessageType = "RequestLog"
	LogMessage                     MessageType = "Log"
	RequestServerInfoMessage       MessageType = "RequestServerInfo"
	ServerInfoMessage              MessageType = "ServerInfo"
	FleshlightLaunchFW12CmdMessage MessageType = "FleshlightLaunchFW12Cmd"
	LovenseCmdMessage              MessageType = "LovenseCmd"
	SingleMotorVibrateCmdMessage   MessageType = "SingleMotorVibrateCmd"
	KiirooCmdMessage               MessageType = "KiirooCmd"
	RawReadCmdMessage              MessageType = "RawReadCmd"
	RawWriteCmdMessage             MessageType = "RawWriteCmd"
	RawSubscribeCmdMessage         MessageType = "RawSubscribeCmd"
	RawUnsubscribeCmdMessage       MessageType = "RawUnsubscribeCmd"
	RawReadingMessage              MessageType = "RawReading"
	VorzeA10CycloneCmdMessage      MessageType = "VorzeA10CycloneCmd"
	VibrateCmdMessage              MessageType = "VibrateCmd"
	RotateCmdMessage               MessageType = "RotateCmd"
	LinearCmdMessage               MessageType = "LinearCmd"
	BatteryLevelCmdMessage         MessageType = "BatteryLevelCmd"
	BatteryLevelReadingMessage     MessageType = "BatteryLevelReading"
	RSSILevelCmdMessage            MessageType = "RSSILevelCmd"
	RSSILevelReadingMessage        MessageType = "RSSILevelReading"
)
const (
	InternalErrorMessage MessageType = "buttplug.InternalError"
)

Additional local-only event types.

type Messages

type Messages map[MessageType]Message

Messages is the large messages object that's passed around.

func CreateMessages

func CreateMessages(msgs ...Message) Messages

CreateMessages creates a Messages object from the given messages.

type NullMessageAttributes

type NullMessageAttributes struct {
}

Attributes for device message that have no attributes.

type OK

type OK struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Signifies successful processing of the message indicated by the id.

func (*OK) MessageID

func (o *OK) MessageID() ID

MessageID implements Message.

func (*OK) MessageType

func (o *OK) MessageType() MessageType

MessageType implements Message.

func (*OK) SetMessageID

func (o *OK) SetMessageID(id ID)

SetMessageID implements Message.

type Ping

type Ping struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Connection keep-alive message.

func (*Ping) MessageID

func (p *Ping) MessageID() ID

MessageID implements Message.

func (*Ping) MessageType

func (p *Ping) MessageType() MessageType

MessageType implements Message.

func (*Ping) SetMessageID

func (p *Ping) SetMessageID(id ID)

SetMessageID implements Message.

type RSSILevelCmd

type RSSILevelCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
}

Requests that a RSSI level be retreived.

func (*RSSILevelCmd) MessageID

func (r *RSSILevelCmd) MessageID() ID

MessageID implements Message.

func (*RSSILevelCmd) MessageType

func (r *RSSILevelCmd) MessageType() MessageType

MessageType implements Message.

func (*RSSILevelCmd) SetMessageID

func (r *RSSILevelCmd) SetMessageID(id ID)

SetMessageID implements Message.

type RSSILevelReading

type RSSILevelReading struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// RSSI Level
	RSSILevel float64 `json:"RSSILevel"`
}

Returns a BatteryLevel read from a device.

func (*RSSILevelReading) MessageID

func (r *RSSILevelReading) MessageID() ID

MessageID implements Message.

func (*RSSILevelReading) MessageType

func (r *RSSILevelReading) MessageType() MessageType

MessageType implements Message.

func (*RSSILevelReading) SetMessageID

func (r *RSSILevelReading) SetMessageID(id ID)

SetMessageID implements Message.

type RawMessageAttributes

type RawMessageAttributes struct {
	Endpoints *[]string `json:"Endpoints,omitempty"`
}

Attributes for raw device messages.

type RawReadCmd

type RawReadCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Endpoint (from device config file) from which the data was retrieved.
	Endpoint string `json:"Endpoint"`
	// Amount of data to read from device, 0 to exhaust whatever is in immediate
	// buffer
	Length int `json:"Length"`
	// If true, then wait until Length amount of data is available.
	WaitForData bool `json:"WaitForData"`
}

Request a raw byte array from a device. Should only be used for testing/development.

func (*RawReadCmd) MessageID

func (r *RawReadCmd) MessageID() ID

MessageID implements Message.

func (*RawReadCmd) MessageType

func (r *RawReadCmd) MessageType() MessageType

MessageType implements Message.

func (*RawReadCmd) SetMessageID

func (r *RawReadCmd) SetMessageID(id ID)

SetMessageID implements Message.

type RawReading

type RawReading struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Endpoint (from device config file) from which the data was retrieved.
	Endpoint string `json:"Endpoint"`
	// Raw byte string received from device.
	Data []int `json:"Data"`
}

Raw byte array received from a device. Should only be used for testing/development.

func (*RawReading) MessageID

func (r *RawReading) MessageID() ID

MessageID implements Message.

func (*RawReading) MessageType

func (r *RawReading) MessageType() MessageType

MessageType implements Message.

func (*RawReading) SetMessageID

func (r *RawReading) SetMessageID(id ID)

SetMessageID implements Message.

type RawSubscribeCmd

type RawSubscribeCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Endpoint (from device config file) from which the data was retrieved.
	Endpoint string `json:"Endpoint"`
}

Subscribe to an endpoint on a device to receive raw info back.

func (*RawSubscribeCmd) MessageID

func (r *RawSubscribeCmd) MessageID() ID

MessageID implements Message.

func (*RawSubscribeCmd) MessageType

func (r *RawSubscribeCmd) MessageType() MessageType

MessageType implements Message.

func (*RawSubscribeCmd) SetMessageID

func (r *RawSubscribeCmd) SetMessageID(id ID)

SetMessageID implements Message.

type RawUnsubscribeCmd

type RawUnsubscribeCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Endpoint (from device config file) from which the data was retrieved.
	Endpoint string `json:"Endpoint"`
}

Unsubscribe to an endpoint on a device.

func (*RawUnsubscribeCmd) MessageID

func (r *RawUnsubscribeCmd) MessageID() ID

MessageID implements Message.

func (*RawUnsubscribeCmd) MessageType

func (r *RawUnsubscribeCmd) MessageType() MessageType

MessageType implements Message.

func (*RawUnsubscribeCmd) SetMessageID

func (r *RawUnsubscribeCmd) SetMessageID(id ID)

SetMessageID implements Message.

type RawWriteCmd

type RawWriteCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Endpoint (from device config file) to send command to.
	Endpoint string `json:"Endpoint"`
	// Raw byte string to send to device.
	Data []int `json:"Data"`
	// If true, BLE writes will use WriteWithResponse. Value ignored for all
	// other types.
	WriteWithResponse bool `json:"WriteWithResponse"`
}

Sends a raw byte array to a device. Should only be used for testing/development.

func (*RawWriteCmd) MessageID

func (r *RawWriteCmd) MessageID() ID

MessageID implements Message.

func (*RawWriteCmd) MessageType

func (r *RawWriteCmd) MessageType() MessageType

MessageType implements Message.

func (*RawWriteCmd) SetMessageID

func (r *RawWriteCmd) SetMessageID(id ID)

SetMessageID implements Message.

type RequestDeviceList

type RequestDeviceList struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Request for the server to send a list of devices to the client.

func (*RequestDeviceList) MessageID

func (r *RequestDeviceList) MessageID() ID

MessageID implements Message.

func (*RequestDeviceList) MessageType

func (r *RequestDeviceList) MessageType() MessageType

MessageType implements Message.

func (*RequestDeviceList) SetMessageID

func (r *RequestDeviceList) SetMessageID(id ID)

SetMessageID implements Message.

type RequestLog

type RequestLog struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Maximum level of log message to receive.
	LogLevel string `json:"LogLevel"`
}

Request for server to stream log messages of a certain level to client.

func (*RequestLog) MessageID

func (r *RequestLog) MessageID() ID

MessageID implements Message.

func (*RequestLog) MessageType

func (r *RequestLog) MessageType() MessageType

MessageType implements Message.

func (*RequestLog) SetMessageID

func (r *RequestLog) SetMessageID(id ID)

SetMessageID implements Message.

type RequestServerInfo

type RequestServerInfo struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Name of the client software.
	ClientName string `json:"ClientName"`
	// Message template version of the client software.
	MessageVersion *int `json:"MessageVersion,omitempty"`
}

Request server version, and relay client name.

func NewRequestServerInfo

func NewRequestServerInfo() *RequestServerInfo

NewRequestServerInfo creates a new RequestServerInfo with the current client information.

func (*RequestServerInfo) MessageID

func (r *RequestServerInfo) MessageID() ID

MessageID implements Message.

func (*RequestServerInfo) MessageType

func (r *RequestServerInfo) MessageType() MessageType

MessageType implements Message.

func (*RequestServerInfo) SetMessageID

func (r *RequestServerInfo) SetMessageID(id ID)

SetMessageID implements Message.

type RotateCmd

type RotateCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Device rotation speeds (floating point, 0 < x < 1) keyed on rotator
	// number, stepping will be device specific.
	Rotations []struct {
		// Rotator number.
		Index int `json:"Index"`
		// Rotation speed (floating point, 0 < x < 1), stepping will be device
		// specific.
		Speed float64 `json:"Speed"`
		// Rotation direction (boolean). Not all devices have a concept of actual
		// clockwise.
		Clockwise bool `json:"Clockwise"`
	} `json:"Rotations"`
}

Sends a rotate command to a device that supports rotation.

func (*RotateCmd) MessageID

func (r *RotateCmd) MessageID() ID

MessageID implements Message.

func (*RotateCmd) MessageType

func (r *RotateCmd) MessageType() MessageType

MessageType implements Message.

func (*RotateCmd) SetMessageID

func (r *RotateCmd) SetMessageID(id ID)

SetMessageID implements Message.

type ScanningFinished

type ScanningFinished struct {
	// Used for non-direct-reply messages that can only be sent from server to
	// client, using the reserved system message Id of 0.
	ID SystemID `json:"Id"`
}

Server notification to client that scanning has ended.

func (*ScanningFinished) MessageID

func (s *ScanningFinished) MessageID() ID

MessageID implements Message.

func (*ScanningFinished) MessageType

func (s *ScanningFinished) MessageType() MessageType

MessageType implements Message.

func (*ScanningFinished) SetMessageID

func (s *ScanningFinished) SetMessageID(id ID)

SetMessageID implements Message.

type ServerInfo

type ServerInfo struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Name of the server. Can be 0-length.
	ServerName string `json:"ServerName"`
	// Message template version of the server software.
	MessageVersion int `json:"MessageVersion"`
	// Major version of server.
	MajorVersion *int `json:"MajorVersion,omitempty"`
	// Minor version of server.
	MinorVersion *int `json:"MinorVersion,omitempty"`
	// Build version of server.
	BuildVersion *int `json:"BuildVersion,omitempty"`
	// Maximum time (in milliseconds) the server will wait between ping messages
	// from client before shutting down.
	MaxPingTime int `json:"MaxPingTime"`
}

Server version information, in Major.Minor.Build format.

func (*ServerInfo) MessageID

func (s *ServerInfo) MessageID() ID

MessageID implements Message.

func (*ServerInfo) MessageType

func (s *ServerInfo) MessageType() MessageType

MessageType implements Message.

func (*ServerInfo) SetMessageID

func (s *ServerInfo) SetMessageID(id ID)

SetMessageID implements Message.

type SingleMotorVibrateCmd

type SingleMotorVibrateCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Device vibration speed (floating point, 0 < x < 1), stepping will be
	// device specific.
	Speed float64 `json:"Speed"`
}

Sends a vibrate command to a device that supports vibration.

func (*SingleMotorVibrateCmd) MessageID

func (s *SingleMotorVibrateCmd) MessageID() ID

MessageID implements Message.

func (*SingleMotorVibrateCmd) MessageType

func (s *SingleMotorVibrateCmd) MessageType() MessageType

MessageType implements Message.

func (*SingleMotorVibrateCmd) SetMessageID

func (s *SingleMotorVibrateCmd) SetMessageID(id ID)

SetMessageID implements Message.

type StartScanning

type StartScanning struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Request for the server to start scanning for new devices.

func (*StartScanning) MessageID

func (s *StartScanning) MessageID() ID

MessageID implements Message.

func (*StartScanning) MessageType

func (s *StartScanning) MessageType() MessageType

MessageType implements Message.

func (*StartScanning) SetMessageID

func (s *StartScanning) SetMessageID(id ID)

SetMessageID implements Message.

type StepCount

type StepCount []int

Specifies granularity of each feature on the device.

type StopAllDevices

type StopAllDevices struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Stops all actions currently being taken by all connected devices.

func (*StopAllDevices) MessageID

func (s *StopAllDevices) MessageID() ID

MessageID implements Message.

func (*StopAllDevices) MessageType

func (s *StopAllDevices) MessageType() MessageType

MessageType implements Message.

func (*StopAllDevices) SetMessageID

func (s *StopAllDevices) SetMessageID(id ID)

SetMessageID implements Message.

type StopDeviceCmd

type StopDeviceCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
}

Stops the all actions currently being taken by a device.

func (*StopDeviceCmd) MessageID

func (s *StopDeviceCmd) MessageID() ID

MessageID implements Message.

func (*StopDeviceCmd) MessageType

func (s *StopDeviceCmd) MessageType() MessageType

MessageType implements Message.

func (*StopDeviceCmd) SetMessageID

func (s *StopDeviceCmd) SetMessageID(id ID)

SetMessageID implements Message.

type StopScanning

type StopScanning struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
}

Request for the server to stop scanning for new devices.

func (*StopScanning) MessageID

func (s *StopScanning) MessageID() ID

MessageID implements Message.

func (*StopScanning) MessageType

func (s *StopScanning) MessageType() MessageType

MessageType implements Message.

func (*StopScanning) SetMessageID

func (s *StopScanning) SetMessageID(id ID)

SetMessageID implements Message.

type SystemID

type SystemID int // [0, 0]

Used for non-direct-reply messages that can only be sent from server to client, using the reserved system message Id of 0.

type SystemIDMessage

type SystemIDMessage struct {
	// Used for non-direct-reply messages that can only be sent from server to
	// client, using the reserved system message Id of 0.
	ID SystemID `json:"Id"`
}

Message sent by the server that is not in direct reply to a message send from the client, and always uses system Id.

type Test

type Test struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// String to be echo'd back from server. Setting this to 'Error' will cause
	// an error to be thrown.
	TestString string `json:"TestString"`
}

Used for connection/application testing. Causes server to echo back the string sent. Sending string of 'Error' will result in a server error.

func (*Test) MessageID

func (t *Test) MessageID() ID

MessageID implements Message.

func (*Test) MessageType

func (t *Test) MessageType() MessageType

MessageType implements Message.

func (*Test) SetMessageID

func (t *Test) SetMessageID(id ID)

SetMessageID implements Message.

type UnknownEventError

type UnknownEventError struct {
	Type MessageType
	Data json.RawMessage
}

UnknownEventError is an error that's sent on an unknown event.

func (*UnknownEventError) Error

func (err *UnknownEventError) Error() string

Error returns the formatted error; it implements error.

type VersionMismatchError

type VersionMismatchError struct {
	Server int
}

VersionMismatchError is returned if the server's version does not match the client's.

func (VersionMismatchError) Error

func (err VersionMismatchError) Error() string

Error implements error.

type VibrateCmd

type VibrateCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Device vibration speeds (floating point, 0 < x < 1) keyed on vibrator
	// number, stepping will be device specific.
	Speeds []struct {
		// Vibrator number.
		Index int `json:"Index"`
		// Vibration speed (floating point, 0 < x < 1), stepping will be device
		// specific.
		Speed float64 `json:"Speed"`
	} `json:"Speeds"`
}

Sends a vibrate command to a device that supports vibration.

func (*VibrateCmd) MessageID

func (v *VibrateCmd) MessageID() ID

MessageID implements Message.

func (*VibrateCmd) MessageType

func (v *VibrateCmd) MessageType() MessageType

MessageType implements Message.

func (*VibrateCmd) SetMessageID

func (v *VibrateCmd) SetMessageID(id ID)

SetMessageID implements Message.

type VorzeA10CycloneCmd

type VorzeA10CycloneCmd struct {
	// User-set id for the message. 0 denotes system message and is reserved.
	ID ID `json:"Id"`
	// Index used for referencing the device in device messages.
	DeviceIndex DeviceIndex `json:"DeviceIndex"`
	// Rotation speed command for the Cyclone.
	Speed int `json:"Speed"`
	// True for clockwise rotation (in relation to device facing user), false
	// for Counter-clockwise
	Clockwise bool `json:"Clockwise"`
}

Sends a raw byte string to a Kiiroo Onyx/Pearl device.

func (*VorzeA10CycloneCmd) MessageID

func (v *VorzeA10CycloneCmd) MessageID() ID

MessageID implements Message.

func (*VorzeA10CycloneCmd) MessageType

func (v *VorzeA10CycloneCmd) MessageType() MessageType

MessageType implements Message.

func (*VorzeA10CycloneCmd) SetMessageID

func (v *VorzeA10CycloneCmd) SetMessageID(id ID)

SetMessageID implements Message.

type Websocket

type Websocket struct {

	// DialTimeout is the maximum duration each dial.
	DialTimeout time.Duration
	// DialDelay is the delay between dials.
	DialDelay time.Duration
	// contains filtered or unexported fields
}

Websocket describes a websocket connection to the Buttplug server.

func NewWebsocket

func NewWebsocket() *Websocket

NewWebsocket creates a new Buttplug Websocket client instance.

func (*Websocket) Command

func (w *Websocket) Command(ctx context.Context, msg Message) (Message, error)

Command sends a message over the websocket and waits for a reply. If the caller calls this method after the websocket is closed, the function will block forever, since a websocket cannot be started back up. The returned message is never nil, but it may be of type InternalError or Error, which the function will unbox into the return error type.

func (*Websocket) CommandCh

func (w *Websocket) CommandCh(ctx context.Context, msg Message) <-chan Message

CommandCh is a channel variant of Command. The returned channel is never closed and will be sent into once.

func (*Websocket) LastError

func (w *Websocket) LastError() error

LastError returns the last error in the websocket. It's recommended to call this method once the Websocket channel is closed to ensure that it has gracefully exited.

func (*Websocket) Open

func (w *Websocket) Open(ctx context.Context, url string) <-chan Message

Open opens the websocket connection by continuously dialing it and ensuring its best that the connection stays alive. If the Websocket is already opened, then it'll be reconnected.

If the given context is cancelled OR if the websocket stumbles upon an unrecoverable error, then the channel is closed with the last event being of type InternalError. A more convenient way of error checking can be done by calling the LastError method.

func (*Websocket) Send

func (w *Websocket) Send(ctx context.Context, msgs ...Message)

Send sends the given messages instance over the websocket asynchronously. If the user needs a synchronous sending API, they should use the Command method.

Directories

Path Synopsis
cmd
buttplughttp Module
Package device contains abstractions to handle devices.
Package device contains abstractions to handle devices.
internal
buttplugschema
Package buttplugschema provides functions to fetch the buttplug.io JSON schema.
Package buttplugschema provides functions to fetch the buttplug.io JSON schema.
Package intiface provides a manager for the Intiface CLI.
Package intiface provides a manager for the Intiface CLI.

Jump to

Keyboard shortcuts

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