socket

package
v0.0.0-...-dae269f Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SignalCancel = "cancel"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// NumPara
	NumParams int

	// Scope and ScopeParam indicate the scope required by the caller.
	// TODO(twiesing): Once we actually include scopes, make them dynamic
	Scope      component.Scope
	ScopeParam string

	// Handle handles this action.
	//
	// ctx is closed once the underlying connection is closed.
	// out is an io.Writer that is automatically sent to the client.
	// params holds exactly NumParams parameters.
	Handle func(ctx context.Context, in io.Reader, out io.Writer, params ...string) error
}

Action is something that can be handled via a WebSocket connection.

type ActionMap

type ActionMap map[string]Action

ActionMap handles a set of WebSocket actions

func (ActionMap) Handle

func (am ActionMap) Handle(auth *auth.Auth, conn httpx.WebSocketConnection) (name string, err error)

Handle handles a new incoming websocket connection using the given authentication.

There are two kinds of messages:

- text messages, which are used to send input and output. - binary messages, which are json-encoded and used for control flow.

To call an action, a client should send a CallMessage struct. The server will then start handling input and output (via text messages). If the client sends a SignalMessage, the signal is propagnated to the underlying context. Finally it will send a ResultMessage once handling is complete.

A corresponding client implementation of this can be found in ..../remote/proto.ts

type CallMessage

type CallMessage struct {
	Call   string   `json:"call"`
	Params []string `json:"params,omitempty"`
}

CallMessage is sent by the client to the server to invoke a remote procedure

type ResultMessage

type ResultMessage struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
}

ResultMessage is sent by the server to the client to report the success of a remote procedure

type Signal

type Signal string

type SignalMessage

type SignalMessage struct {
	Signal Signal `json:"signal"`
}

CancelMessage is sent from the client to the server to stop the current procedure

type Sockets

type Sockets struct {
	component.Base

	Dependencies struct {
		Provision *provision.Provision
		Instances *instances.Instances
		Exporter  *exporter.Exporter
		Purger    *purger.Purger
		Auth      *auth.Auth
	}
	// contains filtered or unexported fields
}

func (*Sockets) Actions

func (sockets *Sockets) Actions() ActionMap

func (*Sockets) Generic

func (sockets *Sockets) Generic(scope component.Scope, scopeParam string, numParams int, handler func(ctx context.Context, socket *Sockets, in io.Reader, out io.Writer, params ...string) error) Action

Generic returns a new action that calls handler with the provided number of parameters

func (*Sockets) HandleRoute

func (sockets *Sockets) HandleRoute(ctx context.Context, path string) (http.Handler, error)

func (*Sockets) Instance

func (sockets *Sockets) Instance(scope component.Scope, scopeParam string, numParams int, handler func(ctx context.Context, sockets *Sockets, instance *wisski.WissKI, in io.Reader, out io.Writer, params ...string) error) Action

Insstance returns a new action that calls handler with a specific WissKI instance

func (*Sockets) Routes

func (socket *Sockets) Routes() component.Routes

func (*Sockets) Serve

func (socket *Sockets) Serve(conn httpx.WebSocketConnection)

Serve handles a connection to the websocket api

type WriteFunc

type WriteFunc func([]byte) (int, error)

WriteFunc implements io.Writer using a function.

func (WriteFunc) Write

func (wf WriteFunc) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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