engine

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OK_REQUEST                   int = -1
	UNKNOWN_TRANSPORT            int = 0
	UNKNOWN_SID                  int = 1
	BAD_HANDSHAKE_METHOD         int = 2
	BAD_REQUEST                  int = 3
	FORBIDDEN                    int = 4
	UNSUPPORTED_PROTOCOL_VERSION int = 5
)

Protocol errors mappings.

View Source
const Protocol = 4

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseServer

type BaseServer interface {
	events.EventEmitter

	Prototype(BaseServer)
	Proto() BaseServer

	Opts() config.ServerOptionsInterface
	// @protected
	Clients() *e_types.Map[string, Socket]
	ClientsCount() uint64
	// @protected
	Middlewares() []Middleware

	// Construct() should be called after calling Prototype()
	Construct(any)

	// @protected
	// @abstract
	Init()
	// @protected
	// Compute the pathname of the requests that are handled by the server
	ComputePath(config.AttachOptionsInterface) string
	// Returns a list of available transports for upgrade given a certain transport.
	Upgrades(string) *e_types.Set[string]
	// @protected
	// Verifies a request.
	Verify(*types.HttpContext, bool) (int, map[string]any)
	// Adds a new middleware.
	Use(Middleware)
	// @protected
	// Apply the middlewares to the request.
	ApplyMiddlewares(*types.HttpContext, func(error))
	// Closes all clients.
	Close() BaseServer
	// @protected
	// @abstract
	Cleanup()
	// generate a socket id.
	// Overwrite this method to generate your custom socket id
	GenerateId(*types.HttpContext) (string, error)
	// @protected
	// Handshakes a new client.
	Handshake(string, *types.HttpContext) (int, transports.Transport)
	// @protected
	// @abstract
	CreateTransport(string, *types.HttpContext) (transports.Transport, error)
}

func MakeBaseServer

func MakeBaseServer() BaseServer

type Middleware

type Middleware func(*types.HttpContext, func(error))

Middleware functions are functions that have access to the *types.HttpContext and the next middleware function in the application's context cycle.

type Server

type Server interface {
	types.Handler
	BaseServer

	SetHttpServer(*types.HttpServer)

	HttpServer() *types.HttpServer

	CreateTransport(string, *types.HttpContext) (transports.Transport, error)
	// Handles an Engine.IO HTTP request.
	HandleRequest(*types.HttpContext)
	// Handles an Engine.IO HTTP Upgrade.
	HandleUpgrade(*types.HttpContext)
	// Captures upgrade requests for a *types.HttpServer.
	Attach(*types.HttpServer, any)
}

func Attach

func Attach(server *types.HttpServer, options any) Server

Captures upgrade requests for a types.HttpServer.

func Listen

func Listen(addr string, options any, fn _types.Callable) Server

Creates an fasthttp.Server exclusively used for WS upgrades.

func MakeServer

func MakeServer() Server

new server.

func New

func New(server any, args ...any) Server

func NewServer

func NewServer(opt any) Server

create server.

type Socket

type Socket interface {
	events.EventEmitter

	SetReadyState(string)

	Protocol() int
	Request() *types.HttpContext
	RemoteAddress() string
	Transport() transports.Transport
	Id() string
	ReadyState() string
	// @private
	Upgraded() bool
	// @private
	Upgrading() bool

	Construct(string, BaseServer, transports.Transport, *types.HttpContext, int)
	// @private
	// Upgrades socket to the given transport
	MaybeUpgrade(transports.Transport)
	// Sends a message packet.
	Send(io.Reader, *packet.Options, func(transports.Transport)) Socket
	Write(io.Reader, *packet.Options, func(transports.Transport)) Socket
	// Closes the socket and underlying transport.
	Close(bool)
}

func MakeSocket

func MakeSocket() Socket

Client class.

func NewSocket

func NewSocket(id string, server BaseServer, transport transports.Transport, ctx *types.HttpContext, protocol int) Socket

Client class.

Jump to

Keyboard shortcuts

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