Help us shape the future of Go! Take the 2026 Go Developer Survey

broadcasting

package
v1.20.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelBaseName

func ChannelBaseName(name string) string

func IsPresenceChannel

func IsPresenceChannel(name string) bool

func IsPrivateChannel

func IsPrivateChannel(name string) bool

func PresenceChannel

func PresenceChannel(name string) string

func PrivateChannel

func PrivateChannel(name string) string

func PublicChannel

func PublicChannel(name string) string

PublicChannel returns the channel name unchanged. It is kept as a semantic wrapper for readability and API stability, mirroring PrivateChannel and PresenceChannel (and Laravel's channel constructors): callers write broadcasting.PublicChannel("orders") instead of a bare "orders" string.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(configFacade contractsconfig.Config, log log.Log, queue queue.Queue, app foundation.Application) *Application

func (*Application) Authenticate

func (*Application) Channel

func (a *Application) Channel(pattern string, callback broadcasting.ChannelAuthFunc)

Channel registers an authorization callback for a channel pattern.

Example:

// Simple channel
facades.Broadcast().Channel("orders", func(ctx context.Context, userID any, channelName string, params map[string]string) (bool, any) {
	return true, nil
})

// Channel with route params
facades.Broadcast().Channel("orders.{orderId}", func(ctx context.Context, userID any, channelName string, params map[string]string) (bool, any) {
	// params["orderId"] contains the matched value
	order := findOrder(ctx, params["orderId"])
	return order.UserID == userID, nil
})

// Presence channel returning custom user info
facades.Broadcast().Channel("chat", func(ctx context.Context, userID any, channelName string, params map[string]string) (bool, any) {
	return true, map[string]any{"id": userID, "name": "Alice"}
})

func (*Application) Dispatch

func (a *Application) Dispatch(ctx context.Context, event broadcasting.ShouldBroadcast) error

Dispatch broadcasts an event. In the synchronous path (events implementing ShouldBroadcastNow with BroadcastNow()==true, or when no queue is available) ctx bounds the driver call. In the asynchronous path ctx is not propagated across the queue boundary; the worker synthesizes a new context, optionally bounded by ShouldBroadcastWithTimeout. The retry policy (BroadcastTries/BroadcastBackoff) is captured from the event's optional interfaces and enforced by the BroadcastJob's ShouldRetry at execution time.

type BroadcastJob

type BroadcastJob struct {
	// contains filtered or unexported fields
}

func (*BroadcastJob) Handle

func (j *BroadcastJob) Handle(args ...any) error

Handle executes the queued broadcast. Retries are governed by ShouldRetry using the event's BroadcastTries/BroadcastBackoff captured at dispatch time. Broadcasts without BroadcastTries defer to the queue worker's tries config. A fresh context is synthesized (the dispatch-time ctx cannot cross the queue boundary); if the originating event implemented ShouldBroadcastWithTimeout the worker context is bounded accordingly, which the Pusher driver honours via WithContext.

func (*BroadcastJob) ShouldRetry

func (j *BroadcastJob) ShouldRetry(err error, attempt, maxTries int) (retryable bool, delay time.Duration)

ShouldRetry controls retries for the queued broadcast. A BroadcastTries-declaring event wins; without one (Tries <= 0) the queue worker's maxTries governs. With a cap it retries while attempt < Tries using the configured per-attempt Backoff (last value repeats); backoff applies to worker-driven retries too. item == nil (cleared on success/invalid payload) is the safe single-shot fallback — never the worker's tries, so an interleaved concurrent task can't inherit another task's policy.

func (*BroadcastJob) Signature

func (j *BroadcastJob) Signature() string

type Config

type Config struct {
	Default     string                                   `json:"default"`
	Connections map[string]broadcasting.ConnectionConfig `json:"connections"`
	Auth        broadcasting.AuthConfig                  `json:"auth"`
}

func NewConfig

func NewConfig(cfg contractsconfig.Config) (*Config, error)

func (*Config) Connection

func (c *Config) Connection(name string) (broadcasting.ConnectionConfig, error)

func (*Config) DefaultConnection

func (c *Config) DefaultConnection() string

type ServiceProvider

type ServiceProvider struct{}

func (*ServiceProvider) Boot

func (r *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (r *ServiceProvider) Register(app foundation.Application)

func (*ServiceProvider) Relationship

func (r *ServiceProvider) Relationship() binding.Relationship

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL