conns

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDisconnectAdvice = &DisconnectAdvice{Reason: "", Reconnect: true}

DefaultDisconnectAdvice is no reason and reconnect.

View Source
var (
	// ShutdownSemaphoreChanBufferSize limits graceful disconnects concurrency on
	// node shutdown.
	ShutdownSemaphoreChanBufferSize = 1000
)

Functions

This section is empty.

Types

type AdminConn

type AdminConn interface {
	// UID returns unique admin connection id.
	UID() string
	// Handle message coming from admin client.
	Handle(message []byte) error
	// Send allows to send message to admin connection.
	Send(*QueuedMessage) error
	// Close closes admin's connection.
	Close(*DisconnectAdvice) error
}

AdminConn is an interface abstracting all methods used by application to interact with admin connection.

type AdminHub

type AdminHub interface {
	Add(c AdminConn) error
	Remove(c AdminConn) error
	NumAdmins() int
	Broadcast(message []byte) error
	Shutdown() error
}

AdminHub is an interface describing admin connections to node.

func NewAdminHub

func NewAdminHub() AdminHub

NewAdminHub initializes new adminHub.

type ClientConn

type ClientConn interface {
	// UID returns unique connection id.
	UID() string
	// User return user ID associated with connection.
	User() string
	// Channels returns a slice of channels connection subscribed to.
	Channels() []string
	// Handle message coming from client.
	Handle(message []byte) error
	// Send allows to send message to connection client.
	Send(*QueuedMessage) error
	// Unsubscribe allows to unsubscribe connection from channel.
	Unsubscribe(ch string) error
	// Close closes client's connection.
	Close(*DisconnectAdvice) error
}

ClientConn is an interface abstracting all methods used by application to interact with client connection.

type ClientHub

type ClientHub interface {
	Add(c ClientConn) error
	Remove(c ClientConn) error
	AddSub(ch string, c ClientConn) (bool, error)
	RemoveSub(ch string, c ClientConn) (bool, error)
	Broadcast(ch string, message []byte) error
	NumSubscribers(ch string) int
	NumClients() int
	NumUniqueClients() int
	NumChannels() int
	Channels() []string
	UserConnections(user string) map[string]ClientConn
	Shutdown() error
}

ClientHub is an interface describing current client connections to node.

func NewClientHub

func NewClientHub() ClientHub

NewClientHub initializes clientHub.

type DisconnectAdvice

type DisconnectAdvice struct {
	Reason    string `json:"reason"`
	Reconnect bool   `json:"reconnect"`
	// contains filtered or unexported fields
}

DisconnectAdvice sent to client when we want it to gracefully disconnect.

func (*DisconnectAdvice) JSONString

func (a *DisconnectAdvice) JSONString() (string, error)

JSONString contains cached representation of DisconnectAdvice as JSON.

type QueuedMessage added in v1.7.0

type QueuedMessage struct {
	// Payload is raw message payload (encoded in JSON).
	Payload []byte
	// UsePrepared can be used in session Send method to determine which
	// underlying transport write method to use. At moment used for websocket
	// session only - so we can call WriteMessage or WritePreparedMessage
	// connection methods.
	UsePrepared bool
	// contains filtered or unexported fields
}

QueuedMessage is a wrapper structure over raw data payload. It can optionally contain prepared websocket message (to drastically reduce overhead of framing in case of using websocket compression).

func NewQueuedMessage added in v1.7.0

func NewQueuedMessage(payload []byte, usePrepared bool) *QueuedMessage

NewQueuedMessage initializes QueuedMessage.

func (*QueuedMessage) Len added in v1.7.0

func (m *QueuedMessage) Len() int

Len returns length of QueuedMessage payload so QueuedMessage implements item that can be queued into our unbounded queue.

func (*QueuedMessage) Prepared added in v1.7.0

func (m *QueuedMessage) Prepared() *websocket.PreparedMessage

Prepared allows to get PreparedMessage for raw websocket connections. It constructs PreparedMessage lazily after first call.

type Session

type Session interface {
	// Send sends one message to session
	Send(*QueuedMessage) error
	// Close closes the session with provided code and reason.
	Close(*DisconnectAdvice) error
}

Session represents a connection transport between server and client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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