Skip to content

Commit 52cc986

Browse files
Added CurrentRoomManager to SharingStage properties.
Updated AutoJoinSessionAndRoom to properly listen for the SharingSessionTracker discconection event instead of the SharingManagers
1 parent be451a0 commit 52cc986

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

Assets/HoloToolkit/Sharing/Scripts/SharingStage.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public string RoomName
6666
{
6767
get
6868
{
69-
return Manager.GetRoomManager() != null && Manager.GetRoomManager().GetCurrentRoom() != null
70-
? Manager.GetRoomManager().GetCurrentRoom().GetName().GetString()
69+
return CurrentRoomManager != null && CurrentRoomManager.GetCurrentRoom() != null
70+
? CurrentRoomManager.GetCurrentRoom().GetName().GetString()
7171
: defaultRoomName;
7272
}
7373
}
@@ -193,9 +193,11 @@ public string UserName
193193
}
194194
}
195195

196+
public RoomManager CurrentRoomManager { get { return Manager != null ? Manager.GetRoomManager() : null; } }
197+
196198
public Room CurrentRoom
197199
{
198-
get { return Manager != null ? Manager.GetRoomManager().GetCurrentRoom() : null; }
200+
get { return CurrentRoomManager != null ? CurrentRoomManager.GetCurrentRoom() : null; }
199201
}
200202

201203
private NetworkConnectionAdapter networkConnectionAdapter;

Assets/HoloToolkit/Sharing/Scripts/Utilities/AutoJoinSessionAndRoom.cs

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace HoloToolkit.Sharing.Utilities
1313
/// </summary>
1414
public class AutoJoinSessionAndRoom : Singleton<AutoJoinSessionAndRoom>
1515
{
16-
private ServerSessionsTracker sessionsTracker;
17-
1816
/// <summary>
1917
/// Some room ID for indicating which room we are in.
2018
/// </summary>
@@ -67,7 +65,7 @@ protected override void OnDestroy()
6765
if (SharingStage.Instance != null)
6866
{
6967
SharingStage.Instance.SharingManagerConnected -= Connected;
70-
SharingStage.Instance.SharingManagerDisconnected -= Disconnected;
68+
SharingStage.Instance.SessionsTracker.ServerDisconnected -= Disconnected;
7169
}
7270

7371
if (autoConnect != null)
@@ -85,20 +83,21 @@ protected override void OnDestroy()
8583
/// <param name="e">Events Arguments.</param>
8684
private void Connected(object sender = null, EventArgs e = null)
8785
{
88-
StopCoroutine(autoConnect);
86+
if (autoConnect != null)
87+
{
88+
StopCoroutine(autoConnect);
89+
}
90+
8991
SharingStage.Instance.SharingManagerConnected -= Connected;
90-
SharingStage.Instance.SharingManagerDisconnected += Disconnected;
92+
SharingStage.Instance.SessionsTracker.ServerDisconnected += Disconnected;
9193
}
9294

9395
/// <summary>
94-
/// Called when the sharing stage connects to a server.
96+
/// Called when the Session Tracker connects to a server.
9597
/// </summary>
96-
/// <param name="sender">Sender.</param>
97-
/// <param name="e">Events Arguments.</param>
98-
private void Disconnected(object sender = null, EventArgs e = null)
98+
private void Disconnected()
9999
{
100-
Debug.LogError("[AutoJoinSession] Disconnected!");
101-
SharingStage.Instance.SharingManagerDisconnected -= Disconnected;
100+
SharingStage.Instance.SessionsTracker.ServerDisconnected -= Disconnected;
102101
SharingStage.Instance.SharingManagerConnected += Connected;
103102

104103
if (SharingStage.Instance.ClientRole == ClientRole.Primary)
@@ -109,7 +108,11 @@ private void Disconnected(object sender = null, EventArgs e = null)
109108

110109
private IEnumerator AutoConnect()
111110
{
112-
Debug.LogWarning("[AutoJoinSession] Attempting to connect...");
111+
if (SharingStage.Instance.ShowDetailedLogs)
112+
{
113+
Debug.Log("[AutoJoinSession] Attempting to connect...");
114+
}
115+
113116
if (SharingStage.Instance.SessionsTracker == null)
114117
{
115118
if (SharingStage.Instance.ShowDetailedLogs)
@@ -125,17 +128,14 @@ private IEnumerator AutoConnect()
125128
yield return null;
126129
}
127130

128-
// Get the ServerSessionsTracker to use later.
129-
sessionsTracker = SharingStage.Instance.SessionsTracker;
130-
131-
if (sessionsTracker.IsServerConnected)
131+
if (SharingStage.Instance.SessionsTracker.IsServerConnected)
132132
{
133133
if (SharingStage.Instance.ShowDetailedLogs)
134134
{
135135
Debug.LogFormat("[AutoJoinSession] Looking for {0}...", SharingStage.Instance.SessionName);
136136

137137
Debug.LogFormat("[AutoJoinSession] Successfully connected to server with {0} Sessions.",
138-
sessionsTracker.Sessions.Count.ToString());
138+
SharingStage.Instance.SessionsTracker.Sessions.Count.ToString());
139139
}
140140
}
141141
else
@@ -145,20 +145,20 @@ private IEnumerator AutoConnect()
145145
Debug.LogWarning("[AutoJoinSession] Disconnected from server. Waiting for a connection... ");
146146
}
147147

148-
while (!sessionsTracker.IsServerConnected)
148+
while (!SharingStage.Instance.SessionsTracker.IsServerConnected)
149149
{
150150
yield return null;
151151
}
152152

153153
if (SharingStage.Instance.ShowDetailedLogs)
154154
{
155-
Debug.LogWarning("[AutoJoinSession] Connected!");
155+
Debug.Log("[AutoJoinSession] Connected!");
156156
}
157157
}
158158

