@@ -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