This quickstart guide covers use of the C++ Party SDK * For Unity users, refer to the Quickstart for Unity * For Unreal Engine users who want to use the PlayFab Online Subsystem for Unreal Engine, refer to the Quickstart for Unreal.
Prerequisites
You need a PlayFab account, and you must enable the Party feature to start using Party.- Create or sign in to your PlayFab account. For instructions, see Quickstart: Game Manager.
- Enable Party feature via Game Manager from your PlayFab account.
Platform Prerequisites
Before you start this quickstart, perform any necessary platform-specific setup as specified in the following topics: <!—3. Nintendo Switch prerequisites—> When you finish the platform-specific steps, continue with the rest of the steps in this topic to set up PlayFab Party.Download and set up Party SDK
There are Party SDKs for different platforms and game engines. Select and download the one that you need. For download links, see Party SDKs. After installing the SDK, you might want to run a sample to see how Party works before you start writing code. To download a sample, go to Party samples. If you’re using Party in XBOX and PC titles, we recommend that you use the Party XBOX Live Helper Library to ensure consistent functionality and behavior. This library helps your title meet XBOX Live requirements. To learn more, see XBOX requirements.Log in to your PlayFab title and obtain an entity token and entity ID
To initialize and use Party, you must log in to PlayFab. You can use PlayFabClientAPI::LoginWithCustomID or a platform-specific login method. Once you execute login, PlayFab returns an entity ID and entity token as part of the LoginResult. These two key pieces of information are used to initialize a Local user instance for PlayFab Party. An example for logging in with a custom ID as implemented inPlayFabManager.cpp is shown in this code snippet:
If you’re using XBOX Live, you can also get use the Party XBOX Live Helper Library to login.
Initialize PlayFab Party
At a high level, initializing Party involves the following steps:- Get a singleton reference to the
PartyManagerand initialize it.
This is the primary management class for interacting with the Party library.
- Create a local user object.
This local user object is used to represent a local user on the device (PC, console, phone, …) when performing networking and chat operations. The local user object is initialized with the PlayFab Entity ID.
- Create a chat control and set the audio input and output channel where Party will receive or forward data.
The chat control object manages the chat operations for the user on the specific device.
- Set the transcription and translation options.
Transcription and translation are optional chat features that can significantly increase accessibility of your game. You can find more information about these features in the Chat Overview.
NetworkManager::Initialize() code in NetworkManager.cpp in the demo app for a complete sample.
The next step is to create a Party Network and connect to it.
Create a Party Network
A Party Network is a secured collection of one or more devices and their authorized users that the game creates to exchange chat or data communication. A Party Network typically aligns with a game’s multiplayer session or chat “lobby” concept. You can only send messages to players inside your own network. The following code snippet shows how we can create a Party Network.CreateNewNetwork() succeeds, a network descriptor PartyNetworkDescriptor object is returned/populated. The descriptor contains the data required for other players to connect to a network.
Refer to the API Reference Documentation for information about the other function parameters.
Once a Party network has been created, invitations are used to control which users can join the network. PlayFab Matchmaking, PlayFab Lobby, platform invites, or custom game services can be used to share connection details with other players.
The simplest invitation type is an open invitation that consists of a network descriptor. For detailed information of all invitation types and the security model, refer to Invitations and the security model.
Share Party network descriptor
At this point, you have a party network descriptor and are ready to share it with other players. There are many synchronization mechanisms that you can use to share this information, but for quick testing purposes, you can copy and paste the Party network descriptor from the host Party session to the guest Party session manually. We recommend using PlayFab Lobby for sharing the network descriptor in your multiplayer game, but you can also use your own lobby service, invites, or other sharing mechanisms based on the needs of your game.Manually share Party network descriptor
- From host session, use PartyManager::SerializeNetworkDescriptor() to serialize the network descriptor to a string and print it out to the console.
- Copy and paste the network descriptor string to another game locally or remotely.
- In the guest session, use PartyManager::DeserializeNetworkDescriptor() to deserialize the network descriptor from the network descriptor string.
- Connect to the Party Network.
Use PlayFab Lobby to share the Party network descriptor
PlayFab Lobby can be used to temporarily group players as they move into and out of matches and can be used to synchronize the network descriptor so that players can join the same network. PlayFab Lobby is highly customizable to support a wide variety of gameplay needs on all supported platforms and across platforms. Refer to the Multiplayer SDK Quickstart for more detail about using PlayFab Lobby with real-time messages. For details about using PlayFab Lobby together with PlayFab Party, refer to Create a lobby with PlayFab Multiplayer SDK.Enable Scalable networks
PlayFab Party networks can scale to support anywhere between 2 and 128 devices. The service will choose a relay configuration optimized for your scenario, so it’s important to configure themaxDeviceCount in PartyNetworkConfiguration to match the max expected number of devices in your network.
For a description of Scalable networks, see Scalable networks.
Connect to a Party network
Follow the steps below to join the party network after obtaining the Party network descriptor:- Use PartyManager::DeserializeNetworkDescriptor() to deserialize the network descriptor from the network descriptor string.
- Connect to the Party Network.
- Authenticate the local user for the network.
- Connect the local chat control to the network so that we can use VOIP.
- Establish a Party Network endpoint for game message traffic.
Send a message to another network device or endpoint
Once you’ve connected to the Party Network, you can send a message using the local endpoint object.Receive a message and render it on the local device
The final step is receiving messages sent by remote Party members and rendering (playing) them on your device.While creating the chat control in one of the previous steps, you’ve already set up the audio input and output devices which is used by Party to send, receive and render audio data. To receive the audio messages, you’ll also need to set the appropriate chat permission between each chat control if you want audio to flow. By default, the chat permissions are set to NONE. For more information, see the Chat Permissions article.
Handling title suspension
Some platforms support temporarily suspending execution of your title: iOS, Switch, and GDK. When your title is suspended, the network stack becomes invalidated and PlayFab Party is unable to maintain a connection to the PlayFab Party network. Special consideration is required to handle suspending and resuming execution of your title when using PlayFab Party.iOS
On iOS, you must leave and reconnect to the PlayFab Party network To leave Party network, call LeaveNetwork(). After the network is reactivated, call ConnectToNetwork() with previous Party network descriptor.Switch and GDK
On Nintendo Switch and Microsoft GDK, you must clean up PlayFab Party and wait until the title execution resumes before reinitializing PlayFab Party and reconnecting to your network. To shut down the Party, call Cleanup().Calling Cleanup() reclaims all library resources and destroys all library objects. After reinitializing Party, you’ll need to recreate any library objects such as local users and chat controls as well as reestablish any previous network state by reauthenticating local users, reconnecting chat controls, and recreating endpoints.
- Connect to the Party Network with previous Party network descriptor.
- Recreate any local user objects and reauthenticate those local users into the network.
- Recreate any local chat controls and reconnect those chat controls to the network to enable VOIP
- Recreate any Party Network endpoints for game message traffic.
If the reconnection is successfully completed, the party will now be able to communicate to other peers, but if the previous network no longer exists, the reconnecting will be failed. In this case, you should handle the appropriate connection error.
