hub

package module
v0.0.0-...-3374993 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2016 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Websocket hub for golang

GoDoc

What? - ready to use websocket server with user subscription for private or broadcast messages. It is based on gorilla websockets package.

Why? - I find it a common use case for needing such behavior in day to day applications. Decided to opensource, maybe someone will find it useful.

See the example application built with angular to show realtime behavior.

cd example && make

Visit localhost:8000 to see it in action. Open a few tabs and try to send some messages.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Time allowed to write a message to the peer.
	WriteWait = 10 * time.Second
	// Time allowed to read the next pong message from the peer.
	PongWait = 60 * time.Second
	// Send pings to peer with this period. Must be less than pongWait.
	PingPeriod = (PongWait * 9) / 10
	// Maximum message size allowed from peer.
	MaxMessageSize int64 = 64 * 1024
)
View Source
var (
	ReadBufferSize  int = 1024
	WriteBufferSize int = 1024
)
View Source
var LogLevel string = "DEBUG"

Functions

This section is empty.

Types

type Hub

type Hub struct {
	sync.Mutex // protects connections

	Broadcast chan *Message     // fan out message to all connections
	Mailbox   chan *MailMessage // fan out message to subscriber

	SubscriptionTokenizer Tokenizer // for user subscription token validation
	// contains filtered or unexported fields
}

func New

func New(logOutput io.Writer, origins ...string) *Hub

func (*Hub) Connections

func (h *Hub) Connections() int

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) ServeHTTP

func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MailMessage

type MailMessage struct {
	Message  *Message
	Username string
}

type Message

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

type Tokenizer

type Tokenizer interface {
	Tokenize(username string) string
}

func HmacSha256Tokenizer

func HmacSha256Tokenizer(secret string) Tokenizer

type TokenizerFunc

type TokenizerFunc func(username string) string

func (TokenizerFunc) Tokenize

func (tf TokenizerFunc) Tokenize(username string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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