ws

package
v0.0.0-...-3cdc2b7 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 9 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 struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client per connection (each device should have at most 1 connection)

func NewClient

func NewClient(cfg *ClientCfg) *Client

func (*Client) AddConsumer

func (c *Client) AddConsumer(ctx context.Context, topic string, consumer *nsq.Consumer) error

func (*Client) ClearConsumers

func (c *Client) ClearConsumers()

func (*Client) Close

func (c *Client) Close(KeepAlive bool)

func (*Client) ReadPump

func (c *Client) ReadPump()

user send msg from frontend to backend

func (*Client) Send

func (c *Client) Send() chan Message

func (*Client) Session

func (c *Client) Session() *model.Session

func (*Client) Start

func (c *Client) Start() error

func (*Client) StartWithContext

func (c *Client) StartWithContext(ctx context.Context) error

func (*Client) StopConsumers

func (c *Client) StopConsumers(topic string) int

func (*Client) WritePump

func (c *Client) WritePump()

user receive msg from backend to frontend

type ClientCfg

type ClientCfg struct {
	Logger *log.Logger
	Conn   *websocket.Conn
	// Producer  *nsq.Producer
	Consumers map[string][]*nsq.Consumer
	Session   *model.Session
	User      *model.User
	// IP        string
	Send chan Message
}

type Data

type Data struct {
	Topic   string `json:"topic"`
	Content string `json:"content"`
}

type Hub

type Hub struct {
	OnComplete func()
	// contains filtered or unexported fields
}

func GetHub

func GetHub() *Hub

func (*Hub) Client

func (h *Hub) Client(uid uint, ip string) *Client

func (*Hub) Clients

func (h *Hub) Clients(uid uint) map[string]*Client

func (*Hub) Close

func (h *Hub) Close()

func (*Hub) Run

func (h *Hub) Run()

type Message

type Message interface {
	Body() []byte
	OnError(err error)
	OnSuccess()
}

Jump to

Keyboard shortcuts

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