buttplug

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: ISC Imports: 13 Imported by: 0

README

go-buttplug

Go Reference

import "libdb.so/go-buttplug"

A Go library for the Intiface Websocket API, including Intiface Central and Intiface Engine, which wraps the buttplug.io protocol.

Example

See cmd/vibrate-em-all for a simple example program that vibrates all connected devices.

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 (
	ActuatorUnknown   = "Unknown"
	ActuatorVibrate   = "Vibrate"
	ActuatorRotate    = "Rotate"
	ActuatorOscillate = "Oscillate"
	ActuatorConstrict = "Constrict"
	ActuatorInflate   = "Inflate"
	ActuatorPosition  = "Position"
)

Actuator type constants.

View Source
const (
	SensorUnknown  = "Unknown"
	SensorBattery  = "Battery"
	SensorRSSI     = "RSSI"
	SensorButton   = "Button"
	SensorPressure = "Pressure"
)

Sensor type constants.

View Source
const DefaultDialTimeout = 10 * time.Second

DefaultDialTimeout is the maximum duration each dial.

View Source
const DefaultServerName = "go-buttplug"

DefaultServerName is the default client name sent to the Buttplug server during handshake.

View Source
const MessageVersion = 3

MessageVersion is the current Buttplug message version this library implements. See https://docs.buttplug.io/docs/spec/changelog.

Variables

View Source
var DefaultDialBackoff backoff.BackOff = &backoff.ExponentialBackOff{
	InitialInterval:     200 * time.Millisecond,
	RandomizationFactor: 0.5,
	Multiplier:          1.5,
	MaxInterval:         2 * time.Second,
}

DefaultDialBackoff is the default backoff policy for reconnecting to a Buttplug server over websocket.

Functions

This section is empty.

Types

type Websocket

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

Websocket describes a websocket connection to the Buttplug server.

func NewWebsocket

func NewWebsocket(wsAddr string, opts *WebsocketOpts) *Websocket

NewWebsocket creates a new Buttplug Websocket client instance with optionally a WebsocketOpts to configure it.

func (*Websocket) MessageChannel

func (w *Websocket) MessageChannel(ctx context.Context) (<-chan buttplugschema.Message, context.CancelFunc)

MessageChannel returns a new channel that will receive all incoming messages coming from the Buttplug server. For convenience, this channel is closed when Websocket.Start exits or when the given context is cancelled, and no messages will be sent to the channel after that.

It is safe to call this method concurrently.

Note that if this method is called after Websocket.Start, messages may be missed. Therefore, this method should only be called before starting the websocket.

func (*Websocket) Send

Send queues the given messages to be sent in the main Websocket.Start loop. An error is only returned if context is cancelled.

It is safe to call this method concurrently.

func (*Websocket) SendCommand

SendCommand sends a single Buttplug command and waits for the response. This is a convenience method around Websocket.Send and listening to the message channels.

func (*Websocket) Start

func (w *Websocket) Start(ctx context.Context) error

Start starts the websocket connection persistently and blocks until the given context is cancelled. It transparently reconnects on connection or loop failure with a backoff defined by DefaultDialBackoff.

type WebsocketOpts

type WebsocketOpts struct {
	// ServerName is the client name sent to the Buttplug server during
	// handshake. It is recommended that you change this to the actual name of
	// the application using the library. If empty, [DefaultServerName] is used.
	ServerName string
	// Logger is an optional logger for internal logging.
	// If empty, [slog.Default] is used.
	Logger *slog.Logger
	// DialTimeout is the maximum duration for each dial attempt.
	// If zero, [WebsocketDialTimeout] is used.
	DialTimeout time.Duration
	// DialBackoff is the backoff policy for reconnecting to the Buttplug
	// server over websocket. If nil, [DefaultDialBackoff] is used.
	DialBackoff backoff.BackOff
}

WebsocketOpts contains options for creating a new Buttplug Websocket instance.

type WebsocketResetMessage

type WebsocketResetMessage struct {
	buttplugschema.InternalMessage
}

WebsocketResetMessage is an empty message that is sent from the websocket loop to indicate that the connection has been reset and that internal state should be cleared.

Directories

Path Synopsis
cmd
buttplug-generate/jsonschema
Package jsonschema wraps around the dreadful santhosh-tekuri/jsonschema package.
Package jsonschema wraps around the dreadful santhosh-tekuri/jsonschema package.
vibrate-em-all command
schema
ptr
Package ptr contains helper types and functions for working with optional types as pointers.
Package ptr contains helper types and functions for working with optional types as pointers.
v0
Package schema contains the Buttplug message schema for version 0.
Package schema contains the Buttplug message schema for version 0.
v1
Package schema contains the Buttplug message schema for version 1.
Package schema contains the Buttplug message schema for version 1.
v2
Package schema contains the Buttplug message schema for version 2.
Package schema contains the Buttplug message schema for version 2.
v3
Package schema contains the Buttplug message schema for version 3.
Package schema contains the Buttplug message schema for version 3.
v4
Package schema contains the Buttplug message schema for version 4.
Package schema contains the Buttplug message schema for version 4.

Jump to

Keyboard shortcuts

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