client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package client contains the internal implementation behind the public osmose package.

It owns lifecycle, gateway, event, and service wiring while the root package keeps the public API surface in client.go.

Index

Constants

View Source
const (
	EndReasonTime     = collectors.EndReasonTime
	EndReasonIdle     = collectors.EndReasonIdle
	EndReasonLimit    = collectors.EndReasonLimit
	EndReasonStopped  = collectors.EndReasonStopped
	EndReasonContext  = collectors.EndReasonContext
	EndReasonOverflow = collectors.EndReasonOverflow
	EndReasonClosed   = collectors.EndReasonClosed
)
View Source
const (
	Disconnected   = events.Disconnected
	Connecting     = events.Connecting
	Initializing   = events.Initializing
	Authenticating = events.Authenticating
	Ready          = events.Ready
	Closing        = events.Closing
)

Variables

View Source
var (
	ErrCollectorEnded    = collectors.ErrCollectorEnded
	ErrCollectorTimeout  = collectors.ErrCollectorTimeout
	ErrCollectorIdle     = collectors.ErrCollectorIdle
	ErrCollectorOverflow = collectors.ErrCollectorOverflow
	ErrCollectorClosed   = collectors.ErrCollectorClosed
)
View Source
var (
	ErrClosed              = events.ErrClosed
	ErrNotConnected        = errors.New("osmose client is not connected")
	ErrNotReady            = errors.New("osmose client is not ready")
	ErrAlreadyRunning      = errors.New("osmose client is already running")
	ErrRunCompleted        = errors.New("osmose client run has completed")
	ErrPermanent           = errors.New("osmose permanent error")
	ErrAuthorizationFailed = errors.New("osmose authorization failed")
	ErrProtocolMismatch    = errors.New("osmose protocol mismatch")
	ErrDisconnected        = rpc.ErrDisconnected
	ErrUnsupportedRequest  = rpc.ErrUnsupportedRequest
)
View Source
var ErrEventQueueFull = eventtypes.ErrEventQueueFull

Functions

func IsPermanent

func IsPermanent(err error) bool

IsPermanent reports whether err contains a permanent Osmose error.

Types

type ChannelDeleteEvent

type ChannelDeleteEvent = eventtypes.ChannelDeleteEvent

type ChannelDeleteHandler

type ChannelDeleteHandler = eventtypes.ChannelDeleteHandler

type ChannelUpdateEvent

type ChannelUpdateEvent = eventtypes.ChannelUpdateEvent

type ChannelUpdateHandler

type ChannelUpdateHandler = eventtypes.ChannelUpdateHandler

type ChatTypingEvent

type ChatTypingEvent = eventtypes.ChatTypingEvent

type ChatTypingHandler

type ChatTypingHandler = eventtypes.ChatTypingHandler

type Client

type Client struct {
	Messages    *messages.Service
	Chats       *chats.Service
	Communities *communities.Service
	Users       *users.Service
	Reactions   *reactions.Service
	Voice       *voice.Service
	// contains filtered or unexported fields
}

Client is the central Osmose client. Services are initialized and ready to use immediately; network operations wait until Run has completed auth. A client has one lifecycle: reconnects happen inside Run, and a completed Run cannot be started again.

func New

func New(config Config) (*Client, error)

func (*Client) AwaitInteraction

func (c *Client) AwaitInteraction(ctx context.Context, options InteractionCollectorOptions) (*InteractionEvent, error)

AwaitInteraction waits for the first interaction matching options.

func (*Client) AwaitMessage

func (c *Client) AwaitMessage(ctx context.Context, options MessageCollectorOptions) (*MessageCreateEvent, error)

AwaitMessage waits for the first message matching options. Its Max value is always one; use CollectMessages when multiple messages are needed.

func (*Client) AwaitReaction

func (c *Client) AwaitReaction(ctx context.Context, options ReactionCollectorOptions) (*MessageReactionsEvent, error)

