events

package
v0.0.0-...-367ce81 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish[D AnyPayload](ctx context.Context, msg Message[D], redis redis.Instance) error

Types

type AckPayload

type AckPayload struct {
	RequestID string         `json:"request_id"`
	Data      map[string]any `json:"data"`
}

type ChangeField

type ChangeField struct {
	Key      string `json:"key"`
	OldValue any    `json:"old_value"`
	NewValue any    `json:"new_value"`
}

type ChangeMap

type ChangeMap struct {
	// The object's ID
	ID primitive.ObjectID `json:"id"`
	// The type of the object
	Kind structures.ObjectKind `json:"kind"`
	// 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 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
)

func (CloseCode) String

func (c CloseCode) String() string

type DispatchPayload

type DispatchPayload struct {
	Type EventType `json:"type"`
	Body ChangeMap `json:"body"`
}

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 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"
	EventTypeAddUserConnection    EventType = "user.add_connection"
	EventTypeUpdateUserConnection EventType = "user.update_connection"
	EventTypeDeleteUserConnection EventType = "user.delete_connection"
)

func (EventType) ObjectName

func (et EventType) ObjectName() string

func (EventType) Split

func (et EventType) Split() []string

type HeartbeatPayload

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

type HelloPayload

type HelloPayload struct {
	HeartbeatInterval int64               `json:"heartbeat_interval"`
	SessionID         string              `json:"session_id"`
	Actor             *primitive.ObjectID `json:"actor,omitempty"`
}

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 = 36 // S - Emit a spectator signal
)

func (Opcode) PublishKey

func (op Opcode) PublishKey() string

func (Opcode) String

func (op Opcode) String() string

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"`
	Targets []string                  `json:"targets"`
}

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"`
	Targets []string  `json:"targets"`
}

type UnsubscribePayload

type UnsubscribePayload struct {
	Type EventType `json:"type"`
}

Jump to

Keyboard shortcuts

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