events

package
v0.0.0-...-5c7d83b Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2014 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventConnections

func NewEventConnections() *eventConnections

NewEventConnections creates a new eventConections to track a set of clients.

func NewHub

func NewHub(c EventConnections) *eventHub

NewHub creates a new hub instance. It doesn't start it.

Types

type Client

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

Client implements a persistent Websocket connection

func NewClient

func NewClient(ws *websocket.Conn, hub Hub) *Client

NewClient creates a new persistent websocket client

func (*Client) Close

func (c *Client) Close()

Close will tell the client to exit and clean up the connection.

func (*Client) Listen

func (c *Client) Listen()

Listen starts up a listener on the websocket, and a separate go routine for writing to the websocket.

func (*Client) Send

func (c *Client) Send(msg Message) error

Send will queue up a message to be sent on the websocket.

type EventConnections

type EventConnections interface {
	Register(*Client)
	Unregister(*Client)
	Broadcast(Message)
}

EventConnections tracks a set of client connections and can be asked to broadcast a message to them.

type Hub

type Hub interface {
	Register(*Client)
	Unregister(*Client)
	Broadcast(Message)
	Start()
}

Hub handles multiple connections, tracking and broadcasting to them.

type Message

type Message struct {
	Event string      `json:"event"`
	Data  schema.User `json:"data"`
}

Message is an event over the websocket. Right only one type of data is sent back.

type Server

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

Server implements a hub for handling multiple websocket connections.

func NewServer

func NewServer(hub Hub) *Server

NewServer creates a new server.

func (*Server) OnConnection

func (s *Server) OnConnection(ws *websocket.Conn)

OnConnection is called when a new websocket connection is made. It creates a persistent client connection and registers that connection with the hub. It it meant to be called by the websocket.Handler method.

Jump to

Keyboard shortcuts

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