sse

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSSESession

func NewSSESession(n *node.Node, w http.ResponseWriter, r *http.Request, info *server.RequestInfo) (*node.Session, error)

func SSEHandler

func SSEHandler(n *node.Node, shutdownCtx context.Context, headersExtractor server.HeadersExtractor, config *Config, l *slog.Logger) http.Handler

SSEHandler generates a new http handler for SSE connections

Types

type Config

type Config struct {
	Enabled bool
	// Path is the URL path to handle long-polling requests
	Path string
	// List of allowed origins for CORS requests
	// We inherit it from the ws.Config
	AllowedOrigins string
}

Long-polling configuration

func NewConfig

func NewConfig() Config

NewConfig creates a new Config with default values.

type Connection

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

func NewConnection

func NewConnection(w http.ResponseWriter) *Connection

NewConnection creates a new long-polling connection wrapper

func (*Connection) Close

func (c *Connection) Close(code int, reason string)

func (*Connection) Context

func (c *Connection) Context() context.Context

func (*Connection) Descriptor

func (c *Connection) Descriptor() net.Conn

func (*Connection) Established

func (c *Connection) Established()

Mark as closed to avoid writing to closed connection

func (*Connection) Read

func (c *Connection) Read() ([]byte, error)

func (*Connection) Write

func (c *Connection) Write(msg []byte, deadline time.Time) error

func (*Connection) WriteBinary

func (c *Connection) WriteBinary(msg []byte, deadline time.Time) error

type Encoder

type Encoder struct {
	// Whether to send only the "message" field of the payload as data or the whole payload
	UnwrapData bool
}

Encoder is responsible for converting messages to SSE format (event:, data:, etc.) NOTE: It's only used to encode messages from server to client.

func (Encoder) Decode

func (Encoder) Decode(raw []byte) (*common.Message, error)

func (*Encoder) Encode

func (e *Encoder) Encode(msg encoders.EncodedMessage) (*ws.SentFrame, error)

func (Encoder) EncodeTransmission

func (e Encoder) EncodeTransmission(raw string) (*ws.SentFrame, error)

func (Encoder) ID

func (Encoder) ID() string

Jump to

Keyboard shortcuts

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