intiface

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package intiface provides a manager for the Intiface CLI.

Example
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

ws := NewWebsocket(0, intifaceCLI)
ch := ws.Open(ctx)

for ev := range ch {
	switch ev := ev.(type) {
	case *buttplug.InternalError:
		log.Println("error:", ev.Err)
	case *buttplug.ServerInfo:
		log.Printf("server %q, version %d.%d", ev.ServerName, ev.MajorVersion, ev.MinorVersion)

		// Try pinging synchronously.
		v, err := ws.Command(ctx, &buttplug.RequestDeviceList{})
		if err != nil {
			log.Fatalln("cannot request device list:", err)
		}

		devices := v.(*buttplug.DeviceList)
		log.Println("devices:", devices)

		// Exit.
		cancel()
	}
}

if err := ws.LastError(); err != nil {
	log.Fatalln("error:", err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var EnableConsole = false

EnableConsole, if true, will make the Intiface CLI print to stderr.

Functions

func StartCLI

func StartCLI(ctx context.Context, port int, h CLIHandler, arg0 string, argv ...string)

StartCLI starts managing the Intiface CLI. The given callback will be called everytime the CLI starts. The caller should call the Address method inside the callback. It should return false if it cannot connect to that address.

Types

type CLIHandler

type CLIHandler interface {
	// OnConnect is called everytime the IntifaceCLI is started. The caller
	// should use this method to start the connection and optionally block until
	// the connection dies.
	OnConnect(address string) bool
	// Log logs the given error.
	Log(err error)
	// Close closes the handler.
	Close()
}

CLIHandler describes the handler that the Intiface CLI manager accepts.

type Websocket

type Websocket struct {
	*buttplug.Websocket
	// contains filtered or unexported fields
}

Websocket wraps around a Buttplug Websocket to simultaneously manage the CLI in the background.

func NewWebsocket

func NewWebsocket(port int, arg0 string, argv ...string) *Websocket

NewWebsocket creates a new websocket instance. If port is 0, then the default port is 20000.

func (*Websocket) LastError

func (w *Websocket) LastError() error

LastError returns the last error.

func (*Websocket) Open

func (w *Websocket) Open(ctx context.Context) <-chan buttplug.Message

Open starts the CLI. It does nothing if called more than once.

Jump to

Keyboard shortcuts

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