events

package
v0.0.0-...-6d36bb5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDispatchKey

func CreateDispatchKey(t EventType, condition EventCondition) string

Types

type AckPayload

type AckPayload struct {
	Command string          `json:"command"`
	Data    json.RawMessage `json:"data"`
}

type BridgedCommandBody

type BridgedCommandBody struct {
	Platform    structures.UserConnectionPlatform `json:"platform"`
	Identifiers []string                          `json:"identifiers"`
	Kinds       []structures.CosmeticKind         `json:"kinds"`
}

type ChangeField

type ChangeField struct {
	Key      string          `json:"key"`
	Index    *int32          `json:"index"`
	Nested   bool            `json:"nested,omitempty"`
	Type     ChangeFieldType `json:"type"`
	OldValue any             `json:"old_value,omitempty"`
	Value    any             `json:"value"`
}

func (ChangeField) String

func (cf ChangeField) String() string

type ChangeFieldType

type ChangeFieldType string
const (
	ChangeFieldTypeString ChangeFieldType = "string"
	ChangeFieldTypeNumber ChangeFieldType = "number"
	ChangeFieldTypeBool   ChangeFieldType = "bool"
	ChangeFieldTypeObject ChangeFieldType = "object"
)

type ChangeMap

type ChangeMap struct {
	// The object's ID
	ID primitive.ObjectID `json:"id"`
	// The type of the object
	Kind structures.ObjectKind `json:"kind"`
	// Contextual is whether or not this event is only relating
	// to the specific source conditions and not indicative of a
	// genuine creation, deletion, or update to the object
	Contextual bool `json:"contextual,omitempty"`
	// The user who made changes to the object
	Actor model.UserPartialModel `json:"actor,omitempty"`
	// A list of added fields
	Added []ChangeField `json:"added,omitempty"`
	// A list of updated fields
	Updated []ChangeField `json:"updated,omitempty"`
	// A list of removed fields
	Removed []ChangeField `json:"removed,omitempty"`
	// A list of items pushed to an array
	Pushed []ChangeField `json:"pushed,omitempty"`
	// A list of items pulled from an array
	Pulled []ChangeField `json:"pulled,omitempty"`
	// A full object. Only available during a "create" event
	Object json.RawMessage `json:"object,omitempty"`
}

type CloseCode

type CloseCode uint16
const (
	CloseCodeServerError           CloseCode = 4000 // an error occured on the server's end
	CloseCodeUnknownOperation      CloseCode = 4001 // the client sent an unexpected opcode
	CloseCodeInvalidPayload        CloseCode = 4002 // the client sent a payload that couldn't be decoded
	CloseCodeAuthFailure           CloseCode = 4003 // the client unsucessfully tried to identify
	CloseCodeAlreadyIdentified     CloseCode = 4004 // the client wanted to identify again
	CloseCodeRateLimit             CloseCode = 4005 // the client is being rate-limited
	CloseCodeRestart               CloseCode = 4006 // the server is restarting and the client should reconnect
	CloseCodeMaintenance           CloseCode = 4007 // the server is in maintenance mode and not accepting connections
	CloseCodeTimeout               CloseCode = 4008 // the client was idle for too long
	CloseCodeAlreadySubscribed     CloseCode = 4009 // the client tried to subscribe to an event twice
	CloseCodeNotSubscribed         CloseCode = 4010 // the client tried to unsubscribe from an event they weren't subscribing to
	CloseCodeInsufficientPrivilege CloseCode = 4011 // the client did something that they did not have permission for
	CloseCodeReconnect             CloseCode = 4012 // the client should reconnect
)

func (CloseCode) String

func (c CloseCode) String() string

type DispatchOptions

type DispatchOptions struct {
	Delay         time.Duration
	Whisper       string
	Effect        *SessionEffect
	DisableDedupe bool
}

type DispatchPayload

