pubsub

package
v0.0.0-...-273060c Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const Capacity = 10

Variables

This section is empty.

Functions

func UseCollection

func UseCollection(coll *Collection) func(http.Handler) http.Handler

Types

type Client

type Client struct {
	UserID facechat.ID
	Events chan interface{}
	// contains filtered or unexported fields
}

func NewClient

func NewClient(userID facechat.ID) *Client

func (*Client) Background

func (c *Client) Background() <-chan struct{}

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect(w http.ResponseWriter, r *http.Request) error

type Collection

type Collection struct {
	*pubsub.PubSub
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(db *db.DB) *Collection

func RequestCollection

func RequestCollection(r *http.Request) *Collection

func (*Collection) BroadcastMessage

func (c *Collection) BroadcastMessage(msg facechat.Message)

BroadcastMessage broadcasts the given message to room ID topic.

func (*Collection) Register

func (c *Collection) Register(client *Client)

Register registers a client.

func (*Collection) SubscribeRoom

func (c *Collection) SubscribeRoom(userID, roomID facechat.ID)

SubscribeRoom subscribes the user with the ID to a room.

func (*Collection) Unregister

func (c *Collection) Unregister(userID facechat.ID)

Unregister unsubscribes the given client, then removes it from the collection.

func (*Collection) UnsubscribeRoom

func (c *Collection) UnsubscribeRoom(userID, roomID facechat.ID)

UnsubscribeRoom unsubscribes the user with the ID to a room.

type Event

type Event struct {
	Event string          `json:"e"`
	Data  json.RawMessage `json:"d"`
}

func NewEvent

func NewEvent(v interface{}) (Event, error)

Jump to

Keyboard shortcuts

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