AwaitReaction waits for the first matching reaction snapshot.

func (*Client) Close

func (c *Client) Close() error

Close stops the run loop and active connection. Run returns after its current handler and connection cleanup finish.

func (*Client) CollectInteractions

func (c *Client) CollectInteractions(options InteractionCollectorOptions) (*InteractionCollector, error)

CollectInteractions starts a bounded interaction collector.

func (*Client) CollectInteractionsContext

func (c *Client) CollectInteractionsContext(ctx context.Context, options InteractionCollectorOptions) (*InteractionCollector, error)

CollectInteractionsContext starts an interaction collector tied to ctx and the client lifecycle.

func (*Client) CollectMessages

func (c *Client) CollectMessages(options MessageCollectorOptions) (*MessageCollector, error)

CollectMessages starts a bounded message collector. Use Stop when no Time, Idle, or Max limit is configured.

func (*Client) CollectMessagesContext

func (c *Client) CollectMessagesContext(ctx context.Context, options MessageCollectorOptions) (*MessageCollector, error)

CollectMessagesContext starts a bounded message collector tied to ctx and the client lifecycle.

func (*Client) CollectReactions

func (c *Client) CollectReactions(options ReactionCollectorOptions) (*ReactionCollector, error)

CollectReactions starts a bounded reaction snapshot collector.

func (*Client) CollectReactionsContext

func (c *Client) CollectReactionsContext(ctx context.Context, options ReactionCollectorOptions) (*ReactionCollector, error)

CollectReactionsContext starts a reaction collector tied to ctx and the client lifecycle.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done closes after the client's run and shutdown cleanup have completed.

func (*Client) DroppedEvents

func (c *Client) DroppedEvents() uint64

DroppedEvents returns the number of updates discarded because the bounded event queue was full.

func (*Client) OnChannelDelete

func (c *Client) OnChannelDelete(handler ChannelDeleteHandler) func()

func (*Client) OnChannelUpdate

func (c *Client) OnChannelUpdate(handler ChannelUpdateHandler) func()

func (*Client) OnChatTyping

func (c *Client) OnChatTyping(handler ChatTypingHandler) func()

func (*Client) OnCommunityDelete

func (c *Client) OnCommunityDelete(handler CommunityDeleteHandler) func()

func (*Client) OnCommunityUpdate

func (c *Client) OnCommunityUpdate(handler CommunityUpdateHandler) func()

func (*Client) OnConnected

func (c *Client) OnConnected(handler ConnectionHandler) func()

func (*Client) OnConnecting

func (c *Client) OnConnecting(handler ConnectionHandler) func()

func (*Client) OnConnectionError

func (c *Client) OnConnectionError(handler ConnectionHandler) func()

func (*Client) OnConversationLastRead

func (c *Client) OnConversationLastRead(handler ConversationLastReadHandler) func()

func (*Client) OnDisconnected

func (c *Client) OnDisconnected(handler ConnectionHandler) func()

func (*Client) OnError

func (c *Client) OnError(handler ConnectionHandler) func()

OnError is a short alias for connection errors. Handler failures remain observable through Config.OnHandlerError.

func (*Client) OnInteraction

func (c *Client) OnInteraction(handler InteractionHandler) func()

func (*Client) OnMemberCreate

func (c *Client) OnMemberCreate(handler MemberCreateHandler) func()

func (*Client) OnMemberDelete

func (c *Client) OnMemberDelete(handler MemberDeleteHandler) func()

func (*Client) OnMemberUpdate

func (c *Client) OnMemberUpdate(handler MemberUpdateHandler) func()

func (*Client) OnMessageCreate

func (c *Client) OnMessageCreate(handler MessageCreateHandler) func()

func (*Client) OnMessageDelete

func (c *Client) OnMessageDelete(handler MessageDeleteHandler) func()

func (*Client) OnMessageReactions

