websocket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package websocket provides WebSocket handling for the crawler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EndpointInfo

type EndpointInfo struct {
	URL            string
	DiscoveredFrom string
	Protocols      []string
	Messages       []Message
	Connected      bool
	ConnectTime    time.Time
	Error          error
}

EndpointInfo contains information about a WebSocket endpoint.

type Handler

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

Handler manages WebSocket connections and message recording.

func NewHandler

func NewHandler() *Handler

NewHandler creates a new WebSocket handler.

func (*Handler) Clear

func (h *Handler) Clear()

Clear clears all discovered endpoints.

func (*Handler) Connect

func (h *Handler) Connect(ctx context.Context, wsURL, sourceURL string) error

Connect attempts to connect to a WebSocket endpoint.

func (*Handler) Count

func (h *Handler) Count() int

Count returns the number of discovered endpoints.

func (*Handler) Disable

func (h *Handler) Disable()

Disable disables WebSocket handling.

func (*Handler) Enable

func (h *Handler) Enable()

Enable enables WebSocket handling.

func (*Handler) GetEndpoints

func (h *Handler) GetEndpoints() []WebSocketEndpoint

GetEndpoints returns all discovered WebSocket endpoints.

func (*Handler) HasEndpoint

func (h *Handler) HasEndpoint(wsURL string) bool

HasEndpoint checks if an endpoint has been discovered.

func (*Handler) SendMessage

func (h *Handler) SendMessage(ctx context.Context, wsURL string, msgType int, data []byte) error

SendMessage sends a message and records the response.

func (*Handler) SetCookies

func (h *Handler) SetCookies(cookies []*http.Cookie)

SetCookies sets cookies for WebSocket connections.

func (*Handler) SetHeaders

func (h *Handler) SetHeaders(headers map[string]string)

SetHeaders sets custom headers for WebSocket connections.

func (*Handler) SetMaxMessages

func (h *Handler) SetMaxMessages(max int)

SetMaxMessages sets the maximum number of messages to record per endpoint.

func (*Handler) SetMessageTimeout

func (h *Handler) SetMessageTimeout(timeout time.Duration)

SetMessageTimeout sets the timeout for receiving messages.

type Message

type Message struct {
	Direction string // "sent" or "received"
	Type      int    // websocket.TextMessage, websocket.BinaryMessage, etc.
	Data      []byte
	Timestamp time.Time
}

Message represents a WebSocket message.

type PatternAnalysis

type PatternAnalysis struct {
	URL           string         `json:"url"`
	MessageCount  int            `json:"message_count"`
	SentCount     int            `json:"sent_count"`
	ReceivedCount int            `json:"received_count"`
	MessageTypes  map[string]int `json:"message_types"`
	AverageSize   int            `json:"average_size"`
	MaxSize       int            `json:"max_size"`
	MinSize       int            `json:"min_size"`
	HasJSON       bool           `json:"has_json"`
}

PatternAnalysis contains analysis of message patterns.

type RecordedMessage

type RecordedMessage struct {
	Timestamp time.Time `json:"timestamp"`
	Direction string    `json:"direction"` // "sent" or "received"
	Type      string    `json:"type"`      // "text", "binary", "ping", "pong"
	Data      []byte    `json:"data"`
	Size      int       `json:"size"`
}

RecordedMessage represents a recorded WebSocket message.

type RecordedSession

type RecordedSession struct {
	URL           string            `json:"url"`
	StartTime     time.Time         `json:"start_time"`
	EndTime       time.Time         `json:"end_time,omitempty"`
	Messages      []RecordedMessage `json:"messages"`
	TotalSent     int               `json:"total_sent"`
	TotalReceived int               `json:"total_received"`
	Active        bool              `json:"active"`
}

RecordedSession contains recorded messages for a WebSocket session.

type Recorder

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

Recorder records WebSocket messages for analysis.

func NewRecorder

func NewRecorder(maxMessages int) *Recorder

NewRecorder creates a new WebSocket recorder.

func (*Recorder) AnalyzePatterns

func (r *Recorder) AnalyzePatterns(url string) *PatternAnalysis

AnalyzePatterns analyzes message patterns in sessions.

func (*Recorder) Clear

func (r *Recorder) Clear()

Clear clears all recorded sessions.

func (*Recorder) EndSession

func (r *Recorder) EndSession(url string)

EndSession ends a WebSocket session.

func (*Recorder) ExportJSON

func (r *Recorder) ExportJSON() ([]byte, error)

ExportJSON exports all sessions as JSON.

func (*Recorder) GetActiveSessions

func (r *Recorder) GetActiveSessions() []*RecordedSession

GetActiveSessions returns all active sessions.

func (*Recorder) GetAllSessions

func (r *Recorder) GetAllSessions() []*RecordedSession

GetAllSessions returns all recorded sessions.

func (*Recorder) GetSession

func (r *Recorder) GetSession(url string) *RecordedSession

GetSession returns a recorded session.

func (*Recorder) RecordMessage

func (r *Recorder) RecordMessage(url string, direction, msgType string, data []byte)

RecordMessage records a WebSocket message.

func (*Recorder) StartSession

func (r *Recorder) StartSession(url string)

StartSession starts recording a new WebSocket session.

func (*Recorder) Stats

func (r *Recorder) Stats() RecorderStats

Stats returns recorder statistics.

type RecorderStats

type RecorderStats struct {
	TotalSessions  int `json:"total_sessions"`
	ActiveSessions int `json:"active_sessions"`
	TotalMessages  int `json:"total_messages"`
}

RecorderStats contains recorder statistics.

type WebSocketEndpoint

type WebSocketEndpoint struct {
	URL            string
	DiscoveredFrom string
	SampleMessages []WebSocketMsg
	Protocols      []string
	Timestamp      time.Time
}

WebSocketEndpoint represents a discovered WebSocket endpoint.

type WebSocketMsg

type WebSocketMsg struct {
	Direction string
	Type      string
	Data      string
	Timestamp time.Time
}

WebSocketMsg represents a WebSocket message.

Jump to

Keyboard shortcuts

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