Skip to content

feat: Add new SetRelayServerData method to UnityTransport #2235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 5, 2022

Conversation

simon-lemay-unity
Copy link
Contributor

This PR adds a new API to UnityTransport that allows setting the Relay server data directly from the RelayServerData structure provided by UTP. The idea behind this change is to make it easier for NGO users to benefit from new APIs introduced in UTP 1.3. These new APIs allow creating RelayServerData structures directly from allocation objects from the Relay SDK.

For example, given an allocation object coming directly from the Relay SDK, this PR allows configuring the Relay server data in this manner:

var serverData = new RelayServerData(allocation, "dtls");
transport.SetRelayServerData(serverData);

Compared to the previous ways of configuring the server data, this has many advantages:

  • It's the same API for both client and host, since the RelayServerData constructors accept both Allocation and JoinAllocation objects.
  • There's no need to deconstruct the Allocation/JoinAllocation objects in their individual fields just to pass them to NGO.
  • There's no need to loop through the server endpoints in the allocation to find the one you want.
  • There's no error possible where there's mismatch between the endpoint selected and the isSecure parameter of SetClientRelayData and SetHostRelayData (e.g. you can't select a DTLS endpoint and forget to set isSecure to true).
  • It handles endpoints that are provided as hostnames instead of IP addresses (e.g. for secure WebSockets).
  • It would transparently support IPv6 endpoints if the Relay server would start handing those out.

The previous APIs to set Relay server data remain available (and I'll get them to work with secure WebSockets in a future PR). Although if this lands I'll probably modify the Relay documentation to use the new ones.

Changelog

  • Added: UnityTransport now provides a way to set the Relay server data directly from the RelayServerData structure (provided by the Unity Transport package) throuh its SetRelayServerData method. This allows making use of the new APIs in UTP 1.3 that simplify integration of the Relay SDK.

Testing and Documentation

  • No tests have been added.
  • No documentation changes or additions were necessary (maybe Relay documentation, but that can wait).

@simon-lemay-unity simon-lemay-unity enabled auto-merge (squash) October 5, 2022 14:45
Copy link
Contributor

@SamuelBellomo SamuelBellomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the description for this PR, this looks really cool. This will remove the should remove the need for our UnityRelayUtilities in boss room I believe. Will need to try.

@simon-lemay-unity
Copy link
Contributor Author

Reading the description for this PR, this looks really cool. This will remove the should remove the need for our UnityRelayUtilities in boss room I believe. Will need to try.

Would be very curious to get some feedback once this is integrated in Boss Room. I've written the new APIs with the goal of simplifying integration with the Relay SDK. And while it did simplify our samples in UTP a lot, trying it in a real project like Boss Room will be interesting.

@johann-r-unity
Copy link
Contributor

@ashwinimurt , this is the PR I was mentioning to add for NGO 1.1

@SamuelBellomo
Copy link
Contributor

Reading the description for this PR, this looks really cool. This will remove the should remove the need for our UnityRelayUtilities in boss room I believe. Will need to try.

Would be very curious to get some feedback once this is integrated in Boss Room. I've written the new APIs with the goal of simplifying integration with the Relay SDK. And while it did simplify our samples in UTP a lot, trying it in a real project like Boss Room will be interesting.

@simon-lemay-unity I have a PR for NGO:1.1 update in boss room here Unity-Technologies/com.unity.multiplayer.samples.coop#708
I'll add this as a todo in there

@simon-lemay-unity simon-lemay-unity merged commit cf695a5 into develop Oct 5, 2022
@simon-lemay-unity simon-lemay-unity deleted the feat/set-relay-data-directly branch October 5, 2022 17:06
jakobbbb pushed a commit to GooseGirlGames/com.unity.netcode.gameobjects that referenced this pull request Feb 22, 2023
…nologies#2235)

* feat: Add new SetRelayServerData method to UnityTransport

* Don't pass server data by reference

* Add PR number to CHANGELOG entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants