hub

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

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 7 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 interface {
	// ID returns a client id
	ID() uint64

	// OnClose sets a close handler
	OnClose(h func())

	// OnSubscribe sets a subscribing handler
	OnSubscribe(h func(params []string))

	// OnSubscribe sets a unsubscribing handler
	OnUnsubscribe(h func(params []string))

	// Send sends a message to the client
	Send(msg []byte)
}

Client represents a contract for websocket client

type Hub

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

Hub maintains a set of active clients

func New

func New(workerPoolSize int) (*Hub, error)

New creates a new hub

func (*Hub) Close

func (h *Hub) Close()

Close closes a hub (not thread safe)

func (*Hub) Register

func (h *Hub) Register(c Client)

Register registers a client to the hub

func (*Hub) Run

func (h *Hub) Run()

Run runs worker to manage clients

func (*Hub) SendEvent

func (h *Hub) SendEvent(e *event.Event)

SendEvent sends an event to clients

func (*Hub) Subscribe

func (h *Hub) Subscribe(e SubscribeEvent)

Subscribe handle subscribing

func (*Hub) UnRegister

func (h *Hub) UnRegister(c Client)

UnRegister unregisters a client from the hub

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(e UnsubscribeEvent)

Unsubscribe handle unsubscribing

type SubscribeEvent

type SubscribeEvent struct {
	ClientID uint64
	Types    []string
}

SubscribeEvent is a subscription detail

type UnsubscribeEvent

type UnsubscribeEvent struct {
	ClientID uint64
	Types    []string
}

UnsubscribeEvent is a unsubscription detail

Jump to

Keyboard shortcuts

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