rtm

package
v1.2.1-0...-521e7c1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: AGPL-3.0-only Imports: 29 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ChannelPrefixStandard   = "*"
	ChannelPrefixNamedGroup = "@"
)

Channel ID prefixes

Variables

View Source
var ChannelDefaultConfig = &ChannelConfig{}

ChannelDefaultConfig holds a Channel's default extra configuration.

Functions

func CreateNamedGroupChannelID

func CreateNamedGroupChannelID(id string, m *Manager) (string, error)

CreateNamedGroupChannelID creates consistent channel IDs from input parameters.

func MustRegister

func MustRegister(reg prometheus.Registerer, cs ...prometheus.Collector)

MustRegister registers all rtm metrics with the provided registerer and panics upon the first registration that causes an error.

func NewManagerCollector

func NewManagerCollector(manager *Manager) prometheus.Collector

NewManagerCollector return as a collector that exports metrics of the provided Manager,

Types

type Channel

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

Channel binds connections together.

func CreateKnownChannel

func CreateKnownChannel(id string, m *Manager, config *ChannelConfig) *Channel

CreateKnownChannel creates a new channel with known id.

func CreateRandomChannel

func CreateRandomChannel(m *Manager, config *ChannelConfig) *Channel

CreateRandomChannel creates a new channel with random id.

func NewChannel

func NewChannel(id string, m *Manager, logger logrus.FieldLogger, config *ChannelConfig) *Channel

NewChannel initializes a new channel with id.

func (*Channel) Add

func (c *Channel) Add(id string, conn *connection.Connection) error

Add adds the provided connection to the channel identified by id.

func (*Channel) CanBeCleanedUp

func (c *Channel) CanBeCleanedUp() bool

CanBeCleanedUp up returns true if the channel can be cleaned up.

func (*Channel) Cleanup

func (c *Channel) Cleanup() bool

Cleanup closes the associated channels resources and marks the channel closed.

func (*Channel) Connections

func (c *Channel) Connections() ([]string, []*connection.Connection)

Connections returns a array the currenct connection ids and an array of the current connections of this channel.

func (*Channel) Forward

func (c *Channel) Forward(source string, target string, conn *connection.Connection, msg *api.RTMTypeWebRTC) error

Forward takes care of sending the provided message to the channels assigned target.

func (*Channel) Get

func (c *Channel) Get(id string) (*connection.Connection, bool)

Get retrieves the connection identified by the provided id.

func (*Channel) Pipeline

func (c *Channel) Pipeline() Pipeline

Pipeline returns the attached Channel's Pipeline.

func (*Channel) Remove

func (c *Channel) Remove(id string) error

Remove removes the connection identified by the provided id.

func (*Channel) Size

func (c *Channel) Size() int

Size returns the number of connections in this channel.

type ChannelConfig

type ChannelConfig struct {
	Group string

	Replace          func(channel *Channel, cid string, oldConn *connection.Connection, newConn *connection.Connection)
	AfterAddOrRemove func(channel *Channel, op ChannelOp, cid string)
	AfterReset       func(channel *Channel)
}

ChannelConfig adds extra configuration for a Channel.

type ChannelOp

type ChannelOp int

A ChannelOp defines channel operations.

const (
	ChannelOpAdd ChannelOp = iota
	ChannelOpRemove
	ChannelOpReset
)

Channel operations

type Manager

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

Manager handles RTM connect state.

func NewManager

func NewManager(ctx context.Context, id string, insecure bool, requiredScopes []string, pipelineForcedPatternString string, logger logrus.FieldLogger, mcum *mcu.Manager, adminm *admin.Manager, guestm *guest.Manager, oidcp *kcoidc.Provider, turnsrv turn.Server) *Manager

NewManager creates a new Manager with an id.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context, userID string, auth *api.AdminAuthToken) (string, error)

Connect adds a new connect entry to the managers table with random key.

func (*Manager) Context

func (m *Manager) Context() context.Context

Context Returns the Context of the associated manager.

func (*Manager) HTTPWebsocketHandler

func (m *Manager) HTTPWebsocketHandler(rw http.ResponseWriter, req *http.Request)

HTTPWebsocketHandler implements the HTTP handler for websocket requests.

func (*Manager) HandleWebsocketConnect

func (m *Manager) HandleWebsocketConnect(ctx context.Context, key string, rw http.ResponseWriter, req *http.Request) error

HandleWebsocketConnect checks the presence of the key in cache and starts the websocket connection in a new go routine. Returns with nil when the websocket connection was successfuly started, otherwise with error.

func (*Manager) LookupConnectionsByID

func (m *Manager) LookupConnectionsByID(id string) ([]*connection.Connection, bool)

LookupConnectionsByID returns a copy slice of the active connections for the user accociated with the provided ID.

func (*Manager) MakeHTTPConnectHandler

func (m *Manager) MakeHTTPConnectHandler(router *mux.Router, websocketRouteIdentifier string) http.Handler

MakeHTTPConnectHandler createss the HTTP handler for rtm.connect.

func (*Manager) MakeHTTPTURNHandler

func (m *Manager) MakeHTTPTURNHandler(router *mux.Router) http.Handler

MakeHTTPTURNHandler creates the HTTP handler for rtm.turn.

func (*Manager) NewHandle

func (m *Manager) NewHandle() int64

NewHandle returns the next available handle id of the accociated manager.

func (*Manager) NumActive

func (m *Manager) NumActive() uint64

NumActive returns the number of the currently active connections at the accociated manager.

func (*Manager) OnBeforeDisconnect

func (m *Manager) OnBeforeDisconnect(c *connection.Connection, err error) error

OnBeforeDisconnect is called before a connection is closed. An indication why the connection will be closed is provided with the passed error.

func (*Manager) OnConnect

func (m *Manager) OnConnect(c *connection.Connection) error

OnConnect is called for new connections.

func (*Manager) OnDisconnect

func (m *Manager) OnDisconnect(c *connection.Connection) error

OnDisconnect is called after a connection has closed.

func (*Manager) OnError

func (m *Manager) OnError(c *connection.Connection, err error) error

OnError is called, when the provided connection has encountered an error. The provided error is the error encountered. Any return value other than nil, will result in a close of the connection.

func (*Manager) OnServerStatus

func (m *Manager) OnServerStatus(newServerStatus *api.ServerStatus) error

OnServerStatus is called, when the associated server status changes any of its pre defined status settings.

func (*Manager) OnText

func (m *Manager) OnText(c *connection.Connection, msg []byte) error

OnText is called when the provided connection received a text message. The message payload is provided as []byte in the msg parameter.

func (*Manager) Pipeline

func (m *Manager) Pipeline(scope string, id string) Pipeline

Pipeline returns a pipleline which fits to the accociated Manager.

type Pipeline

type Pipeline interface {
	ID() string
	Mode() string

	Connect(onConnect func() error, onText func([]byte) error, onReset func(error) error) error

	Send(msg interface{}) error

	Close() error
}

Pipeline is for forwarding rtm messages to somewhere else.

Jump to

Keyboard shortcuts

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