Documentation ¶
Overview ¶
Package actioncable provides a server-side implementation of the Rails Action Cable protocol (https://docs.anycable.io/misc/action_cable_protocol)
Index ¶
Constants ¶
const ( ActionCableV1JSONSubprotocol = "actioncable-v1-json" ActionCableV1MsgpackSubprotocol = "actioncable-v1-msgpack" )
Variables ¶
This section is empty.
Functions ¶
func SupportedSubprotocols ¶ added in v0.5.0
func SupportedSubprotocols() []string
Types ¶
type Cancellers ¶
type Cancellers struct {
// contains filtered or unexported fields
}
Cancellers associates IDs with context cancellation functions so that those functions can be run by ID.
func NewCancellers ¶
func NewCancellers() *Cancellers
NewCancellers creates a new instance of Cancellers.
func (*Cancellers) Add ¶
func (c *Cancellers) Add(id string, canceller context.CancelFunc)
Add records an association between the ID and the context cancellation function.
func (*Cancellers) Cancel ¶
func (c *Cancellers) Cancel(id string)
Cancel runs and then forgets all context cancellation functions associated with the ID.
type Channel ¶
type Channel interface { // Subscribe handles an Action Cable subscribe command from the client with the provided // [Subscription]. Subscribe(ctx context.Context, sub *Subscription) error // Perform handles an Action Cable action command from the client. Perform(data string) error }
Channel represents a server-side Action Cable channel.
type ChannelDispatcher ¶ added in v0.5.0
type ChannelDispatcher struct {
// contains filtered or unexported fields
}
ChannelDispatcher manages channels, channel subscriptions, and channel actions.
func NewChannelDispatcher ¶ added in v0.5.0
func NewChannelDispatcher( factories map[string]ChannelFactory, channels map[string]Channel, checkers ...IdentifierChecker, ) *ChannelDispatcher
func (*ChannelDispatcher) HandleAction ¶ added in v0.5.0
func (d *ChannelDispatcher) HandleAction(ctx context.Context, identifier, data string) error
HandleAction dispatches Action Cable action messages to the appropriate channels.
func (*ChannelDispatcher) HandleSubscription ¶ added in v0.5.0
func (d *ChannelDispatcher) HandleSubscription(ctx context.Context, sub *Subscription) error
HandleSubscription associates the subscription to its corresponding channel and calls the channel's Subscribe method, first instantiating the channel if necessary.
type ChannelFactory ¶
ChannelFactory creates a Channel from an Action Cable subscription identifier.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a server-side Action Cable connection.
func Upgrade ¶
Upgrade upgrades the WebSocket connection to an Action Cable connection. The WebSocket connection should not be written to or read from if the upgrade completes successfully.
type ConnOption ¶
type ConnOption func(conn *Conn)
ConnOption modifies a Conn. For use with Upgrade.
func WithErrorSanitizer ¶
func WithErrorSanitizer(f ErrorSanitizer) ConnOption
WithErrorSanitizer creates a ConnOption to set the Conn's error sanitizer, which processes errors to avoid leaking sensitive information in server logs.
type DataPayload ¶ added in v0.5.0
type ErrorSanitizer ¶
type Handler ¶ added in v0.5.0
type Handler interface { HandleSubscription(ctx context.Context, sub *Subscription) error HandleAction(ctx context.Context, identifier, data string) error }
Handler handles Action Cable channel subscription and channel action messages.
type IdentifierChecker ¶
IdentifierChecker returns an error if the provided identifier is invalid.
func WithCSRFTokenChecker ¶
func WithCSRFTokenChecker(checker func(token string) error) IdentifierChecker
WithCSRFTokenChecker creates an IdentifierChecker which extracts a CSRF token from the Action Cable subscription identifier and checks it using the checker callback function.
type Signer ¶ added in v0.5.0
type Signer struct {
Config SignerConfig
}
Signer creates and verifies subscription identifier names with an HMAC.
func NewSigner ¶ added in v0.5.0
func NewSigner(config SignerConfig) Signer
NewSigner creates a new instance of Signer.
func (Signer) Check ¶ added in v0.5.0
Check parses the subscription identifier's name field and checks if it matches the HMAC in the subscription identiier's hash field. Note that these fields are not part of the Action Cable specification; rather, they're conventions inherited from the Rails implementation of integration between Turbo Streams and Action Cable.
type SignerConfig ¶ added in v0.5.0
type SignerConfig struct {
HashKey []byte
}
func GetSignerConfig ¶ added in v0.5.0
func GetSignerConfig() (c SignerConfig, err error)
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents the server end of an Action Cable subscription.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close releases any resources associated with the subscription. The Subscription should not be used after it's closed.
func (*Subscription) Identifier ¶
func (s *Subscription) Identifier() string
Identifier returns the Action Cable subscription identifier.