websockets

package
v1.7.6-0...-a17e0fe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2016 License: MIT Imports: 11 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

View Source
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

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 {
	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

func (c *Client) Close(status int, reason string) error

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

func (*Client) Send

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

Send thread-safely sends a message to the websocket client

type ClientMap

type ClientMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ClientMap is a threadsame store for *clients

func (*ClientMap) Add

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

Add adds a client to the map

func (*ClientMap) CountByIP

func (c *ClientMap) CountByIP() int

CountByIP returns the number of unique IPs synchronised with the server

func (*ClientMap) Has

func (c *ClientMap) Has(id string) bool

Has checks if a client exists already by id

func (*ClientMap) Remove

func (c *ClientMap) Remove(id string)

Remove removes a client from the map

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

type SubscriptionMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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