websockets

package
v2.0.0-alpha+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package websockets manages active websocket connections and messages received from and sent to them.

Index

Constants

This section is empty.

Variables

View Source
var Clients = ClientMap{
	// contains filtered or unexported fields
}

Clients stores all synchronised websocket clients in a theread-safe map

Functions

func CheckOrigin

func CheckOrigin(req *http.Request) bool

CheckOrigin asserts the client matches the origin specified by the server or has none.

func Handler

func Handler(res http.ResponseWriter, req *http.Request)

Handler is an http.HandleFunc that responds to new websocket connection requests.

Types

type Client

type Client struct {
	ID string
	util.AtomicCloser

	// Send thread-safely sends a message to the websocket client
	Send chan []byte

	// AllocateImage receives Image structs from the thumbnailer for allocation
	// by the client
	AllocateImage chan types.Image
	// contains filtered or unexported fields
}

Client stores and manages a websocket-connected remote client and its interaction with the server and database

func (*Client) Close

func (c *Client) Close(err error)

Close closes a websocket connection with the provided status code and optional reason

func (*Client) Listen

func (c *Client) Listen() (err error)

Listen listens for incoming messages on the channels and processes them

type ClientMap

type ClientMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ClientMap is a thread-safe store for all connected clients. You also perform multiclient message dispatches etc., by calling its methods.

func (*ClientMap) Add

func (c *ClientMap) Add(cl *Client, syncID string)

Add adds a client to the map

func (*ClientMap) ChangeSync

func (c *ClientMap) ChangeSync(clientID, syncID string)

ChangeSync changes the thread or board ID the client is synchronised to

func (*ClientMap) Clear

func (c *ClientMap) Clear()

Clear removes all clients from the map

func (*ClientMap) CountByIP

func (c *ClientMap) CountByIP() int

CountByIP returns the number of unique IPs synchronised with the server

func (*ClientMap) Get

func (c *ClientMap) Get(id string) (*Client, error)

Get returns a *Client of the passed ID or an error, if there is none

func (*ClientMap) Has

func (c *ClientMap) Has(id string) bool

Has checks if a client exists already by id

func (*ClientMap) Remove

func (c *ClientMap) Remove(id string)

Remove removes a client from the map

func (*ClientMap) SendAll

func (c *ClientMap) SendAll(msg []byte)

SendAll sends a message to all synchronised websocket clients

Jump to

Keyboard shortcuts

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