ws

package
v0.0.0-...-fcbdc9d Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 23 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 {

	// Buffered channel of outbound messages.
	Send chan []byte

	SendEvents chan []*types.Event

	Language string

	PluginChan chan []*types.Event

	// WaitGroup which keeps track of running read/write loops and write access to Send. If the WaitGroup is done,
	// it is safe to close all channels (all loops are done and there are no more write operations on the channels)
	sync.WaitGroup
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub.

func NewClient

func NewClient(hub *Hub, conn *websocket.Conn, user *types.User, language string, doneChan chan struct{}) *Client

func (*Client) EvaluateFilterEvent

func (c *Client) EvaluateFilterEvent(event *types.Event) bool

func (*Client) PluginLoop

func (c *Client) PluginLoop()

A per-client plugin loop. Reads the PluginChan and calls per-client plugins. Will be exited when the PluginChan is closed.

func (*Client) ReadLoop

func (c *Client) ReadLoop()

ReadLoop pumps messages from the websocket connection to the hub.

The application runs ReadLoop in a per-connection goroutine. The application ensures that there is at most one reader on a connection by executing all reads from this goroutine.

func (*Client) RunFilterEvent

func (c *Client) RunFilterEvent(event *types.Event, prog *vm.Program) bool

func (*Client) SendHistory

func (c *Client) SendHistory(events []*types.Event, wg *sync.WaitGroup)

func (*Client) WriteLoop

func (c *Client) WriteLoop()

WriteLoop pumps messages from the hub to the websocket connection.

A goroutine running WriteLoop is started for each connection. The application ensures that there is at most one writer to a connection by executing all writes from this goroutine.

type Hub

type Hub struct {
	// there is one hub per room
	*types.Room

	// Broadcast events to all clients.
	BroadcastEvents chan []*types.Event

	// Register a new client to the hub.
	Register chan *Client

	// Unregister a client from the hub.
	Unregister chan *Client

	// keep the chat history in a ring buffer
	EventHistory chan []*types.Event

	// global configuration
	Cfg *config.Config

	// persistence
	Persister persistence.Persister

	// mutex for manipulating the clients
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHub

func NewHub(room *types.Room, cfg *config.Config, persister persistence.Persister, pluginMap map[string]plugins.PluginSpec) *Hub

func (*Hub) EvaluatePluginFilterEvent

func (h *Hub) EvaluatePluginFilterEvent(event *types.Event, pluginFilter string) bool

func (*Hub) GetHistory

func (h *Hub) GetHistory() []*types.Event

func (*Hub) GetInfo

func (h *Hub) GetInfo() *types.Event

func (*Hub) NoClients

func (h *Hub) NoClients() int

NoClients returns the number of clients registered

func (*Hub) Run

func (h *Hub) Run()

Run is the main hub event loop handling register, unregister and broadcast events.

func (*Hub) RunPluginFilterEvent

func (h *Hub) RunPluginFilterEvent(event *types.Event, prog *vm.Program) bool

func (*Hub) SendInfo

func (h *Hub) SendInfo(event *types.Event)

SendInfo broadcasts hub statistics to all clients.

Jump to

Keyboard shortcuts

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