浏览代码

Updating Lobby and Relay packages, including updates to the RelayAPIInterface.

/main/staging/error_codes_to_exceptions
nathaniel.buck@unity3d.com 3 年前
当前提交
3e096d83
共有 4 个文件被更改,包括 31 次插入46 次删除
  1. 55
      Assets/Scripts/Relay/RelayAPIInterface.cs
  2. 7
      Assets/Scripts/Tests/PlayMode/RelayRoundTripTests.cs
  3. 4
      Packages/manifest.json
  4. 11
      Packages/packages-lock.json

55
Assets/Scripts/Relay/RelayAPIInterface.cs


using System;
using Unity.Services.Relay;
using Unity.Services.Relay.Allocations;
using RelayService = Unity.Services.Relay.Relay;
namespace LobbyRelaySample.Relay
{

/// </summary>
public static void AllocateAsync(int maxConnections, Action<Allocation> onComplete)
{
CreateAllocationRequest createAllocationRequest = new CreateAllocationRequest(new AllocationRequest(maxConnections));
var task = RelayService.AllocationsApiClient.CreateAllocationAsync(createAllocationRequest);
var task = RelayService.Instance.CreateAllocationAsync(maxConnections);
void OnResponse(Response<AllocateResponseBody> response)
void OnResponse(Allocation response)
else if (response.Status >= 200 && response.Status < 300)
onComplete?.Invoke(response.Result.Data.Allocation);
Debug.LogError($"Allocation returned a non Success code: {response.Status}");
onComplete?.Invoke(response);
};
}

/// </summary>
public static void GetJoinCodeAsync(Guid hostAllocationId, Action<string> onComplete)
{
GetJoinCodeAsync(hostAllocationId, a =>
var task = RelayService.Instance.GetJoinCodeAsync(hostAllocationId);
AsyncRequestRelay.Instance.DoRequest(task, OnResponse);
void OnResponse(string response)
if (a.Status >= 200 && a.Status < 300)
onComplete.Invoke(a.Result.Data.JoinCode);
if (response == null)
Debug.LogError("Could not retrieve a Relay join code.");
{
Debug.LogError($"Relay GetJoinCodeAsync returned a non-success code: {a.Status}");
}
});
}
private static void GetJoinCodeAsync(Guid hostAllocationId, Action<Response<JoinCodeResponseBody>> onComplete)
{
CreateJoincodeRequest joinCodeRequest = new CreateJoincodeRequest(new JoinCodeRequest(hostAllocationId));
var task = RelayService.AllocationsApiClient.CreateJoincodeAsync(joinCodeRequest);
AsyncRequestRelay.Instance.DoRequest(task, onComplete);
onComplete?.Invoke(response);
}
}
/// <summary>

{
JoinAsync(joinCode, a =>
var task = RelayService.Instance.JoinAllocationAsync(joinCode);
AsyncRequestRelay.Instance.DoRequest(task, OnResponse);
void OnResponse(JoinAllocation response)
if (a.Status >= 200 && a.Status < 300)
onComplete.Invoke(a.Result.Data.Allocation);
if (response == null)
Debug.LogError("Could not join async with Relay join code " + joinCode);
{
Debug.LogError($"Join Call returned a non Success code: {a.Status}");
}
});
}
public static void JoinAsync(string joinCode, Action<Response<JoinResponseBody>> onComplete)
{
JoinRelayRequest joinRequest = new JoinRelayRequest(new JoinRequest(joinCode));
var task = RelayService.AllocationsApiClient.JoinRelayAsync(joinRequest);
AsyncRequestRelay.Instance.DoRequest(task, onComplete);
onComplete?.Invoke(response);
};
}
}
}

7
Assets/Scripts/Tests/PlayMode/RelayRoundTripTests.cs


using System.Collections;
using LobbyRelaySample.Relay;
using NUnit.Framework;
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
using UnityEngine;
using UnityEngine.TestTools;

// Joining with the join code
timeout = 5;
Response<JoinResponseBody> joinResponse = null;
JoinAllocation joinResponse = null;
RelayAPIInterface.JoinAsync(joinCode, (j) => { joinResponse = j; });
while (joinResponse == null && timeout > 0)
{ yield return new WaitForSeconds(0.25f);

var codeIp = joinResponse.Result.Data.Allocation.RelayServer.IpV4;
var codePort = joinResponse.Result.Data.Allocation.RelayServer.Port;
var codeIp = joinResponse.RelayServer.IpV4;
var codePort = joinResponse.RelayServer.Port;
Assert.AreEqual(codeIp, allocationIP);
Assert.AreEqual(codePort, allocationPort);
}

4
Packages/manifest.json


"com.unity.nuget.newtonsoft-json": "2.0.0",
"com.unity.services.authentication": "1.0.0-pre.4",
"com.unity.services.core": "1.0.0",
"com.unity.services.lobby": "1.0.0-pre.3",
"com.unity.services.relay": "1.0.0-pre.3",
"com.unity.services.lobby": "1.0.0-pre.4",
"com.unity.services.relay": "1.0.1-pre.1",
"com.unity.sysroot.linux-x86_64": "0.1.15-preview",
"com.unity.test-framework": "1.1.27",
"com.unity.textmeshpro": "3.0.6",

11
Packages/packages-lock.json


"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.services.lobby": {
"version": "1.0.0-pre.3",
"version": "1.0.0-pre.4",
"depth": 0,
"source": "registry",
"dependencies": {

"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.nuget.newtonsoft-json": "2.0.0",
"com.unity.services.authentication": "1.0.0-pre.3"
"com.unity.services.authentication": "1.0.0-pre.4"
"version": "1.0.0-pre.3",
"version": "1.0.1-pre.1",
"com.unity.services.core": "1.1.0-pre.4",
"com.unity.services.core": "1.1.0-pre.8",
"com.unity.nuget.newtonsoft-json": "2.0.0"
"com.unity.nuget.newtonsoft-json": "2.0.0",
"com.unity.services.authentication": "1.0.0-pre.4"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},

正在加载...
取消
保存