Documentation
¶
Index ¶
- type Client
- func (c *Client) Connect() error
- func (c *Client) Disconnect() error
- func (c *Client) EventHandlers() map[string][]EventHandler
- func (c *Client) IsConnected() bool
- func (c *Client) Listen() error
- func (c *Client) Off(eventType string, handler EventHandler)
- func (c *Client) On(eventType string, handler EventHandler)
- func (c *Client) SetCustomWebSocketURL(url string)
- func (c *Client) SetDeviceProvider(provider DeviceProvider)
- func (c *Client) StopListening() error
- type Config
- type DeviceProvider
- type Event
- type EventHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Mercury API client for websocket communication
func (*Client) Disconnect ¶
Disconnect closes the websocket connection
func (*Client) EventHandlers ¶
func (c *Client) EventHandlers() map[string][]EventHandler
EventHandlers returns a copy of the event handlers map (for testing)
func (*Client) IsConnected ¶
IsConnected returns whether the client is connected to the Mercury service
func (*Client) Off ¶
func (c *Client) Off(eventType string, handler EventHandler)
Off removes an event handler for a specific event type
func (*Client) On ¶
func (c *Client) On(eventType string, handler EventHandler)
On registers an event handler for a specific event type
func (*Client) SetCustomWebSocketURL ¶
SetCustomWebSocketURL sets a custom WebSocket URL for Mercury connection
func (*Client) SetDeviceProvider ¶
func (c *Client) SetDeviceProvider(provider DeviceProvider)
SetDeviceProvider sets a device provider to use for getting websocket URLs
func (*Client) StopListening ¶
StopListening is an alias for Disconnect, maintained for compatibility with JS SDK
type Config ¶
type Config struct {
ForceCloseDelay time.Duration // Delay after which to force close a websocket connection if no close event is received
PingInterval time.Duration // Interval between ping messages
PongTimeout time.Duration // Timeout for receiving a pong response
BackoffTimeMax time.Duration // Maximum time between connection attempts
BackoffTimeReset time.Duration // Initial time before the first retry
MaxRetries int // Number of times to retry before giving up
InitialConnectionMaxRetries int // Number of times to retry before giving up on the initial connection
}
Config holds the configuration for the Mercury plugin
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default configuration for the Mercury plugin
type DeviceProvider ¶
DeviceProvider is an interface for getting the websocket URL from a device
type Event ¶
type Event struct {
// JSON fields from the websocket message
ID string `json:"id,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
TrackingID string `json:"trackingId,omitempty"`
AlertType string `json:"alertType,omitempty"`
SequenceNumber int64 `json:"sequenceNumber,omitempty"`
FilterMessage bool `json:"filterMessage,omitempty"`
WsWriteTimestamp int64 `json:"wsWriteTimestamp,omitempty"`
Headers map[string]interface{} `json:"headers,omitempty"`
// Derived fields populated during processing
EventType string `json:"-"` // Populated from data.eventType
ActivityType string `json:"-"` // Populated from data.activity.verb
WebSocketError string `json:"-"` // Internal field for connection errors
ResourceType string `json:"-"` // Type of resource in the event
ActorID string `json:"-"` // ID of the actor who performed the activity
OrgID string `json:"-"` // Organization ID associated with the activity
Resource map[string]interface{} `json:"-"` // Resource data from the event
}
Event represents a Mercury websocket event
type EventHandler ¶
type EventHandler func(event *Event)
EventHandler is a function that handles a websocket event