websocket

package
v0.0.0-...-500edce Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetCommandMethod = iota + 1
	DeleteCommandMethod
	PostCommandMethod
	PatchCommandMethod
	NotifyCommandMethod
	ErrorCommandMethod
	HeartbeatCommandMethod
)
View Source
const (
	RequestContextCommandKey = "command"
	RequestContextSourceKey  = "Source"
	RequestContextIDKey      = "id"
)

Variables

This section is empty.

Functions

func NewRequestContext

func NewRequestContext(command RESTCommand, id, sourceCtx int) context.Context

Types

type RESTCommand

type RESTCommand struct {
	Ressource string `json:"ressource"`
	Method    int    `json:"method"`
}

type Server

type Server struct {
	Messaging     messaging.Service
	Conversations conversations.Service
	User          user.Service
	// contains filtered or unexported fields
}

func New

func New(
	messagingService messaging.Service,
	conversationService conversations.Service,
	userService user.Service,
	limiterStore throttled.GCRAStore,
	logger log.Logger) *Server

func (*Server) AddRoom

func (s *Server) AddRoom(roomNumber int, initialClientID int)

AddRoom adds a new room to the room map.

func (*Server) BroadcastToRoom

func (s *Server) BroadcastToRoom(roomNumber int, payload interface{}, ctx context.Context)

BroadcastToRoom sends a RESTCommand with payload to every member of the specified room.

func (*Server) DisconnectClient

func (s *Server) DisconnectClient(clientID int)

func (*Server) JoinRoom

func (s *Server) JoinRoom(roomNumber int, userID int)

JoinRoom adds a client to a room If either the room or the client does not exist, nothing is done.

func (*Server) RemoveClientFromRoom

func (s *Server) RemoveClientFromRoom(roomNumber int, userID int)

RemoveClientFromRoom removes the client with the spcified id from the room. If the client or the room doesn't exist this function does nothing.

func (*Server) RemoveRoom

func (s *Server) RemoveRoom(roomNumber int)

func (*Server) StartWebsocket

func (s *Server) StartWebsocket(w http.ResponseWriter, r *http.Request, user int) error

StartWebsocket upgrades the connection to a websocket connection.

func (*Server) Unicast

func (s *Server) Unicast(ctx context.Context, userID int, payload interface{})

Unicast sends a message over all the connections a client has established.

type WebsocketRateLimiter

type WebsocketRateLimiter struct {
	RateLimiter throttled.RateLimiter
	VaryBy      interface {
		Key(method int, ressource string, remoteAddr string) string
	}
}

func (*WebsocketRateLimiter) RateLimit

func (l *WebsocketRateLimiter) RateLimit(method int, ressource string, remoteAddr string) (error, error)

RateLimit checks if the rate limit for the given citeria was reached. If yes it returns an RequestLimitExceededError error as its first return value. The second returned error is not nil if something went wrong.

type WebsocketVaryBy

type WebsocketVaryBy struct {
	RemoteAddr bool
	Method     bool
	Ressource  bool
}

func (*WebsocketVaryBy) Key

func (vb *WebsocketVaryBy) Key(method int, ressource string, remoteAddr string) string

Key returns the key for this request based on the criteria defined by the VaryBy struct.

Jump to

Keyboard shortcuts

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