websocket

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)

ServeWs handles websocket requests from the peer.

Types

type Client

type Client struct {

	// Unique client ID
	ID string `json:"id"`
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub

type Hub

type Hub struct {

	// Shutdown channel to stop the Hub
	Shutdown chan struct{}

	// Client subscriptions
	Subscriptions []*Subscription

	// Register channel for requests from the clients.
	Register chan *Client

	// Unregister channel for requests from clients.
	Unregister chan *Client
	// contains filtered or unexported fields
}

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub(db *database.Database, shutdown chan struct{}) (*Hub, error)

func (*Hub) ProcessMessage

func (h *Hub) ProcessMessage(client *Client, messageType int, payload []byte) *Hub

func (*Hub) Run

func (h *Hub) Run(serviceWG *sync.WaitGroup)

func (*Hub) RunSubscriptionService

func (h *Hub) RunSubscriptionService(sub *Subscription, exchangeName, product string, client *Client)

func (*Hub) Send

func (h *Hub) Send(client *Client, message []byte)

func (*Hub) Subscribe

func (h *Hub) Subscribe(client *Client, exchange string, product string)

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(client *Client)

func (*Hub) UnsubscribeAll

func (h *Hub) UnsubscribeAll()

type Message

type Message struct {
	Action     string `json:"action"`
	ExchangeID string `json:"exchange_id"`
	Message    string `json:"message"`
}

Message is the type for a valid message from a client

type MessageResponse

type MessageResponse struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type Subscription

type Subscription struct {
	ExchangeClient qsx.IExchange
	Client         *Client
	Shutdown       chan struct{}
}

Subscription type holds a single client <-> exchange connection

Jump to

Keyboard shortcuts

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