Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotConnected is returned when Call is made while the relay is reconnecting. ErrNotConnected = errors.New("relay is not connected") ErrConnectionLost = errors.New("relay connection lost") ErrClosed = errors.New("relay client is closed") ErrPayloadTooLarge = errors.New("relay payload too large") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client maintains an outbound connection to one relay room.
func NewClient ¶
func NewClient(relayURL, relayToken, pairingToken, network string, options ...ClientOption) *Client
NewClient creates a relay client. relayToken is used only to open the relay WebSocket; pairingToken is carried on outgoing request frames as this network's pairing credential. Run must be started before calls can use it.
func (*Client) Call ¶
func (c *Client) Call( ctx context.Context, method string, path string, body []byte, ) (status int, respBody []byte, err error)
Call sends a request through the current relay connection and waits for its response. Calls made while the client is reconnecting return ErrNotConnected rather than waiting for a future connection.
func (*Client) Close ¶
func (c *Client) Close()
Close stops Run, closes the live WebSocket connection, and unblocks pending calls.
func (*Client) Run ¶
Run keeps a connection to the relay open until ctx is canceled or Close is called.
func (*Client) SetHandler ¶
SetHandler serves requests received from the relay peer through handler. The originator pairing credential is taken from each inbound frame. It may be called after NewClient to resolve startup ordering with the application's HTTP handler.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a relay Client.
func WithInboundHandler ¶
func WithInboundHandler(handler http.Handler) ClientOption
WithInboundHandler serves requests sent by the relay peer through handler. Each synthetic HTTP request carries the originator pairing credential from its relay frame, not either of this client's credentials. Handlers run on bounded per-request goroutines and may call Call and its helpers through this Client. A handler must not synchronously call this Client's Close: Close waits for in-flight handlers, including the caller, to return.
type InboundHandler ¶
type InboundHandler struct {
// contains filtered or unexported fields
}
InboundHandler serves relay requests through an injected HTTP handler.
func NewInboundHandler ¶
func NewInboundHandler(handler http.Handler) *InboundHandler
NewInboundHandler creates an inbound relay request handler. Each synthetic request receives the originator credential carried by its relay frame.