func (c *Client) OnMessageReactions(handler MessageReactionsHandler) func()

func (*Client) OnMessageUpdate

func (c *Client) OnMessageUpdate(handler MessageUpdateHandler) func()

func (*Client) OnReady

func (c *Client) OnReady(handler ReadyHandler) func()

func (*Client) OnReconnecting

func (c *Client) OnReconnecting(handler ConnectionHandler) func()

func (*Client) OnUpdate

func (c *Client) OnUpdate(handler UpdateHandler) func()

func (*Client) OnUserUpdate

func (c *Client) OnUserUpdate(handler UserUpdateHandler) func()

func (*Client) OnVoiceRoomParticipant

func (c *Client) OnVoiceRoomParticipant(handler VoiceRoomParticipantHandler) func()

func (*Client) OnVoiceRoomState

func (c *Client) OnVoiceRoomState(handler VoiceRoomStateHandler) func()

func (*Client) Raw

func (c *Client) Raw() *RawClient

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run owns the connection lifecycle until ctx is canceled, Close is called, or a permanent protocol error is returned. It may be called only once per Client; use a new Client for a new lifecycle.

func (*Client) SessionID

func (c *Client) SessionID() types.ID

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) error

Shutdown closes the client and waits for all run and event-dispatch cleanup. It is safe to call when the client is not running.

func (*Client) State

func (c *Client) State() State

func (*Client) User

func (c *Client) User() *types.User

func (*Client) WaitReady

func (c *Client) WaitReady(ctx context.Context) error

type CollectorError

type CollectorError = collectors.CollectorError

type CollectorResult

type CollectorResult = collectors.CollectorResult

type CommunityDeleteEvent

type CommunityDeleteEvent = eventtypes.CommunityDeleteEvent

type CommunityDeleteHandler

type CommunityDeleteHandler = eventtypes.CommunityDeleteHandler

type CommunityUpdateEvent

type CommunityUpdateEvent = eventtypes.CommunityUpdateEvent

type CommunityUpdateHandler

type CommunityUpdateHandler = eventtypes.CommunityUpdateHandler

type Config

type Config struct {
	Token    string
	ClientID uint32

	ServerURL         string
	Logger            *slog.Logger
	OnHandlerError    HandlerErrorHandler
	OnEventOverflow   EventOverflowHandler
	RequestTimeout    time.Duration
	RequestInterval   time.Duration
	HeartbeatInterval time.Duration
	EventQueue        int
	EventWorkers      int
	WriteQueue        int
	WriteTimeout      time.Duration
	ReadLimit         int64
	DialTimeout       time.Duration
	StableConnection  time.Duration
	BackoffMin        time.Duration
	BackoffMax        time.Duration

	DeviceType    string
	DeviceVersion string
	AppVersion    string
	// contains filtered or unexported fields
}

Config controls a Client. Zero values use sensible defaults.

type ConnectionEvent

type ConnectionEvent = eventtypes.ConnectionEvent

type ConnectionHandler

type ConnectionHandler = eventtypes.ConnectionHandler

type ConversationLastReadEvent

type ConversationLastReadEvent = eventtypes.ConversationLastReadEvent

type ConversationLastReadHandler

type ConversationLastReadHandler = eventtypes.ConversationLastReadHandler

type EndReason

type EndReason = collectors.EndReason

type EventOverflowHandler

type EventOverflowHandler = eventtypes.EventOverflowHandler

type HandlerError

type HandlerError = eventtypes.HandlerError

type HandlerErrorHandler

type HandlerErrorHandler = eventtypes.HandlerErrorHandler

type InteractionCollector

type InteractionCollector = collectors.InteractionCollector

type InteractionCollectorOptions

type InteractionCollectorOptions = collectors.InteractionCollectorOptions

type InteractionEvent

type InteractionEvent = eventtypes.InteractionEvent

type InteractionHandler

type InteractionHandler = eventtypes.InteractionHandler

type MemberCreateEvent

