rta

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK int32 = iota
	StatusUnknownResource
	StatusSubscriptionLimitReached
	StatusNoResourceData
	StatusThrottled          = 1001
	StatusServiceUnavailable = 1002
)

Variables

View Source
var ErrUnavailable = errors.New("rta: connection unavailable")

ErrUnavailable is returned when an operation requires an RTA connection, but no RTA connection is configured.

View Source
var ErrUnsubscribed = errors.New("rta: subscription removed from RTA connection")

ErrUnsubscribed is an error notified by SubscriptionHandler.HandleError when the RTA subscription is unsubscribed by the user.

Functions

This section is empty.

Types

type Conn

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

Conn represents a connection between the real-time activity services. It can be established from Dialer with an authorization token that relies on the party 'https://xboxlive.com/'.

A Conn controls subscriptions real-timely under a websocket connection. An index-specific JSON array is used for the communication. Conn is safe for concurrent use in multiple goroutines.

SubscriptionHandlers are useful to handle any events that may occur in the subscriptions controlled by Conn, and can be stored atomically to a Subscription from Subscription.Handle.

func Dial added in v2.0.2

func Dial(ctx context.Context, client *http.Client, log *slog.Logger) (*Conn, error)

Dial establishes a connection with real-time activity service.

The context.Context is used to control the deadline of the establishment of the WebSocket connection. The http.Client is used to authenticate handshake HTTP requests and is typically retrieved from github.com/df-mc/go-xsapi.Client.HTTPClient.

func (*Conn) Close

func (c *Conn) Close() (err error)

Close closes the websocket connection with websocket.StatusNormalClosure.

func (*Conn) Subscribe

func (c *Conn) Subscribe(ctx context.Context, sub *Subscription) error

Subscribe attempts to subscribe using a caller-owned Subscription. It is useful for services that need to preserve the same subscription object across reconnects.

func (*Conn) Unsubscribe

func (c *Conn) Unsubscribe(ctx context.Context, sub *Subscription) error

Unsubscribe attempts to unsubscribe with a Subscription associated with an ID, with the context.Context to be used during the handshake. An error may be returned.

type NopSubscriptionHandler

type NopSubscriptionHandler struct{}

NopSubscriptionHandler is a no-op implementation of SubscriptionHandler.

func (NopSubscriptionHandler) HandleError added in v2.0.2

func (NopSubscriptionHandler) HandleError(error)

func (NopSubscriptionHandler) HandleEvent

func (NopSubscriptionHandler) HandleEvent(json.RawMessage)

func (NopSubscriptionHandler) HandleResync added in v2.0.2

func (NopSubscriptionHandler) HandleResync()

func (NopSubscriptionHandler) HandleSubscribe added in v2.0.2

func (NopSubscriptionHandler) HandleSubscribe(json.RawMessage) error

type OutOfRangeError

type OutOfRangeError struct {
	Payload []json.RawMessage
	Index   int
}

An OutOfRangeError occurs when reading values from payload received from the service. The Payload specifies the remaining values included in the payload, and the Index specifies a length of values that is missing from the payload.

func (*OutOfRangeError) Error

func (e *OutOfRangeError) Error() string

Error returns a string representation of the Error in the same format used by [runtime.boundsError].

type Subscription

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

Subscription represents a subscription contracted with the resource URI available through the real-time activity service. A Subscription may be contracted via Conn.Subscribe.

func NewSubscription added in v2.0.2

func NewSubscription(resourceURI string, h SubscriptionHandler) *Subscription

func (*Subscription) Active added in v2.0.2

func (s *Subscription) Active() bool

Active reports whether the Subscription is currently active.

func (*Subscription) Custom

func (s *Subscription) Custom() json.RawMessage

Custom returns the custom data associated with the Subscription.

The format and semantics of this data depend on the resource the subscription is targeting. It is received alongside the successful subscription response when the Subscription was established. The custom data may change if the Conn has reconnected to RTA service.

func (*Subscription) Handle

func (s *Subscription) Handle(h SubscriptionHandler)

Handle registers a SubscriptionHandler on the Subscription to handle future events that may occur in the subscription. If h is nil, a no-op handler is registered.

func (*Subscription) ID

func (s *Subscription) ID() uint32

ID returns the ID assigned to the Subscription within a single RTA connection.

func (*Subscription) ResourceURI added in v2.0.2

func (s *Subscription) ResourceURI() string

ResourceURI returns the URI identifying the resource which the Subscription is targeting. The returned value is identical to the one passed to Conn.Subscribe.

type SubscriptionHandler

type SubscriptionHandler interface {
	// HandleEvent handles an event message received over the RTA subscription.
	// The event data reflects what occurred within that subscription.
	// For example, in Social API, an event is received when a user adds or
	// removes the caller.
	HandleEvent(custom json.RawMessage)

	HandleSubscribe(custom json.RawMessage) error
	// HandleResync is called when a Resync message is received from the RTA service
	// and the resource targeted by the Subscription may have been changed.
	HandleResync()

	// HandleError is called when an unrecoverable error has occurred for this subscription.
	// The caller may need to resubscribe in order to receive updates for the resource.
	HandleError(err error)
}

SubscriptionHandler is the interface for handling events that may occur in a single Subscription. An implementation can be registered on a Subscription via Subscription.Handle.

type UnexpectedStatusError

type UnexpectedStatusError struct {
	Code    int32
	Message string
}

func (*UnexpectedStatusError) Error

func (e *UnexpectedStatusError) Error() string

Jump to

Keyboard shortcuts

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