type DispatchPayload struct {
	Type EventType `json:"type"`
	// Detailed changes to an object
	Body ChangeMap `json:"body"`
	// Hash is a hash of the target object, used for deduping
	Hash *uint32 `json:"hash,omitempty"`
	// A list of effects to apply to the session when this dispatch is received
	Effect *SessionEffect `json:"effect,omitempty"`
	// A list of subscriptions that match this dispatch
	Matches []uint32 `json:"matches,omitempty"`
	// A list of conditions where at least one must have all its fields match a subscription in order for this dispatch to be delivered
	Conditions []EventCondition `json:"condition,omitempty"`
	// This dispatch is a whisper to a specific session, usually as a response to a command
	Whisper string `json:"whisper,omitempty"`
}

type EmptyObject

type EmptyObject = struct{}

type EndOfStreamPayload

type EndOfStreamPayload struct {
	Code    CloseCode `json:"code"`
	Message string    `json:"message"`
}

type ErrorPayload

type ErrorPayload struct {
	Message       string         `json:"message"`
	MessageLocale string         `json:"message_locale,omitempty"`
	Fields        map[string]any `json:"fields"`
}

type EventCondition

type EventCondition map[string]string

func (EventCondition) Match

func (evc EventCondition) Match(other EventCondition) bool

func (EventCondition) Set

func (evc EventCondition) Set(key string, value string) EventCondition

func (EventCondition) SetObjectID

func (evc EventCondition) SetObjectID(id primitive.ObjectID) EventCondition

type EventType

type EventType string
const (
	EventTypeAnySystem          EventType = "system.*"
	EventTypeSystemAnnouncement EventType = "system.announcement"

	EventTypeAnyEmote    EventType = "emote.*"
	EventTypeCreateEmote EventType = "emote.create"
	EventTypeUpdateEmote EventType = "emote.update"
	EventTypeDeleteEmote EventType = "emote.delete"

	EventTypeAnyEmoteSet    EventType = "emote_set.*"
	EventTypeCreateEmoteSet EventType = "emote_set.create"
	EventTypeUpdateEmoteSet EventType = "emote_set.update"
	EventTypeDeleteEmoteSet EventType = "emote_set.delete"

	EventTypeAnyUser    EventType = "user.*"
	EventTypeCreateUser EventType = "user.create"
	EventTypeUpdateUser EventType = "user.update"
	EventTypeDeleteUser EventType = "user.delete"

	EventTypeAnyEntitlement    EventType = "entitlement.*"
	EventTypeCreateEntitlement EventType = "entitlement.create"
	EventTypeUpdateEntitlement EventType = "entitlement.update"
	EventTypeDeleteEntitlement EventType = "entitlement.delete"

	EventTypeAnyCosmetic    EventType = "cosmetic.*"
	EventTypeCreateCosmetic EventType = "cosmetic.create"
	EventTypeUpdateCosmetic EventType = "cosmetic.update"
	EventTypeDeleteCosmetic EventType = "cosmetic.delete"

	EventTypeWhisper EventType = "whisper.self"
)

func (EventType) ObjectName

func (et EventType) ObjectName() string

func (EventType) Split

func (et EventType) Split() []string

type EventsInst

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

func (*EventsInst) Dispatch

func (inst *EventsInst) Dispatch(t EventType, cm ChangeMap, cond ...EventCondition)

func (*EventsInst) DispatchWithEffect

func (inst *EventsInst) DispatchWithEffect(t EventType, cm ChangeMap, opt DispatchOptions, cond ...EventCondition) Message[DispatchPayload]

type HeartbeatPayload

type HeartbeatPayload struct {
	Count uint64 `json:"count"`
}

type HelloPayload

type HelloPayload struct {
	HeartbeatInterval uint32                   `json:"heartbeat_interval"`
	SessionID         string                   `json:"session_id"`
	SubscriptionLimit int32                    `json:"subscription_limit"`
	Actor             *primitive.ObjectID      `json:"actor,omitempty"`
	Instance          HelloPayloadInstanceInfo `json:"instance,omitempty"`
}

type HelloPayloadInstanceInfo

type HelloPayloadInstanceInfo struct {
	Name       string `json:"name"`
	Population int32  `json:"population"`
}

