websocket

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodSubscribe   = "subscribe"
	MethodUnsubscribe = "unsubscribe"
)

methods

View Source
const (
	ChannelHead   = "head"
	ChannelBlocks = "blocks"
)

channels

Variables

View Source
var (
	ErrUnknownMethod     = errors.New("unknown method")
	ErrUnknownChannel    = errors.New("unknown channel")
	ErrUnavailableFilter = errors.New("unknown filter value")
)

Functions

This section is empty.

Types

type BlockFilter added in v1.4.0

type BlockFilter struct{}

func (BlockFilter) Filter added in v1.4.0

func (f BlockFilter) Filter(c client, msg Notification[*responses.Block]) bool

type Channel

type Channel[I any, M INotification] struct {
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel[I any, M INotification](processor processor[I, M], filters Filterable[M]) *Channel[I, M]

func (*Channel[I, M]) AddClient

func (channel *Channel[I, M]) AddClient(c client)

func (*Channel[I, M]) RemoveClient

func (channel *Channel[I, M]) RemoveClient(id uint64)

type Client

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

func (*Client) ApplyFilters

func (c *Client) ApplyFilters(msg Subscribe) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) DetachFilters

func (c *Client) DetachFilters(msg Unsubscribe) error

func (*Client) Filters

func (c *Client) Filters() *Filters

func (*Client) Id

func (c *Client) Id() uint64

func (*Client) Notify

func (c *Client) Notify(msg any)

func (*Client) ReadMessages

func (c *Client) ReadMessages(ctx context.Context, ws *websocket.Conn, sub *Client, log echo.Logger)

func (*Client) WriteMessages

func (c *Client) WriteMessages(ctx context.Context, ws *websocket.Conn, log echo.Logger)

type Filterable

type Filterable[M INotification] interface {
	Filter(c client, msg Notification[M]) bool
}

type Filters

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

type HeadFilter

type HeadFilter struct{}

func (HeadFilter) Filter

func (f HeadFilter) Filter(c client, msg Notification[*responses.State]) bool

type INotification added in v1.4.0

type INotification interface {
	*responses.Block | *responses.State
}

type Manager

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

func NewManager

func NewManager(observer *bus.Observer) *Manager

func (*Manager) AddClientToChannel

func (manager *Manager) AddClientToChannel(channel string, client *Client)

func (*Manager) Close

func (manager *Manager) Close() error

func (*Manager) Handle

func (manager *Manager) Handle(c echo.Context) error

Handle godoc

@Summary				Websocket API
@Description.markdown	websocket
@Tags					websocket
@ID						websocket
@Produce				json
@Router					/v1/ws [get]

func (*Manager) RemoveClientFromChannel

func (manager *Manager) RemoveClientFromChannel(channel string, client *Client)

func (*Manager) Start

func (manager *Manager) Start(ctx context.Context)

type Message

type Message struct {
	Method string          `json:"method" validate:"required,oneof=subscribe,unsubscribe"`
	Body   json.RawMessage `json:"body"   validate:"required"`
}

type Notification added in v1.4.0

type Notification[T INotification] struct {
	Channel string `json:"channel"`
	Body    T      `json:"body"`
}

func NewBlockNotification added in v1.4.0

func NewBlockNotification(block responses.Block) Notification[*responses.Block]

func NewStateNotification added in v1.4.0

func NewStateNotification(state responses.State) Notification[*responses.State]

type Subscribe

type Subscribe struct {
	Channel string          `json:"channel" validate:"required,oneof=head tx"`
	Filters json.RawMessage `json:"filters" validate:"required"`
}

type TransactionFilters

type TransactionFilters struct {
	Status   []string `json:"status,omitempty"`
	Messages []string `json:"msg_type,omitempty"`
}

type Unsubscribe

type Unsubscribe struct {
	Channel string `json:"channel" validate:"required,oneof=head tx"`
}

Jump to

Keyboard shortcuts

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