159159
// If we are a Primary Client and can join sessions...
160160
// Check to see if we aren't already in the desired session
161-
Session currentSession = sessionsTracker.GetCurrentSession();
161+
Session currentSession = SharingStage.Instance.SessionsTracker.GetCurrentSession();
162162

163163
// We're not in a valid session.
164164
if (currentSession == null)
@@ -168,9 +168,9 @@ private IEnumerator AutoConnect()
168168
Debug.Log("[AutoJoinSession] Didn't find the session, making a new one...");
169169
}
170170

171-
yield return sessionsTracker.CreateSession(new XString(SharingStage.Instance.SessionName));
171+
yield return SharingStage.Instance.SessionsTracker.CreateSession(new XString(SharingStage.Instance.SessionName));
172172

173-
currentSession = sessionsTracker.GetCurrentSession();
173+
currentSession = SharingStage.Instance.SessionsTracker.GetCurrentSession();
174174
}
175175

176176
// We're already in the Session we're searching for.
@@ -197,9 +197,9 @@ private IEnumerator AutoConnect()
197197
yield break;
198198
}
199199

200-
for (int i = 0; i < sessionsTracker.Sessions.Count; ++i)
200+
for (int i = 0; i < SharingStage.Instance.SessionsTracker.Sessions.Count; ++i)
201201
{
202-
if (sessionsTracker.Sessions[i].GetName().GetString() != SharingStage.Instance.SessionName)
202+
if (SharingStage.Instance.SessionsTracker.Sessions[i].GetName().GetString() != SharingStage.Instance.SessionName)
203203
{
204204
continue;
205205
}
@@ -209,7 +209,7 @@ private IEnumerator AutoConnect()
209209
Debug.LogFormat("[AutoJoinSession] Joining session {0}...", SharingStage.Instance.SessionName);
210210
}
211211

212-
yield return sessionsTracker.JoinSession(sessionsTracker.Sessions[i]);
212+
yield return SharingStage.Instance.SessionsTracker.JoinSession(SharingStage.Instance.SessionsTracker.Sessions[i]);
213213
}
214214

215215
while (currentSession != null && currentSession.GetMachineSessionState() != MachineSessionState.JOINED)
@@ -222,12 +222,15 @@ private IEnumerator AutoConnect()
222222
Debug.LogFormat("[AutoJoinSession] Joined session {0} successfully!", SharingStage.Instance.SessionName);
223223
}
224224

225-
var roomManager = SharingStage.Instance.Manager.GetRoomManager();
226-
227225
// First check if there is a current room
228-
var currentRoom = roomManager.GetCurrentRoom();
226+
var currentRoom = SharingStage.Instance.CurrentRoom;
229227

230-
if (currentRoom == null || roomManager.GetRoomCount() == 0)
228+
while (SharingStage.Instance.CurrentRoom != null)
229+
{
230+
yield return null;
231+
}
232+
233+
if (currentRoom == null || SharingStage.Instance.CurrentRoomManager.GetRoomCount() == 0)
231234
{
232235
// If we are the user with the lowest user ID, we will create the room.
233236
if (ShouldLocalUserCreateRoom)
@@ -239,22 +242,22 @@ private IEnumerator AutoConnect()
239242

240243
// To keep anchors alive even if all users have left the session...
241244
// Pass in true instead of false in CreateRoom.
242-
currentRoom = roomManager.CreateRoom(
245+
currentRoom = SharingStage.Instance.CurrentRoomManager.CreateRoom(
243246
new XString(SharingStage.Instance.RoomName),
244247
roomID,
245248
SharingStage.Instance.KeepRoomAlive);
246249
}
247250
}
248-
else if (roomManager.GetRoomCount() > 0)
251+
else if (SharingStage.Instance.CurrentRoomManager.GetRoomCount() > 0)
249252
{
250253
// Look through the existing rooms and join the one that matches the room name provided.
251-
for (int i = 0; i < roomManager.GetRoomCount(); i++)
254+
for (int i = 0; i < SharingStage.Instance.CurrentRoomManager.GetRoomCount(); i++)
252255
{
253-
if (roomManager.GetRoom(i).GetName().GetString().Equals(SharingStage.Instance.RoomName,
256+
if (SharingStage.Instance.CurrentRoomManager.GetRoom(i).GetName().GetString().Equals(SharingStage.Instance.RoomName,
254257
StringComparison.OrdinalIgnoreCase))
255258
{
256-
currentRoom = roomManager.GetRoom(i);
257-
roomManager.JoinRoom(currentRoom);
259+
currentRoom = SharingStage.Instance.CurrentRoomManager.GetRoom(i);
260+
SharingStage.Instance.CurrentRoomManager.JoinRoom(currentRoom);
258261

259262
if (SharingStage.Instance.ShowDetailedLogs)
260263
{
@@ -272,11 +275,6 @@ private IEnumerator AutoConnect()
272275
yield break;
273276
}
274277

275-
while (currentRoom != SharingStage.Instance.CurrentRoom)
276-
{
277-
yield return null;
278-
}
279-
280278
if (SharingStage.Instance.ShowDetailedLogs)
281279
{
282280
Debug.LogFormat("[AutoJoinSession] Joined room {0} successfully!", currentRoom.GetName().GetString());

0 commit comments

Comments
 (0)