type Instance

type Instance interface {
	Dispatch(t EventType, cm ChangeMap, cond ...EventCondition)
	DispatchWithEffect(t EventType, cm ChangeMap, opt DispatchOptions, cond ...EventCondition) Message[DispatchPayload]
}

func NewPublisher

func NewPublisher(nc *nats.Conn, subject string) Instance

type Message

type Message[D AnyPayload] struct {
	Op        Opcode `json:"op"`
	Timestamp int64  `json:"t"`
	Data      D      `json:"d"`
	Sequence  uint64 `json:"s,omitempty"`
}

func ConvertMessage

func ConvertMessage[D AnyPayload](c Message[json.RawMessage]) (Message[D], error)

func NewMessage

func NewMessage[D AnyPayload](op Opcode, data D) Message[D]

func (Message[D]) ToRaw

func (e Message[D]) ToRaw() Message[json.RawMessage]

type Opcode

type Opcode uint8
const (
	// Default ops (0-32)
	OpcodeDispatch    Opcode = 0 // R - Server dispatches data to the client
	OpcodeHello       Opcode = 1 // R - Server greets the client
	OpcodeHeartbeat   Opcode = 2 // R - Keep the connection alive
	OpcodeReconnect   Opcode = 4 // R - Server demands that the client reconnects
	OpcodeAck         Opcode = 5 // R - Acknowledgement of an action
	OpcodeError       Opcode = 6 // R - Extra error context in cases where the closing frame is not enough
	OpcodeEndOfStream Opcode = 7 // R - The connection's data stream is ending

	// Commands (33-64)
	OpcodeIdentify    Opcode = 33 // S - Authenticate the session
	OpcodeResume      Opcode = 34 // S - Resume the previous session and receive missed events
	OpcodeSubscribe   Opcode = 35 // S - Subscribe to an event
	OpcodeUnsubscribe Opcode = 36 // S - Unsubscribe from an event
	OpcodeSignal      Opcode = 37 // S - Emit a spectator signal
	OpcodeBridge      Opcode = 38 // S - Send a special command
)

func (Opcode) PublishKey

func (op Opcode) PublishKey() string

func (Opcode) String

func (op Opcode) String() string

type ReconnectPayload

type ReconnectPayload struct {
	Reason string `json:"reason"`
}

type ResumePayload

type ResumePayload struct {
	SessionID string `json:"session_id"`
}

type SessionEffect

type SessionEffect struct {
	AddSubscriptions    []SubscribePayload   `json:"add_subscriptions,omitempty"`
	RemoveSubscriptions []UnsubscribePayload `json:"remove_subscriptions,omitempty"`
	RemoveHashes        []uint32             `json:"remove_hashes,omitempty"`
}

type SessionMutation

type SessionMutation struct {
	RequestID string                 `json:"request_id"`
	SessionID string                 `json:"session_id"`
	Events    []SessionMutationEvent `json:"events,omitempty"`
	ActorID   primitive.ObjectID     `json:"actor_id,omitempty"`
}

type SessionMutationEvent

type SessionMutationEvent struct {
	Action    structures.ListItemAction `json:"action"`
	Type      EventType                 `json:"type"`
	Condition map[string]string         `json:"condition"`
}

type SignalPayload

type SignalPayload struct {
	Sender SignalUser `json:"sender"`
	Host   SignalUser `json:"host"`
}

type SignalUser

type SignalUser struct {
	ID          primitive.ObjectID `json:"id"`
	ChannelID   string             `json:"channel_id"`
	Username    string             `json:"username"`
	DisplayName string             `json:"display_name"`
}

type SubscribePayload

type SubscribePayload struct {
	Type      EventType         `json:"type"`
	Condition map[string]string `json:"condition"`
	TTL       time.Duration     `json:"ttl,omitempty"`
}

type UnsubscribePayload

type UnsubscribePayload struct {
	Type      EventType         `json:"type"`
	Condition map[string]string `json:"condition"`
}

Jump to

Keyboard shortcuts

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