Documentation
¶
Index ¶
- Variables
- type Channel
- type CloseWrapper
- type Conn
- type ConnectionHook
- type ConnectionRegistry
- type ConnectionRegistryOption
- func WithConcurrencyLimit(limit uint) ConnectionRegistryOption
- func WithConnectionLimit(limit int) ConnectionRegistryOption
- func WithInActivityTimeout(timeout time.Duration) ConnectionRegistryOption
- func WithMaxFrameLimit(limit int64) ConnectionRegistryOption
- func WithOnConnectHook(cb ConnectionHook) ConnectionRegistryOption
- func WithOnDisconnectHook(cb ConnectionHook) ConnectionRegistryOption
- type ConnectionWrapper
- type Middlewere
- type Option
- type SendWrapper
- type WrapperOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnectionClosed is error for closed connections ErrConnectionClosed = errors.New("connection is closed") )
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is default implementation of Channel
func NewChannel ¶
func NewChannel( path string, dispatcher wasabi.Dispatcher, connRegistry wasabi.ConnectionRegistry, opts ...Option, ) *Channel
NewChannel creates new instance of Channel path - channel path dispatcher - dispatcher to use connRegistry - connection registry to use reqParser - request parser to use returns new instance of Channel
func (*Channel) Close ¶
Shutdown gracefully shuts down the Channel by shutting down the underlying connection registry. It waits for all active connections to be closed or until the context is canceled. Returns an error if the shutdown process encounters any issues.
type CloseWrapper ¶ added in v0.2.0
type CloseWrapper func(conn wasabi.Connection, status websocket.StatusCode, reason string, closingCtx ...context.Context) error
CloseWrapper is a function type that wraps the Close method of a ConnectionWrapper.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is default implementation of Connection
func NewConnection ¶
func NewConnection( ctx context.Context, ws *websocket.Conn, cb wasabi.OnMessage, bufferPool *bufferPool, concurrencyLimit uint, inActivityTimeout time.Duration, ) *Conn
NewConnection creates new instance of websocket connection
func (*Conn) Close ¶
Close closes the connection with the specified status code and reason. If the connection is already closed, it returns an error. If a closing context is provided, it waits for pending requests to complete before closing the connection. If the context is canceled, the connection is closed immediately. If there are no pending requests, the connection is closed immediately. After closing the connection, the connection state is set to terminated
type ConnectionHook ¶ added in v0.2.0
type ConnectionHook func(wasabi.Connection)
type ConnectionRegistry ¶
type ConnectionRegistry struct {
// contains filtered or unexported fields
}
ConnectionRegistry is default implementation of ConnectionRegistry
func NewConnectionRegistry ¶
func NewConnectionRegistry(opts ...ConnectionRegistryOption) *ConnectionRegistry
NewConnectionRegistry creates new instance of ConnectionRegistry
func (*ConnectionRegistry) CanAccept ¶ added in v0.4.0
func (r *ConnectionRegistry) CanAccept() bool
CanAccept checks if the connection registry can accept new connections. It returns true if the registry can accept new connections, and false otherwise.
func (*ConnectionRegistry) Close ¶
func (r *ConnectionRegistry) Close(ctx ...context.Context) error
Shutdown closes all connections in the ConnectionRegistry. It sets the isClosed flag to true, indicating that the registry is closed. It then iterates over all connections, closes them with the given context, and waits for all closures to complete before returning.
func (*ConnectionRegistry) GetConnection ¶
func (r *ConnectionRegistry) GetConnection(id string) wasabi.Connection
GetConnection returns connection by id
func (*ConnectionRegistry) HandleConnection ¶ added in v0.4.0
func (r *ConnectionRegistry) HandleConnection( ctx context.Context, ws *websocket.Conn, cb wasabi.OnMessage, )
AddConnection adds new Websocket connection to registry
type ConnectionRegistryOption ¶
type ConnectionRegistryOption func(*ConnectionRegistry)
func WithConcurrencyLimit ¶
func WithConcurrencyLimit(limit uint) ConnectionRegistryOption
WithConcurrencyLimit sets the maximum number of concurrent requests that can be handled by a connection. The default concurrency limit is 25. When the concurrency limit is exceeded, the connection stops reading messages until the number of concurrent requests decreases.
func WithConnectionLimit ¶ added in v0.4.0
func WithConnectionLimit(limit int) ConnectionRegistryOption
WithConnectionLimit sets the maximum number of connections that can be accepted by the ConnectionRegistry. The default connection limit is -1, which means there is no limit on the number of connections. If the connection limit is set to a positive integer, the ConnectionRegistry will not accept new connections once the number of active connections reaches the specified limit.
func WithInActivityTimeout ¶
func WithInActivityTimeout(timeout time.Duration) ConnectionRegistryOption
WithInActivityTimeout sets the inactivity timeout for the connection. The default inactivity timeout is 0 seconds, which means the timeout is disabled. When the inactivity timeout is enabled, the connection is closed if there are no messages received within the specified duration.
func WithMaxFrameLimit ¶
func WithMaxFrameLimit(limit int64) ConnectionRegistryOption
WithMaxFrameLimit sets the maximum frame size limit for incomming messages to the ConnectionRegistry. The limit parameter specifies the maximum frame size limit in bytes. This option can be used when creating a new ConnectionRegistry instance. The default frame size limit is 32768 bytes. If the limit is set to -1, the frame size limit is disabled. When the frame size limit is exceeded, the connection is closed with status 1009 (message too large).
func WithOnConnectHook ¶ added in v0.2.0
func WithOnConnectHook(cb ConnectionHook) ConnectionRegistryOption
WithOnConnectHook sets the connection hook function that will be called when a new connection is established. The provided callback function `cb` will be invoked with the newly established connection as its argument. This function returns a ConnectionRegistryOption that can be used to configure a ConnectionRegistry.
func WithOnDisconnectHook ¶ added in v0.2.0
func WithOnDisconnectHook(cb ConnectionHook) ConnectionRegistryOption
WithOnDisconnectHook sets the callback function to be executed when a connection is disconnected. The provided callback function should have the signature `func(connectionID string)`. It can be used to perform any necessary cleanup or logging operations when a connection is disconnected.
type ConnectionWrapper ¶ added in v0.2.0
type ConnectionWrapper struct {
// contains filtered or unexported fields
}
ConnectionWrapper is a wrapper around a wasabi.Connection that allows for custom behavior to be applied to the connection.
func NewConnectionWrapper ¶ added in v0.2.0
func NewConnectionWrapper(connection wasabi.Connection, opts ...WrapperOptions) *ConnectionWrapper
NewConnectionWrapper creates a new ConnectionWrapper instance with the given connection and options. It applies the provided WrapperOptions to the wrapper before returning it.
func (*ConnectionWrapper) Close ¶ added in v0.2.0
func (cw *ConnectionWrapper) Close(status websocket.StatusCode, reason string, closingCtx ...context.Context) error
Close closes the connection with the specified status code and reason. It also accepts an optional closing context. If an onCloseWrapper function is set, it will be called instead of directly closing the connection. The onCloseWrapper function should have the same signature as the Connection.Close method.
func (*ConnectionWrapper) Context ¶ added in v0.2.0
func (cw *ConnectionWrapper) Context() context.Context
Context returns the context associated with the connection wrapper.
func (*ConnectionWrapper) ID ¶ added in v0.2.0
func (cw *ConnectionWrapper) ID() string
ID returns the ID of the ConnectionWrapper.
func (*ConnectionWrapper) Send ¶ added in v0.2.0
func (cw *ConnectionWrapper) Send(msgType wasabi.MessageType, msg []byte) error
Send sends a message of the specified type and content over the connection. If an onSendWrapper function is set, it will be called instead of directly sending the message. The onSendWrapper function should have the signature func(connection Connection, msgType MessageType, msg []byte) error. If there is no onSendWrapper function set, the message will be sent directly using the underlying connection. Returns an error if there was a problem sending the message.
type Middlewere ¶
Middlewere is interface for middlewares
type Option ¶
type Option func(*channelConfig)
func WithCompressionMode ¶ added in v0.4.0
func WithCompressionMode(mode websocket.CompressionMode, threshold int) Option
WithCompressionMode sets the compression mode and threshold for a channel configuration. The compression mode determines how the channel data will be compressed, and the threshold specifies the minimum size of the payload required for compression to be applied.
func WithOriginPatterns ¶
WithOriginPatterns sets the origin patterns for the channel. The origin patterns are used to validate the Origin header of the WebSocket handshake request. If the Origin header does not match any of the patterns, the connection is rejected.
type SendWrapper ¶ added in v0.2.0
type SendWrapper func(conn wasabi.Connection, msgType wasabi.MessageType, msg []byte) error
SendWrapper is a function type that wraps the Send method of a ConnectionWrapper.
type WrapperOptions ¶ added in v0.2.0
type WrapperOptions func(*ConnectionWrapper)
WrapperOptions is a function type that represents options for configuring a ConnectionWrapper. It is used to modify the behavior of the ConnectionWrapper by applying various options.
func WithCloseWrapper ¶ added in v0.2.0
func WithCloseWrapper(wrapper CloseWrapper) WrapperOptions
WithCloseWrapper returns a WrapperOptions function that sets the onCloseWrapper field of the ConnectionWrapper to the provided wrapper.
func WithSendWrapper ¶ added in v0.2.0
func WithSendWrapper(wrapper SendWrapper) WrapperOptions
WithSendWrapper returns a WrapperOptions function that sets the onSendWrapper field of the ConnectionWrapper to the provided wrapper.