events

package
v0.0.0-...-727718e Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PubSub: Room events — all subscribers in room get published events.
	// Format: room:{roomId}:events
	RoomEventPattern = "room:%s:events"

	// PubSub: Entity updates — broadcast to all subscribers.
	// Format: entity:updates
	EntityUpdateChannel = "entity:updates"

	// Stream: Room movement sync — stateful (replay last N messages).
	// Format: room:{roomId}:movements
	// Each message: {"player_id":"p1","x":100,"y":200,"ts":1234567890}
	RoomMovementPattern = "room:%s:movements"

	// List (queue): Mutations from WS server → fookie-server processes.
	// Format: mutations:queue
	// Each item: JSON-encoded GraphQL mutation request
	MutationsQueue = "mutations:queue"

	// PubSub: Mutation results — WS server listens for responses.
	// Format: mutation:result:{requestId}
	MutationResultPattern = "mutation:result:%s"
)

Variables

This section is empty.

Functions

func ChannelName

func ChannelName(roomID string) string

ChannelName builds a room event channel name.

func ResultChannel

func ResultChannel(requestID string) string

ResultChannel builds a mutation result channel name.

func StreamName

func StreamName(roomID string) string

StreamName builds a room movement stream name.

Types

type Bus

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

func NewBus

func NewBus() *Bus

func (*Bus) Publish

func (b *Bus) Publish(ev Event)

func (*Bus) PublishCRUD

func (b *Bus) PublishCRUD(op, model, id string, payload map[string]interface{})

func (*Bus) Subscribe

func (b *Bus) Subscribe() (<-chan Event, func())

type Event

type Event struct {
	Op                Op                     `json:"op"`
	Model             string                 `json:"model"`
	ID                string                 `json:"id"`
	Payload           map[string]interface{} `json:"payload"`
	Timestamp         time.Time              `json:"ts"`
	CachedPayloadJSON string                 `json:"-"` // Pre-computed for GraphQL subscriptions
	// contains filtered or unexported fields
}

type Op

type Op string
const (
	OpCreate Op = "created"
	OpRead   Op = "read"
	OpUpdate Op = "updated"
	OpDelete Op = "deleted"
)

type RoomBus

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

func NewRoomBus

func NewRoomBus() *RoomBus

func NewRoomBusWithRedis

func NewRoomBusWithRedis(rdb *redis.Client) *RoomBus

func (*RoomBus) Publish

func (rb *RoomBus) Publish(roomID string, msg map[string]interface{})

Publish sends to local subscribers and (if Redis configured) to all other server instances.

func (*RoomBus) RoomCount

func (rb *RoomBus) RoomCount() int

RoomCount returns the number of active rooms with subscribers (for metrics).

func (*RoomBus) StartRedisSubscriber

func (rb *RoomBus) StartRedisSubscriber(ctx context.Context)

StartRedisSubscriber subscribes to all room channels on Redis and forwards incoming messages to local subscribers. Call in a goroutine.

func (*RoomBus) Subscribe

func (rb *RoomBus) Subscribe(roomID string) (ch chan interface{}, cancel func())

func (*RoomBus) SubscriberCount

func (rb *RoomBus) SubscriberCount(roomID string) int

SubscriberCount returns the number of active subscribers for a room (for metrics).

Jump to

Keyboard shortcuts

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