Documentation
¶
Index ¶
Constants ¶
View Source
const Protocol = parser.Protocol
Variables ¶
View Source
var ( // Protocol errors mappings. UNKNOWN_TRANSPORT = &types.CodeMessage{Code: 0, Message: `Transport unknown`} UNKNOWN_SID = &types.CodeMessage{Code: 1, Message: `Session ID unknown`} BAD_HANDSHAKE_METHOD = &types.CodeMessage{Code: 2, Message: `Bad handshake method`} BAD_REQUEST = &types.CodeMessage{Code: 3, Message: `Bad request`} FORBIDDEN = &types.CodeMessage{Code: 4, Message: `Forbidden`} UNSUPPORTED_PROTOCOL_VERSION = &types.CodeMessage{Code: 4, Message: `Unsupported protocol version`} )
Functions ¶
This section is empty.
Types ¶
type BaseServer ¶
type BaseServer interface {
events.EventEmitter
Prototype(BaseServer)
Proto() BaseServer
Opts() config.ServerOptionsInterface
// Protected
Clients() *types.Map[string, Socket]
ClientsCount() uint64
// Protected
Middlewares() []Middleware
// Construct() should be called after calling Prototype()
Construct(any)
// Protected
//
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.
//
// Todo: Return []string
Upgrades(string) *types.Set[string]
// Protected
//
// Verifies a request.
Verify(*types.HttpContext, bool) (*types.CodeMessage, 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
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) (*types.CodeMessage, transports.Transport)
// Protected
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 SendCallback ¶ added in v2.2.1
type SendCallback func(transports.Transport)
type Server ¶
type Server interface {
BaseServer
// Captures upgrade requests for a http.Handler, Need to handle server shutdown disconnecting client connections.
http.Handler
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)
OnWebTransportSession(*types.HttpContext, *webtransport.Server)
// 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.
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, SendCallback) Socket
Write(io.Reader, *packet.Options, SendCallback) Socket
// Closes the socket and underlying transport.
Close(bool)
}
func NewSocket ¶
func NewSocket(id string, server BaseServer, transport transports.Transport, ctx *types.HttpContext, protocol int) Socket
Client class.
Click to show internal directories.
Click to hide internal directories.