fanout

package
v0.17.15 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventTypeWebP is used to signal what type of message we are sending over
	// the socket.
	EventTypeWebP = "webp"

	// EventTypeSchema is used to signal that the schema for a given app has
	// changed.
	EventTypeSchema = "schema"

	// EventTypeErr is used to signal there was an error encountered rendering
	// the WebP image.
	EventTypeErr = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a structure for incomming websocket requests so they can be tracked by a Fanout.

func (*Client) Quit

func (c *Client) Quit()

Quit will close the connection and unregiseter it from the Fanout.

func (*Client) Send

func (c *Client) Send(event WebsocketEvent)

Send is used to send a webp message to the client.

type Fanout

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

Fanout provides a structure for broadcasting messages to registered clients when an update comes in on a go channel.

func NewFanout

func NewFanout() *Fanout

NewFanout creates a new Fanout structure and runs the main loop.

func (*Fanout) Broadcast

func (fo *Fanout) Broadcast(event WebsocketEvent)

Broadcast sends a message to all registered clients.

func (*Fanout) NewClient

func (f *Fanout) NewClient(conn *websocket.Conn) *Client

NewClient instantiates a client with a websocket connection. It spwans off go routines to send data to the client and send pings to ensure the client is still alive. We're passing a Fanout here so the client can unregister itself on error.

func (*Fanout) Quit

func (fo *Fanout) Quit()

Quit stops broadcasting messages over the channel.

func (*Fanout) RegisterClient

func (fo *Fanout) RegisterClient(c *Client)

RegisterClient registers a client to include in broadcasts.

func (*Fanout) UnregisterClient

func (fo *Fanout) UnregisterClient(c *Client)

UnregisterClient removes it from the broadcast.

type WebsocketEvent

type WebsocketEvent struct {
	// Message is the contents of the message. This is a webp, base64 encoded.
	Message string `json:"message"`

	// Type is the type of message we are sending over the socket.
	Type string `json:"type"`
}

WebsocketEvent is a structure used to send messages over the socket.

Jump to

Keyboard shortcuts

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