Skip to content

Commit 6ba2aee

Browse files
committed
review: split method for session joining
1 parent b49aea5 commit 6ba2aee

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

Assets/Scripts/Gameplay/UI/Session/SessionUIMediator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public async void JoinSessionWithCodeRequest(string sessionCode)
150150

151151
m_ConnectionManager.StartClientSession(m_LocalUser.DisplayName);
152152

153-
var result = await m_MultiplayerServicesFacade.TryJoinSessionAsync(sessionCode, null);
153+
var result = await m_MultiplayerServicesFacade.TryJoinSessionByCodeAsync(sessionCode);
154154

155155
HandleSessionJoinResult(result);
156156
}
@@ -169,7 +169,7 @@ public async void JoinSessionRequest(ISessionInfo sessionInfo)
169169

170170
m_ConnectionManager.StartClientSession(m_LocalUser.DisplayName);
171171

172-
var result = await m_MultiplayerServicesFacade.TryJoinSessionAsync(null, sessionInfo.Id);
172+
var result = await m_MultiplayerServicesFacade.TryJoinSessionByNameAsync(sessionInfo.Id);
173173

174174
HandleSessionJoinResult(result);
175175
}

Assets/Scripts/UnityServices/Sessions/MultiplayerServicesFacade.cs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,36 +138,60 @@ public void EndTracking()
138138
}
139139

140140
/// <summary>
141-
/// Attempt to join an existing session. Will try to join via code, if code is null - will try to join via ID.
141+
/// Attempt to join an existing session with a join code.
142142
/// </summary>
143-
public async Task<(bool Success, ISession Session)> TryJoinSessionAsync(string sessionCode, string sessionId)
143+
public async Task<(bool Success, ISession Session)> TryJoinSessionByCodeAsync(string sessionCode)
144144
{
145145
if (!m_RateLimitJoin.CanCall)
146146
{
147147
Debug.LogWarning("Join Session hit the rate limit.");
148148
return (false, null);
149149
}
150150

151-
if (sessionId == null && sessionCode == null)
151+
if (string.IsNullOrEmpty(sessionCode))
152152
{
153-
Debug.LogWarning("Cannot join a Session without a join code or session ID.");
153+
Debug.LogWarning("Cannot join a Session without a join code.");
154154
return (false, null);
155155
}
156156

157-
Debug.Log($"Joining session with session code {sessionCode}");
157+
Debug.Log($"Joining session with join code {sessionCode}");
158158

159159
try
160160
{
161-
if (!string.IsNullOrEmpty(sessionCode))
162-
{
163-
var session = await m_MultiplayerServicesInterface.JoinSessionByCode(sessionCode, m_LocalUser.GetDataForUnityServices());
164-
return (true, session);
165-
}
166-
else
167-
{
168-
var session = await m_MultiplayerServicesInterface.JoinSessionById(sessionId, m_LocalUser.GetDataForUnityServices());
169-
return (true, session);
170-
}
161+
var session = await m_MultiplayerServicesInterface.JoinSessionByCode(sessionCode, m_LocalUser.GetDataForUnityServices());
162+
return (true, session);
163+
}
164+
catch (Exception e)
165+
{
166+
PublishError(e);
167+
}
168+
169+
return (false, null);
170+
}
171+
172+
/// <summary>
173+
/// Attempt to join an existing session by name.
174+
/// </summary>
175+
public async Task<(bool Success, ISession Session)> TryJoinSessionByNameAsync(string sessionName)
176+
{
177+
if (!m_RateLimitJoin.CanCall)
178+
{
179+
Debug.LogWarning("Join Session hit the rate limit.");
180+
return (false, null);
181+
}
182+
183+
if (string.IsNullOrEmpty(sessionName))
184+
{
185+
Debug.LogWarning("Cannot join a Session without a session name.");
186+
return (false, null);
187+
}
188+
189+
Debug.Log($"Joining session with name {sessionName}");
190+
191+
try
192+
{
193+
var session = await m_MultiplayerServicesInterface.JoinSessionById(sessionName, m_LocalUser.GetDataForUnityServices());
194+
return (true, session);
171195
}
172196
catch (Exception e)
173197
{
@@ -440,4 +464,4 @@ void PublishError(Exception e, bool checkIfDeleted = false)
440464
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Session Error", reason, UnityServiceErrorMessage.Service.Session, e));
441465
}
442466
}
443-
}
467+
}

0 commit comments

Comments
 (0)