ws

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client[State any] struct {
	// contains filtered or unexported fields
}

func (*Client[State]) Request

func (this *Client[State]) Request(c ctx.C, req Op[State], fn func(ctx.C, Op[State]) error) (*Request[State], error)

send the request to the server on a new channel, and use the given callback function for any reply returns an object which can then be closed

type Conn

type Conn[State any] struct {
	State State
	// contains filtered or unexported fields
}

func (*Conn[State]) Close

func (this *Conn[State]) Close(c ctx.C, reason string) error

func (*Conn[State]) OnClose

func (this *Conn[State]) OnClose(c ctx.C, f func())

func (*Conn[State]) Send

func (this *Conn[State]) Send(c ctx.C, obj any) error

type Frame

type Frame struct {
	Path     string  `json:"path,omitempty"`
	Channel  string  `json:"channel,omitempty"`
	Data     enc.Map `json:"data,omitempty"`
	Error    string  `json:"error,omitempty"`
	Tracking string  `json:"tracking-id,omitempty"`
}

The frame used internally to route the custom data using Path anc Channel

type Handler

type Handler[State any] struct {
	// optional callback fired on connection.
	OnConnect func(c ctx.C, conn *Conn[State])

	// fired when a shutdown start, if empty it will send `"shutdown"` to the client
	OnShutdown func(c ctx.C, conn *Conn[State])
	// contains filtered or unexported fields
}

Handler is used to define a websocket. It tells on which path to mount it, what to do on connect and which object should be expected to be processed

func New

func New[State any](c ctx.C, objs ...Op[State]) (*Handler[State], error)

Build a new Websocket handler, which support the given operations. Note: the given Op objects might not have an `api:"url"` field, in which case the Object name will be used

func (Handler[State]) NewClient

func (h Handler[State]) NewClient(c ctx.C, send func(ctx.C, enc.Node) error, fallback func(ctx.C, enc.Node) error) *Client[State]

create a client for this websocket, you must provide a way to send data to the server, and the fallback for any messages which are not a reply to our requests

func (*Handler[State]) ServeHTTP

func (this *Handler[State]) ServeHTTP(w gohttp.ResponseWriter, r *gohttp.Request)

func (*Handler[State]) TestClient

func (this *Handler[State]) TestClient(c ctx.C) *TestClient[State]

creates a TestClient which can be used to locally test a client against a websocket implementation the websocket will run on its own separate thread

type Op

type Op[State any] interface {
	Do(ctx.C, State) error
}

A request sent from a client to the websocket

type Request

type Request[State any] struct {
	// contains filtered or unexported fields
}

func (Request[State]) Close

func (this Request[State]) Close() error

type TestClient

type TestClient[State any] struct {
	*Client[State]

	Conn *Conn[State]
	// contains filtered or unexported fields
}

func (*TestClient[State]) Close

func (this *TestClient[State]) Close() error

func (*TestClient[State]) Read

func (this *TestClient[State]) Read(c ctx.C) (enc.Node, error)

func (*TestClient[State]) Write

func (this *TestClient[State]) Write(c ctx.C, n enc.Node) error

Jump to

Keyboard shortcuts

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