Version: v0.0.0-...-10a4253 Latest Latest

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

Go to latest
Published: Aug 30, 2019 License: MIT Imports: 6 Imported by: 0




This section is empty.


This section is empty.


func SetRoutes

func SetRoutes(engine *gin.Engine, h Handler) error

SetRoutes sets all of the appropriate routes to websocket handlers for the application


type Client

type Client struct {
	// contains filtered or unexported fields

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

func NewClient

func NewClient(dispatcher *Dispatcher, conn *websocket.Conn, channel string) *Client

NewClient creates and returns a pointer to a new client

func (*Client) Dispatcher

func (c *Client) Dispatcher() *Dispatcher

Dispatcher returns the `Dispatcher` struct

func (*Client) ReadDispatch

func (c *Client) ReadDispatch()

ReadDispatch pumps messages from the websocket connection to the dispatcher.

The application runs ReadDispatch 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) WriteDispatch

func (c *Client) WriteDispatch()

WriteDispatch pumps messages from the dispatcher to the websocket connection.

A goroutine running WriteDispatch 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 Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields

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

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new Dispatcher

func (*Dispatcher) Broadcast

func (d *Dispatcher) Broadcast() chan *Message

Broadcast returns the broadcast channel

func (*Dispatcher) Run

func (d *Dispatcher) Run()

Run starts the dispatch loop

type Handler

type Handler interface {
	WebsocketHandler(c *gin.Context)

Handler is an interface to the HTTP handler functions.

type Handlers

type Handlers struct {
	// contains filtered or unexported fields

Handlers handles websocket connections and provides an interface to dispatch events

func NewHandlers

func NewHandlers(dispatcher *Dispatcher) *Handlers

NewHandlers creates and returns a pointer to a new instance of `Handler`

func (*Handlers) WebsocketHandler

func (h *Handlers) WebsocketHandler(c *gin.Context)

WebsocketHandler handles all of the websocket connections

type Message

type Message struct {
	Channel string      // the channel name to broadcast on
	Data    interface{} // the data to broadcast

Message wraps the relevant information needed to broadcast a message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL