Files
OpenFlare/backend/openflare/plugins/relay/wsclient/client.go
T

44 lines
1.2 KiB
Go

// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
// Package wsclient provides a WebSocket client for relay control-plane communication.
package wsclient
import (
"context"
"time"
edgews "Wavelet/openflare/share/edge/wsclient"
)
// WSMessage is a WebSocket message exchanged with the control plane.
type WSMessage = edgews.WSMessage
// MessageHandler processes incoming WebSocket messages.
type MessageHandler = edgews.MessageHandler
// Connection represents an active WebSocket connection.
type Connection = edgews.Connection
// Client connects to the relay WebSocket endpoint on the control plane.
type Client struct {
inner *edgews.Client
}
// New creates a WebSocket client for the relay control-plane endpoint.
func New(baseURL, token string, timeout time.Duration) *Client {
return &Client{
inner: edgews.New(edgews.PresetRelay, baseURL, token, timeout),
}
}
// SetToken updates the authentication token used for the WebSocket connection.
func (c *Client) SetToken(token string) {
c.inner.SetToken(token)
}
// Connect establishes a WebSocket connection to the control plane.
func (c *Client) Connect(ctx context.Context) (*Connection, error) {
return c.inner.Connect(ctx)
}