Documentation ¶
Overview ¶
Package websockets manages active websocket connections and messages received from and sent to them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Clients = ClientMap{ // contains filtered or unexported fields }
Clients stores all synchronised websocket clients in a theread-safe map
var Subs = SubscriptionMap{ // contains filtered or unexported fields }
Subs is the only instance of SubscriptionMap in this running instance, that constains and manages all active subscriptions
Functions ¶
func CheckOrigin ¶
CheckOrigin asserts the client matches the origin specified by the server or has none.
Types ¶
type Client ¶
type Client struct { ID string // 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 ¶
Close closes a websocket connection with the provided status code and optional reason
type ClientMap ¶
ClientMap is a threadsame store for *clients
func (*ClientMap) CountByIP ¶
CountByIP returns the number of unique IPs synchronised with the server
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription manages a map of listener `chan []byte` and sends events to all of them, allowing for thread-safe eventful distribution
func (*Subscription) Add ¶
func (s *Subscription) Add(client chan<- []byte, id string)
Add adds a Client to listen on the Subscription
func (*Subscription) Close ¶
func (s *Subscription) Close(err error)
Close terminates the Subscription
func (*Subscription) Open ¶
func (s *Subscription) Open() error
Open intializes the Subscription and start it's internal loop
func (*Subscription) Remove ¶
func (s *Subscription) Remove(id string)
Remove removes a client from the Subscription
type SubscriptionMap ¶
SubscriptionMap contains all active Subscriptions to threads and boards
func (*SubscriptionMap) Exists ¶
func (s *SubscriptionMap) Exists(id uint64) bool
Exists returns weather a subscription for a thread already exists
func (*SubscriptionMap) ListenTo ¶
func (s *SubscriptionMap) ListenTo(id uint64, client *Client)
ListenTo assigns a client to listen to the specified subscription. If the subscription is not currently active, it is created.
func (*SubscriptionMap) Remove ¶
func (s *SubscriptionMap) Remove(id uint64)
Remove a subscription from the subscription map
func (*SubscriptionMap) Unlisten ¶
func (s *SubscriptionMap) Unlisten(subID uint64, clientID string)
Unlisten removes a listener from a subscription and removes the subscription, if it no longer has any listeners.