websockets

package
v2.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2016 License: AGPL-3.0, AGPL-3.0-or-later Imports: 24 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 EncodeMessage

func EncodeMessage(typ MessageType, msg interface{}) ([]byte, error)

EncodeMessage encodes a message for sending through websockets or writing to the replication log.

func Handler

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

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

func Listen

func Listen() error

Listen initializes and starts listening for post updates from RethinkDB

func UpdatePost

func UpdatePost(id int64, key string, val interface{}, msg []byte) error

UpdatePost post updates a single field of an existing post with the appropriate replication log update and timestamp modification.

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(err error)

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

func (*Client) Send

func (c *Client) Send(msg []byte)

Send a message to the client. Can be used concurrently.

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

type MessageType

type MessageType uint8

MessageType is the identifier code for websocket message types

const (
	MessageInvalid MessageType = iota
	MessageInsertThread
	MessageInsertPost
	MessageAppend
	MessageBackspace
	MessageSplice
	MessageClosePost
	MessageLink
	MessageBacklink
	MessageCommand
	MessageInsertImage
	MessageSpoiler
	MessageDelete
)

1 - 29 modify post model state

const (
	// Update feeds
	MessageSynchronise MessageType = 30 + iota
	MessageReclaim
	MessageSwitchSync

	// Account management
	MessageRegister
	MessageLogin
	MessageAuthenticate
	MessageLogout
	MessageLogOutAll
	MessageChangePassword

	// Board administration
	MessageConfigServer
	MessageCreateBoard

	// Send new post ID to client
	MessagePostID

	// Concatenation of multiple websocket messages to reduce transport overhead
	MessageConcat
)

>= 30 are miscelenious and do not write to post models

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