Skip to main content

External Communication

External Communication

Elympics SDK provides developers with the ability to communicate with external services. This communication is facilitated through specific interfaces available in the ElympicsLobbyPackage.ExternalCommunication namespace.

The Lobby package provides developers with easy access to external communications through the ElympicsExternalCommunicator class. An instance of this class is included in the JsReceiver prefab.

ElympicsExternalCommunicator is an all-in-one solution for managing external communications, containing all the necessary interface implementations for external communication. This works in the PlayPad environment, and to test these behaviors in the Editor, you need to mock them.

IExternalGameStatusCommunicator

The IExternalGameStatusCommunicator interface is used for initializing communication with the PlayPad and for sending game status updates, such as the end of a match.

  • ApplicationInitialized method is used to send a notification to the PlayPad that the game has started. It is crucial to use this method only once per game instance to ensure proper communication with the PlayPad.

  • GameFinished method is used by the client to notify that the match has ended correctly, along with the final score. This method should be used after the completion of a match.

IExternalAuthorizer

The IExternalAuthorizer interface is used to obtain information regarding external authentication.

InitializationMessage method is used to receive feedback in the form of ExternalAuthData. This method provides essential details about the external authentication capabilities. Based on the information in ExternalAuthData, appropriate parameters for authentication are determined and used in the ElympicsLobbyClient.Instance.ConnectToElympicsAsync() method. For example:

  • If AuthData is not null, use it as ConnectionData.AuthFromCacheData in ElympicsLobbyClient.Instance.ConnectToElympicsAsync().
  • If AuthData is null, depending on the Capabilities, check the wallet address with IExternalWalletCommunicator.Connect(), and if valid, connect using the corresponding AuthType with ElympicsLobbyClient.Instance.ConnectToElympicsAsync().
tip

For example, if Capabilities.IsEth(), use AuthType.EthAddress.

ExternalAuthData

The ExternalAuthData structure provide details about:

  • AuthData Contains information about external authentication. If AuthData is null, it means there is no external authentication.
  • IsMobile Indicates whether the context is mobile or desktop WebGL.
  • Capabilities Describes the user's authentication capabilities.
  • Environment Provides information about the development environment.

IExternalWalletCommunicator

The IExternalWalletCommunicator interface consists of several methods and events designed to manage and interact with external wallets. Here is a description of each function and event based on the provided context:

  • WalletConnected Triggered when a wallet successfully connects.
  • WalletDisconnected Triggered when a wallet is disconnected.
  • SignMessage() Signs a message with the specified wallet address.
  • Connect() Get a ConnectionResponse to a wallet using the specified blockchain chain ID.
  • GetBalance() Retrieves the balance of the specified wallet owner.
  • GetAllowance() Retrieves the allowance set for a specific spender by the owner.
  • ApproveMax() Approves a maximum allowance for the spender by the owner.
  • SendTransaction() Sends a transaction to sign on blockchain.
  • Deposit() Deposits a specified token and value into the wallet.
  • ExternalShowChainSelection() Shows the selected chain.
  • ExternalShowConnectToWallet() Allows for connection to a wallet through the PlayPad.
  • ExternalShowAccountInfo() Displays the account information, providing the option to disconnect the wallet through the PlayPad.
warning

Events WalletConnected and WalletDisconnected are triggered by the PlayPad. It doesn't interfere with or change in-game authentication state automatically. We must handle the appropriate user re-authentication based on these events manually.

  • If a WalletConnected event occurs, we should call ElympicsLobbyClient.Instance.SignOut() and then log in using AuthType.EthAddress.
  • If a WalletDisconnected event occurs, we should call ElympicsLobbyClient.Instance.SignOut() and then log in as a guest using AuthType.ClientSecret.

Additionally, if these events occur during matchmaking or a match, they should be remembered and handled only after returning to the menu scene.