Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) Close()
- func (c *Client) Send(channel, action string, data map[string]interface{}) <-chan error
- func (c *Client) Subscribe(channel string) (<-chan *EventOrErr, error)
- func (c *Client) SubscribeWith(params json.RawMessage) (<-chan *EventOrErr, error)
- func (c *Client) Unsubscribe(channel string)
- type Command
- type CommandIdentifier
- type Event
- type EventOrErr
- type HeaderFunc
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadySubscribed = errors.New("channel already subscribed")
ErrAlreadySubscribed is returned when the client has already subscribed to a given channel.
var ErrNoChannelName = errors.New("Subscription data must contain a channel name")
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an ActionCable websocket client.
func NewClient ¶
func NewClient(url string, connHdrFunc HeaderFunc) *Client
NewClient creates a new Client that connects to the provided url using the HTTP headers from connHdrFunc, which will be called once for each connection attempt. If connHdrFunc returns an error when called, that will cause the connection attempt to fail.
func (*Client) Close ¶
func (c *Client) Close()
Close closes any active connection on the Client and stops it from making additional connections.
func (*Client) Send ¶
Send an action on a channel. The "action" field of data will be overridden. The return channel will send an error if one is encountered, or will close if the send completes.
func (*Client) Subscribe ¶
func (c *Client) Subscribe(channel string) (<-chan *EventOrErr, error)
Subscribe establishes a subscription to a specific channel. If the channel is already subscribed, ErrAlreadySubscribed is returned. Otherwise an subscription channel will return. If the subscription is rejected at any point (including after a future reconnect), the channel will be closed. It will also be closed if Unsubscribe is called for that subscription.
The channel will receive a confirm_subscription event anytime the subscription is confirmed (including every time the client reconnects) and will receive any events sent to that channel. Events may be missed during disconnects, so a confirm_subscription event might be a good time to resynchronize state that might be stale.
func (*Client) SubscribeWith ¶
func (c *Client) SubscribeWith(params json.RawMessage) (<-chan *EventOrErr, error)
SubscribeWith subscribes to a channel giving parameters the params must contain a field "channel" containing the channe to subscribe to
func (*Client) Unsubscribe ¶
Unsubscribe stops subscribing to channel.
type Command ¶
type Command struct { Command string `json:"command"` Data json.RawMessage `json:"data,omitempty"` Identifier CommandIdentifier `json:"identifier"` // contains filtered or unexported fields }
Command is a command issued on a channel.
type CommandIdentifier ¶
type CommandIdentifier struct { // Channel is the name of the channel. Channel string RawData json.RawMessage }
CommandIdentifier identifies which Channel a Command occurs on.
func (*CommandIdentifier) MarshalJSON ¶
func (c *CommandIdentifier) MarshalJSON() ([]byte, error)
MarshalJSON encodes the CommandIdentifier to JSON.
func (*CommandIdentifier) UnmarshalJSON ¶
func (c *CommandIdentifier) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the CommandIdentifier from JSON.
type Event ¶
type Event struct { Type string `json:"type"` Message json.RawMessage `json:"message"` Data json.RawMessage `json:"data"` Identifier *CommandIdentifier `json:"identifier"` }
Event is a subscription event received on a channel.
type EventOrErr ¶
EventOrErr is an Event or error returned on a subscription channel.
type HeaderFunc ¶
HeaderFunc is a function that returns HTTP headers or an error.