Documentation ¶
Overview ¶
Package websockets manages active websocket connections and messages received from and sent to them
Index ¶
- Variables
- func ConstructThread(req ThreadCreationRequest, ip string, parseBody bool) (id uint64, timeStamp int64, hasImage bool, err error)
- func EncodeMessage(typ MessageType, msg interface{}) ([]byte, error)
- func Handler(res http.ResponseWriter, req *http.Request)
- func Listen() error
- func UpdatePost(id uint64, key string, val interface{}, msg []byte) error
- type Client
- type ClientMap
- type ImageRequest
- type MessageType
- type ReplyCreationRequest
- type SyncID
- type ThreadCreationRequest
Constants ¶
This section is empty.
Variables ¶
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 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.
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
type ClientMap ¶
ClientMap is a thread-safe store for all clients connected to this server instance
type ImageRequest ¶
ImageRequest contains data for allocating an image
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 )
1 - 29 modify post model state
const ( MessageSynchronise MessageType = 30 + iota MessageReclaim // Send new post ID to client MessagePostID // Concatenation of multiple websocket messages to reduce transport overhead MessageConcat // Message from the client meant to invoke no operation. Mostly used as a // one way ping, because the JS Websocket API does not provide access to // pinging. MessageNOOP )
>= 30 are miscellaneous and do not write to post models
type ReplyCreationRequest ¶
type ReplyCreationRequest struct { Image ImageRequest Name, Auth, Password, Body string }
ReplyCreationRequest contains common fields for both thread and reply creation
type SyncID ¶
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 string common.Captcha }
ThreadCreationRequest contains data for creating a new thread