mercury

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MPL-2.0 Imports: 8 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 {
	// contains filtered or unexported fields
}

Client is the Mercury API client for websocket communication

func New

func New(webexClient *webexsdk.Client, config *Config) *Client

New creates a new Mercury plugin

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes a websocket connection to the Mercury service

func (*Client) Disconnect

func (c *Client) Disconnect() error

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

func (c *Client) IsConnected() bool

IsConnected returns whether the client is connected to the Mercury service

func (*Client) Listen

func (c *Client) Listen() error

Listen is an alias for Connect, maintained for compatibility with JS SDK

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

func (c *Client) SetCustomWebSocketURL(url string)

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

func (c *Client) StopListening() error

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

type DeviceProvider interface {
	Register() error
	GetWebSocketURL() (string, error)
}

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

Jump to

Keyboard shortcuts

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