Real-time notifications SignalR Hub

Note

Using Lobby, Matchmaking, and real-time notifications directly with REST and SignalR APIs is significantly more complex than using client SDKs such as the Lobby C++ SDK and Matchmaking C++ SDK, and should only be done if the SDKs don't meet your needs.

The real-time notifications feature for Lobby and Matchmaking services works through a SignalR service, which exposes a SignalR Hub. This SignalR Hub can be used by game clients to receive messages about resources they subscribed to.

Connecting to the SignalR Hub

The first step in receiving real-time notifications is to create a SignalR client. The client can create a connection to the SignalR Hub by instantiating a HubConnection with the following API: SignalR Negotiate REST API. This API implements the Negotiate API described in the SignalR documentation.

Warning

Using MessagePack (MsgPack) encoding when connecting to the SignalR Hub is strongly recommended, and will be enforced as the only supported encoding in the future.

Note

  1. SignalR client implementations expect the URL to omit the /negotiate portion of this path (ex: HubConnection should created to a URL that ends in ...playfabapi.com/pubsub).
  2. The auth headers required to call this API can be passed to the SignalR client via HttpConnectionOptions as seen on this method.

Implementing client methods to receive messages

See the SignalR Client documentation about implementing client methods that will be invoked to receive messages. Clients should implement all of the methods listed in Client methods below.

Starting and ending a session by calling server methods

See the SignalR Client documentation about calling server methods to manage your session. For example, once connected to the hub, you must call StartOrRecoverSession to receive a connection handle that you can use to subscribe to resources. Similarly, once you're done with the session, call EndSession.

Subscribing to resources

Once a session has been started with StartOrRecoverSession, you can use the connection handle returned to start subscribing to resources and receiving messages.

APIs

Client methods

Name Description
ReceiveMessage Receive a notification message.
ReceiveSubscriptionChangeMessage Receive a SubscriptionChangeMessage to track current subscriptions.

Server methods

Name Description
StartOrRecoverSession Start or recover a session.
EndSession End the session.

Shared session methods

Name Description
AddEntityToSession For scenarios where multiple entities are signed in to the same device. Add an extra entity to the session, to receive messages for multiple local entities on a shared session.
RemoveEntityFromSession Remove an entity from the session.

See also