websockets

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2017 License: AGPL-3.0, AGPL-3.0-or-later Imports: 20 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 synchronized websocket clients in a thread-safe map

Functions

func ConstructThread

func ConstructThread(req ThreadCreationRequest, ip string, parseBody bool) (
	id uint64, timeStamp int64, hasImage bool, err error,
)

ConstructThread creates a new tread and writes it to the database. Returns the ID of the thread and its creation timestamp

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 {
	// 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) Redirect

func (c *Client) Redirect(board string)

Redirect closes any open posts and forces the client to sync to the target board

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

func (c *ClientMap) GetByIP(ip string) (clients []common.Client)

GetByIP retrieves all Clients that match the passed IP

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 ImageRequest

type ImageRequest struct {
	Spoiler     bool
	Token, Name string
}

ImageRequest contains data for allocating an image

type ReplyCreationRequest

type ReplyCreationRequest struct {
	Image ImageRequest
	auth.SessionCreds
	Name, Password, Body string
}

ReplyCreationRequest contains common fields for both thread and reply creation

type SyncID

type SyncID struct {
	OP    uint64
	Board string
}

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

type ThreadCreationRequest

type ThreadCreationRequest struct {
	ReplyCreationRequest
	Subject, Board, Captcha string
}

ThreadCreationRequest contains data for creating a new thread

Jump to

Keyboard shortcuts

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