websockets

package
v2.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2016 License: AGPL-3.0, AGPL-3.0-or-later Imports: 25 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 {

	// Client identity information
	auth.Ident
	// 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()

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

func (*Client) Listen

func (c *Client) Listen() 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 clients connected to this server instance

func (*ClientMap) Add

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

Add adds a client to the map

func (*ClientMap) ChangeSync

func (c *ClientMap) ChangeSync(cl *Client, syncID SyncID)

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) GetSync

func (c *ClientMap) GetSync(cl *Client) (bool, SyncID)

GetSync returns if the current client is synced and the thread and board it is synced to.

func (*ClientMap) Remove

func (c *ClientMap) Remove(cl *Client)

Remove removes a client from the map

type SyncID

type SyncID struct {
	OP    int64
	Board string
}

SyncID contains the board and thread the client are currently synced to. If the client is on the board page, thread = 0.

Jump to

Keyboard shortcuts

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