Documentation
¶
Index ¶
- func Authorize(pattern string, fn AuthorizeFunc)
- func Broadcast(channel string, payload any)
- func BroadcastExcept(channel string, payload any, excludeUIDs ...string)
- func CheckChannel(ctx *reqctx.Context, channel string) bool
- func GetSubscribers(channel string) []string
- func OnBroadcast(fn BroadcastHook)
- func OnConnect(fn ConnectHook)
- func OnDisconnect(fn DisconnectHook)
- func OnSubscribe(fn SubscribeHook)
- func OnUnsubscribe(fn UnsubscribeHook)
- type AuthorizeFunc
- type BroadcastHook
- type Client
- type Config
- type ConnectHook
- type DisconnectHook
- type Plugin
- type RedisTransport
- type RedisTransportConfig
- type Store
- func (s *Store) Connect() (string, *Client)
- func (s *Store) DeliverToChannel(channel string, payload any, excludeUIDs ...string)
- func (s *Store) Disconnect(uid string)
- func (s *Store) SendToChannel(channel string, payload any, excludeUIDs ...string)
- func (s *Store) Subscribe(channel, uid string)
- func (s *Store) Subscribers(channel string) []string
- func (s *Store) Unsubscribe(channel, uid string)
- type SubscribeHook
- type Transport
- type UnsubscribeHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authorize ¶
func Authorize(pattern string, fn AuthorizeFunc)
Authorize registers an authorization callback for channels matching pattern. Pattern uses :param syntax (e.g. "users/:id", "chats/:chatId/messages"). Return true to allow, false to deny. Channels without a matching rule are public.
func Broadcast ¶
Broadcast sends payload to all subscribers of channel. With transport configured, publishes to Redis so all instances deliver.
func BroadcastExcept ¶
BroadcastExcept sends payload to all subscribers except the given UIDs.
func CheckChannel ¶
CheckChannel returns true if the client may subscribe to channel.
func GetSubscribers ¶
GetSubscribers returns UIDs subscribed to channel (AdonisJS getSubscribersFor).
func OnBroadcast ¶
func OnBroadcast(fn BroadcastHook)
OnBroadcast registers a callback when a message is broadcast.
func OnConnect ¶
func OnConnect(fn ConnectHook)
OnConnect registers a callback for new SSE connections.
func OnDisconnect ¶
func OnDisconnect(fn DisconnectHook)
OnDisconnect registers a callback when a client disconnects.
func OnSubscribe ¶
func OnSubscribe(fn SubscribeHook)
OnSubscribe registers a callback when a client subscribes to a channel.
func OnUnsubscribe ¶
func OnUnsubscribe(fn UnsubscribeHook)
OnUnsubscribe registers a callback when a client unsubscribes.
Types ¶
type AuthorizeFunc ¶
AuthorizeFunc returns true to allow subscription, false to deny.
type BroadcastHook ¶
type Config ¶
type Config struct {
Path string // route prefix, default __transmit
PingInterval string // e.g. "30s", "1m", empty to disable
Middleware []router.Middleware // optional middleware for all transmit routes (e.g. auth)
Transport Transport // optional; Redis for multi-instance sync
}
Config holds Transmit configuration.
type ConnectHook ¶
type ConnectHook func(uid string)
type DisconnectHook ¶
type DisconnectHook func(uid string)
type Plugin ¶
type Plugin struct {
nimbus.BasePlugin
// contains filtered or unexported fields
}
Plugin integrates SSE into Nimbus.
func (*Plugin) RegisterRoutes ¶
RegisterRoutes mounts SSE routes.
type RedisTransport ¶
type RedisTransport struct {
// contains filtered or unexported fields
}
RedisTransport uses Redis Pub/Sub for multi-instance sync.
func NewRedisTransport ¶
func NewRedisTransport(cfg RedisTransportConfig) (*RedisTransport, error)
NewRedisTransport creates a Redis transport.
func (*RedisTransport) Close ¶
func (t *RedisTransport) Close() error
Close closes the pubsub and client.
type RedisTransportConfig ¶
type RedisTransportConfig struct {
URL string // redis://localhost:6379
Channel string // default transmit::broadcast
}
RedisTransportConfig configures the Redis transport.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds connections and channel subscriptions.
func (*Store) DeliverToChannel ¶
DeliverToChannel delivers to local subscribers without emitting OnBroadcast. Used by transport when relaying from other instances.
func (*Store) Disconnect ¶
Disconnect removes a client and unsubscribes from all channels.
func (*Store) SendToChannel ¶
SendToChannel sends payload to all subscribers of channel, optionally excluding UIDs. Emits OnBroadcast. Use DeliverToChannel when relaying from transport (no emit).
func (*Store) Subscribers ¶
Subscribers returns UIDs subscribed to channel.
func (*Store) Unsubscribe ¶
Unsubscribe removes uid from channel.
type SubscribeHook ¶
type SubscribeHook func(uid, channel string)
type Transport ¶
type Transport interface {
// Publish sends channel+payload to all instances (including self via subscription).
Publish(ctx context.Context, channel string, payload any, excludeUIDs []string) error
// Subscribe starts receiving published messages. Call from Boot. Blocking.
Subscribe(ctx context.Context, onMessage func(channel string, payload any, excludeUIDs []string)) error
// Close stops the transport.
Close() error
}
Transport synchronizes broadcasts across server instances.
type UnsubscribeHook ¶
type UnsubscribeHook func(uid, channel string)