Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions Runtime/Matchmaking/Api.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
Expand All @@ -18,6 +19,7 @@ public class Api<T, A>
internal string PATH_BEACONS = "locations/beacons";
internal string PATH_TICKETS = "tickets";
internal string PATH_GROUP_TICKETS = "group-tickets";
internal string PATH_GROUP_UP = "groups";

public Api(MonoBehaviour parent, string authToken, string baseUrl)
{
Expand Down Expand Up @@ -187,5 +189,192 @@ Action<string, UnityWebRequest> onErrorDelegate
onErrorDelegate
);
}

public void CreateGroupAsync(
T group,
Action<GroupUpResponseDTO, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Post(
$"{BaseUrl}/{PATH_GROUP_UP}",
AuthToken,
JsonConvert.SerializeObject(group),
(string response, UnityWebRequest request) =>
{
try
{
GroupUpResponseDTO assignment =
JsonConvert.DeserializeObject<GroupUpResponseDTO>(response);
onSuccessDelegate(assignment, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse assignment, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void GetGroupAsync(
string groupID,
Action<GroupDetailResponse, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Get(
$"{BaseUrl}/{PATH_GROUP_UP}/{groupID}",
AuthToken,
(string response, UnityWebRequest request) =>
{
try
{
GroupDetailResponse details =
JsonConvert.DeserializeObject<GroupDetailResponse>(response);
onSuccessDelegate(details, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse details, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void DeleteGroupAsync(
string groupID,
Action<UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Delete(
$"{BaseUrl}/{PATH_GROUP_UP}/{groupID}",
AuthToken,
(string response, UnityWebRequest request) =>
{
onSuccessDelegate(request);
},
onErrorDelegate
);
}

public void CreateGroupMemberAsync(
T member,
string groupID,
Action<GroupUpResponseDTO, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Post(
$"{BaseUrl}/{PATH_GROUP_UP}/{groupID}",
AuthToken,
JsonConvert.SerializeObject(member),
(string response, UnityWebRequest request) =>
{
try
{
GroupUpResponseDTO assignment =
JsonConvert.DeserializeObject<GroupUpResponseDTO>(response);
onSuccessDelegate(assignment, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse assignment, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void GetGroupMemberDetailsAsync(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you simplify the method names? including the other new group methods.

Suggested change
public void GetGroupMemberDetailsAsync(
public void GetGroupMember(

detail seems a little unnecessary, and there's no need to repeat async everywhere that's just a legacy pattern from the matchmaking SDK. All the methods are now async using the same pattern so mentioning it everywhere is a little redundant.

string groupID,
string memberID,
Action<GroupUpResponseDTO, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Get(
$"{BaseUrl}/{PATH_GROUP_UP}/{groupID}/members/{memberID}",
AuthToken,
(string response, UnityWebRequest request) =>
{
try
{
GroupUpResponseDTO details =
JsonConvert.DeserializeObject<GroupUpResponseDTO>(response);
onSuccessDelegate(details, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse details, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void UpdateGroupMemberAsync(
string groupID,
string memberID,
bool isReady,
Action<GroupUpResponseDTO, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Patch(
$"{BaseUrl}/{PATH_GROUP_UP}/{groupID}/members/{memberID}",
AuthToken,
JsonConvert.SerializeObject(new KeyValuePair<string, bool>("is_ready", isReady)),
(string response, UnityWebRequest request) =>
{
try
{
GroupUpResponseDTO assignment =
JsonConvert.DeserializeObject<GroupUpResponseDTO>(response);
onSuccessDelegate(assignment, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse assignment, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void DeleteGroupMemberAsync(
string groupID,
string memberID,
Action<UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Delete(
$"{BaseUrl}/{PATH_GROUP_UP}/{groupID}/members/{memberID}",
AuthToken,
(string response, UnityWebRequest request) =>
{
onSuccessDelegate(request);
},
onErrorDelegate
);
}
}
}
2 changes: 2 additions & 0 deletions Runtime/Matchmaking/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void ResumeMatchmaking(TicketResponseDTO assignment, bool abandon = false
});
}

[Obsolete("Managing group tickets in clients is deprecated, please use Group Up flow instead.")]
public void StartGroupMatchmaking(
T hostTicket,
List<T> memberTickets,
Expand Down Expand Up @@ -199,6 +200,7 @@ public void StartGroupMatchmaking(
});
}

[Obsolete("Managing group tickets in clients is deprecated, please use Group Up flow instead.")]
public void JoinGroupMatchmaking(TicketResponseDTO assignment, bool abandon = false)
{
ResumeMatchmaking(assignment, abandon);
Expand Down
57 changes: 57 additions & 0 deletions Runtime/Matchmaking/DTOs/GroupUpResponseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Edgegap.Matchmaking
{
public class GroupUpResponseDTO
{
[JsonProperty("member_id")]
public string MemberID;

[JsonProperty("group_id")]
public string GroupID;

[JsonProperty("is_ready")]
public bool IsReady;

[JsonProperty("status")]
public string Status;

#nullable enable
[JsonProperty("ticket_id")]
public string? TicketID;

[JsonProperty("assignment")]
public DeploymentDTO? Assignment;

[JsonProperty("team_id")]
public string? TeamID;
#nullable disable

public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}

public class GroupDetailResponse
{
[JsonProperty("status")]
public string Status;

#nullable enable
[JsonProperty("assignment")]
public DeploymentDTO? Assignment;

[JsonProperty("team_id")]
public string? TeamID;
#nullable disable

public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
}

2 changes: 2 additions & 0 deletions Runtime/Matchmaking/DTOs/GroupUpResponseDTO.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Runtime/Matchmaking/DTOs/TicketsRequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,25 @@ public override string ToString()
return JsonConvert.SerializeObject(this);
}
}

public abstract class GroupUpRequestDTO<A> : TicketsRequestDTO<A>
{
[JsonProperty("is_ready")]
public bool IsReady;

public GroupUpRequestDTO(string profile, bool isReady = false)
: base(profile)
{
IsReady = isReady;
}
}

public class SimpleGroupUpRequestDTO : GroupUpRequestDTO<LatenciesAttributesDTO>
{
public SimpleGroupUpRequestDTO(Dictionary<string, float> latencyBeacons)
: base("simple-example")
{
Attributes = new LatenciesAttributesDTO(latencyBeacons);
}
}
}