ServerRelayData constructor changed?

Prior to removing the deprecated lobby & relay packages and installing the new unified multiplayer services package, I could set the connection type for the transport to “wss” for WebGL. I am not getting a syntax error with this code:

void SetHostRelayData(Allocation allocation, string connectionType)
{
   RelayServerData relayServerData = new RelayServerData(allocation, connection);
   Transport.SetRelayServerData(relayServerData);
}

Did the constructor RelayServerData change? What is the new correct way to specify wss when targeting WebGL?

Found the answer. The migration docs need to be updated to include this information.
Unity 6 Multiplayer Relay WebSocket “wss” ERROR - Unity Services - Unity Discussions

I’ve looked at the link you attached, but I am a bit lost with that. What does your new code look like for the SetHostRelayData and SetClientRelayData?

Hi @AGrunt ,
Here is the Migrate to the Multiplayer Services SDK documentation, I hope the code snippets will help you have a better understanding.

Probably a bit more than you’re asking for but here’s my code:

        async Task SetRelayClientData(string relayCode)
        {
            var transport = NetworkManager.Singleton.GetComponentInChildren<UnityTransport>();
            var joinAllocation = await RelayService.Instance.JoinAllocationAsync(relayCode);

            var endpoint = GetEndpointForAllocation(
                joinAllocation.ServerEndpoints,
                joinAllocation.RelayServer.IpV4,
                joinAllocation.RelayServer.Port,
                out var isSecure);

            transport.SetClientRelayData(
                AddressFromEndpoint(endpoint),
                endpoint.Port,
                joinAllocation.AllocationIdBytes,
                joinAllocation.Key,
                joinAllocation.ConnectionData,
                joinAllocation.HostConnectionData,
                isSecure);

            #if UNITY_WEBGL
            var relayClientData = joinAllocation.ToRelayServerData("wss");
            transport.SetRelayServerData(relayClientData);
            #else
            var relayClientData = joinAllocation.ToRelayServerData("dtls");
            transport.SetRelayServerData(relayClientData);
            #endif
            await PlayerConnectionsManager.Instance.StartClient();
        }

        async Task<string> GetRelayAllocation()
        {
            var regions = await RelayService.Instance.ListRegionsAsync();
            var region = regions[0].Id;
            
            var allocation = await RelayService.Instance.CreateAllocationAsync(CurrentLobby.MaxPlayers, region);
            var relayCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);

            var endpoint = GetEndpointForAllocation(
                allocation.ServerEndpoints,
                allocation.RelayServer.IpV4,
                allocation.RelayServer.Port,
                out bool isSecure);
            
            var transport = NetworkManager.Singleton.GetComponent<UnityTransport>();
            transport.SetHostRelayData(AddressFromEndpoint(endpoint), 
                endpoint.Port,
                allocation.AllocationIdBytes, 
                allocation.Key, 
                allocation.ConnectionData, 
                isSecure);
            
            #if UNITY_WEBGL
            SetRelayServerData(allocation, "wss");
            #else
            SetHostRelayData(allocation, "dtls");
            #endif
            
            return relayCode;
        }

        void SetRelayServerData(Allocation allocation, string connectionType)
        {
            var relayServerData = allocation.ToRelayServerData(connectionType);
            Transport.SetRelayServerData(relayServerData);
        }
        
        async Task SetLobbyRelayCode(string relayCode)
        {
            var options = new UpdateLobbyOptions
            {
                Data = new Dictionary<string, DataObject>
                {
                    [RelayCodeKey] = new(DataObject.VisibilityOptions.Public, relayCode)
                }
            };
            CurrentLobby = await LobbyService.Instance.UpdateLobbyAsync(CurrentLobby.Id, options);
        }

        string AddressFromEndpoint(NetworkEndpoint endpoint)
        {
            return endpoint.Address.Split(':')[0];
        }

        /// <summary>
        /// Determine the server endpoint for connecting to the Relay server, for either an Allocation or a JoinAllocation.
        /// If DTLS encryption is available, and there's a secure server endpoint available, use that as a secure connection. Otherwise, just connect to the Relay IP unsecured.
        /// </summary>
        NetworkEndpoint GetEndpointForAllocation(
            List<RelayServerEndpoint> endpoints,
            string ip,
            int port,
            out bool isSecure)
        {
#if ENABLE_MANAGED_UNITYTLS && !UNITY_WEBGL
            foreach (RelayServerEndpoint endpoint in endpoints)
            {
                if (!endpoint.Secure || endpoint.Network != RelayServerEndpoint.NetworkOptions.Udp) continue;
                isSecure = true;
                return NetworkEndpoint.Parse(endpoint.Host, (ushort)endpoint.Port);
            }
#endif
            isSecure = false;
            return NetworkEndpoint.Parse(ip, (ushort)port);
        }

Git-amend has a new video that shows how a lot of this stuff is now encapsulated in the ISession interface.