ws

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ws implements the WebSocket client for Flashduty communication.

Index

Constants

View Source
const (

	// DefaultMaxReconnectAttempts is the default max reconnect attempts (0 = unlimited).
	DefaultMaxReconnectAttempts = 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the WebSocket client for Flashduty communication.

func NewClient

func NewClient(token, apiURL, workspaceRoot string, handler MessageHandler, version string, maxAttempts int) *Client

NewClient creates a new WebSocket client. maxAttempts controls reconnection: 0 = unlimited, >0 = max attempts before giving up.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes a WebSocket connection to Flashduty.

func (*Client) EnvironmentID added in v0.0.6

func (c *Client) EnvironmentID() string

EnvironmentID returns the environment ID assigned by Flashduty.

func (*Client) Labels

func (c *Client) Labels() []string

Labels returns the environment labels from welcome message.

func (*Client) Name

func (c *Client) Name() string

Name returns the environment name from welcome message.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run starts the client's read/write loops.

func (*Client) RunWithReconnect

func (c *Client) RunWithReconnect(ctx context.Context) error

RunWithReconnect runs the client with automatic reconnection.

func (*Client) Send

func (c *Client) Send(msg *protocol.Message) error

Send sends a message to Flashduty.

func (*Client) SendPayload

func (c *Client) SendPayload(msgType protocol.MessageType, payload any) error

SendPayload sends a message with the given type and payload.

func (*Client) SetOnConnected added in v0.0.14

func (c *Client) SetOnConnected(f func())

SetOnConnected registers a callback fired once after each successful welcome handshake.

type Handler

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

Handler handles incoming WebSocket messages.

func NewHandler

func NewHandler(ws *environment.Environment) *Handler

NewHandler creates a new message handler.

func (*Handler) CancelAllTasks

func (h *Handler) CancelAllTasks()

CancelAllTasks cancels all running tasks.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, msg *protocol.Message) error

Handle handles an incoming message.

func (*Handler) RunningTaskCount

func (h *Handler) RunningTaskCount() int

RunningTaskCount returns the number of running tasks.

func (*Handler) SetClient

func (h *Handler) SetClient(client *Client)

SetClient sets the WebSocket client for sending responses.

func (*Handler) SetDisableAutoUpdate added in v0.0.14

func (h *Handler) SetDisableAutoUpdate(disabled bool)

SetDisableAutoUpdate makes the handler ignore all upgrade advertisements.

func (*Handler) WaitForTasks

func (h *Handler) WaitForTasks(timeout time.Duration) bool

WaitForTasks waits for all running tasks to complete with a timeout. Returns true if all tasks completed, false if timeout occurred.

type MessageHandler

type MessageHandler func(ctx context.Context, msg *protocol.Message) error

MessageHandler handles incoming messages from Flashduty.

Jump to

Keyboard shortcuts

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