ws

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 15 Imported by: 1

README

RoadRunner: Websocket broadcasting

Latest Stable Version GoDoc Build Status Go Report Card Codecov

License:

The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

Documentation

Index

Constants

View Source
const (
	// EventConnect fired when new client is connected, the context is *websocket.Conn.
	EventConnect = iota + 2500

	// EventDisconnect fired when websocket is disconnected, context is empty.
	EventDisconnect

	// EventJoin caused when topics are being consumed, context if *TopicEvent.
	EventJoin

	// EventLeave caused when topic consumption are stopped, context if *TopicEvent.
	EventLeave

	// EventError when any broadcast error occurred, the context is *ErrorEvent.
	EventError
)
View Source
const ID = "ws"

ID defines service id.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path defines on this URL the middleware must be activated. Same path must
	// be handled by underlying application kernel to authorize the consumption.
	Path string

	// NoOrigin disables origin check, only for debug.
	NoOrigin bool
}

Config defines the websocket service configuration.

func (*Config) Hydrate

func (c *Config) Hydrate(cfg service.Config) error

Hydrate reads the configuration values from the source configuration.

type ConnContext

type ConnContext struct {
	// Conn to the client.
	Conn *websocket.Conn

	// Topics contain list of currently subscribed topics.
	Topics []string
	// contains filtered or unexported fields
}

ConnContext carries information about websocket connection and it's topics.

func (*ConnContext) SendMessage

func (ctx *ConnContext) SendMessage(topic string, payload interface{}) (err error)

SendMessage message directly to the client.

type ErrorEvent

type ErrorEvent struct {
	// Conn specific to the error.
	Conn *websocket.Conn

	// Error contains job specific error.
	Error error
}

ErrorEvent represents singular broadcast error event.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service to manage websocket clients.

func (*Service) AddListener

func (s *Service) AddListener(l func(event int, ctx interface{}))

AddListener attaches server event controller.

func (*Service) Init

func (s *Service) Init(
	cfg *Config,
	env env.Environment,
	rttp *rhttp.Service,
	rpc *rpc.Service,
	broadcast *broadcast.Service,
) (bool, error)

Init the service.

func (*Service) Serve

func (s *Service) Serve() error

Serve the websocket connections.

func (*Service) Stop

func (s *Service) Stop()

Stop the service and disconnect all connections.

type TopicEvent

type TopicEvent struct {
	// Conn associated with topics.
	Conn *websocket.Conn

	// Topics specific to event.
	Topics []string
}

TopicEvent caused when topic is joined or left.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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