type MemberCreateEvent = eventtypes.MemberCreateEvent

type MemberCreateHandler

type MemberCreateHandler = eventtypes.MemberCreateHandler

type MemberDeleteEvent

type MemberDeleteEvent = eventtypes.MemberDeleteEvent

type MemberDeleteHandler

type MemberDeleteHandler = eventtypes.MemberDeleteHandler

type MemberUpdateEvent

type MemberUpdateEvent = eventtypes.MemberUpdateEvent

type MemberUpdateHandler

type MemberUpdateHandler = eventtypes.MemberUpdateHandler

type MessageCollector

type MessageCollector = collectors.MessageCollector

type MessageCollectorOptions

type MessageCollectorOptions = collectors.MessageCollectorOptions

type MessageCreateEvent

type MessageCreateEvent = eventtypes.MessageCreateEvent

type MessageCreateHandler

type MessageCreateHandler = eventtypes.MessageCreateHandler

type MessageDeleteEvent

type MessageDeleteEvent = eventtypes.MessageDeleteEvent

type MessageDeleteHandler

type MessageDeleteHandler = eventtypes.MessageDeleteHandler

type MessageReactionsEvent

type MessageReactionsEvent = eventtypes.MessageReactionsEvent

type MessageReactionsHandler

type MessageReactionsHandler = eventtypes.MessageReactionsHandler

type MessageUpdateEvent

type MessageUpdateEvent = eventtypes.MessageUpdateEvent

type MessageUpdateHandler

type MessageUpdateHandler = eventtypes.MessageUpdateHandler

type PermanentError

type PermanentError struct{ Err error }

PermanentError marks an error that should not be retried by Client.Run. Its cause remains available through errors.Is and errors.As.

func (*PermanentError) Error

func (e *PermanentError) Error() string

func (*PermanentError) Is

func (e *PermanentError) Is(target error) bool

func (*PermanentError) Unwrap

func (e *PermanentError) Unwrap() error

type RPCError

type RPCError struct {
	Code    uint32
	Message string
	TraceID string
}

RPCError is an error returned by the Osmium RPC endpoint.

func (*RPCError) Error

func (e *RPCError) Error() string

type RawClient

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

RawClient is the escape hatch for generated protobuf requests not wrapped by a high-level service yet.

func (*RawClient) Call

func (r *RawClient) Call(ctx context.Context, request proto.Message) (*core.RPCResult, error)

type ReactionCollector

type ReactionCollector = collectors.ReactionCollector

type ReactionCollectorOptions

type ReactionCollectorOptions = collectors.ReactionCollectorOptions

type ReadyEvent

type ReadyEvent = eventtypes.ReadyEvent

type ReadyHandler

type ReadyHandler = eventtypes.ReadyHandler

type State

type State = events.State

State is kept as an alias for compatibility with the root client API.

type UnexpectedResultError

type UnexpectedResultError = rpc.UnexpectedResultError

UnexpectedResultError means the server answered with a result different from the one defined for the requested method.

type UpdateEvent

type UpdateEvent = eventtypes.UpdateEvent

type UpdateHandler

type UpdateHandler = eventtypes.UpdateHandler

type UserUpdateEvent

type UserUpdateEvent = eventtypes.UserUpdateEvent

type UserUpdateHandler

type UserUpdateHandler = eventtypes.UserUpdateHandler

type VoiceRoomParticipantEvent

type VoiceRoomParticipantEvent = eventtypes.VoiceRoomParticipantEvent

type VoiceRoomParticipantHandler

type VoiceRoomParticipantHandler = eventtypes.VoiceRoomParticipantHandler

type VoiceRoomStateEvent

type VoiceRoomStateEvent = eventtypes.VoiceRoomStateEvent

type VoiceRoomStateHandler

type VoiceRoomStateHandler = eventtypes.VoiceRoomStateHandler

Jump to

Keyboard shortcuts

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