Documentation
¶
Index ¶
Constants ¶
const ( StatusOK int32 = iota StatusUnknownResource StatusSubscriptionLimitReached StatusNoResourceData StatusThrottled = 1001 )
Variables ¶
ErrUnavailable is returned when an operation requires an RTA connection, but no RTA connection is configured.
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
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) 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 ¶
func (*UnexpectedStatusError) Error ¶
func (e *UnexpectedStatusError) Error() string