websocket

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID           string
	Connection   *websocket.Conn
	UserID       string
	Subscribed   map[EventType]bool
	Send         chan Event
	LastActivity time.Time
	// contains filtered or unexported fields
}

Client represents a connected websocket client

func (*Client) ReadPump

func (client *Client) ReadPump(manager *Manager)

ReadPump pumps messages from the websocket connection to the manager

func (*Client) WritePump

func (client *Client) WritePump()

WritePump pumps messages from the manager to the websocket connection

type Event

type Event struct {
	Type      EventType   `json:"type"`
	Timestamp time.Time   `json:"timestamp"`
	ID        string      `json:"id"`
	Data      interface{} `json:"data"`
}

Event represents a message sent over the websocket

type EventType

type EventType string

EventType represents the type of event being sent over the websocket

const (
	EventTypePing          EventType = "ping"
	EventTypeServiceStatus EventType = "service_status"
	EventTypeTransaction   EventType = "transaction"
	EventTypePriceFeed     EventType = "price_feed"
	EventTypeTrigger       EventType = "trigger"
	EventTypeFunction      EventType = "function"
	EventTypeRandomNumber  EventType = "random_number"
	EventTypeOracle        EventType = "oracle"
	EventTypeNotification  EventType = "notification"
	EventTypeError         EventType = "error"
)

Event types

type Manager

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

Manager handles websocket connections and broadcasts

func NewManager

func NewManager() *Manager

NewManager creates a new websocket manager

func (*Manager) Authenticate

func (m *Manager) Authenticate(client *Client, userID string)

Authenticate marks a client as authenticated

func (*Manager) Broadcast

func (m *Manager) Broadcast(eventType EventType, data interface{})

Broadcast sends an event to all clients

func (*Manager) GetConnectedClientsCount

func (m *Manager) GetConnectedClientsCount() int

GetConnectedClientsCount returns the number of currently connected clients

func (*Manager) Register

func (m *Manager) Register(client *Client)

Register adds a new client

func (*Manager) SendToUser

func (m *Manager) SendToUser(userID string, eventType EventType, data interface{})

SendToUser sends an event to a specific user

func (*Manager) Start

func (m *Manager) Start()

Start begins the manager's goroutines

func (*Manager) Stop

func (m *Manager) Stop()

Stop closes all connections and stops the manager

func (*Manager) Unregister

func (m *Manager) Unregister(client *Client)

Unregister removes a client

Jump to

Keyboard shortcuts

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