hub

package
v0.0.0-...-0f02880 Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Websocket = Hub{
	Broadcast:   make(chan []byte),
	Register:    make(chan *Connection),
	Unregister:  make(chan *Connection),
	Connections: make(map[*Connection]bool),
}

Websocket global

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// WS connection.
	WS *websocket.Conn

	// Send buffered channel of outbound messages.
	Send chan []byte
}

Connection is an middleman between the websocket connection and the hub.

func (*Connection) ReadPump

func (c *Connection) ReadPump()

ReadPump pumps messages from the websocket hub.Connection to the hub.

func (*Connection) WritePump

func (c *Connection) WritePump()

WritePump pumps messages from the hub to the websocket hub.Connection.

type Hub

type Hub struct {
	// Connections registered connections.
	Connections map[*Connection]bool

	// Broadcast inbound messages from the connections.
	Broadcast chan []byte

	// Register requests from the connections.
	Register chan *Connection

	// Unregister requests from connections.
	Unregister chan *Connection
}

Hub maintains the set of active connections and broadcasts messages to the connections.

func (*Hub) Run

func (h *Hub) Run()

Run websocket loop

type Message

type Message struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

Message for websocket transport

func (*Message) JSON

func (n *Message) JSON() []byte

JSON version fo a message

Jump to

Keyboard shortcuts

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