// Constructor public MessageStream(TransportType transport = TransportType.LONGPOLLING) { // InitializeMessageList(); // Start transport client when session is acquired Mage.EventManager.On("session.set", (sender, session) => { sessionKey = UnityEngine.WWW.EscapeURL(session["key"].ToString()); transportClient.Start(); }); // Stop the message client when session is lost Mage.EventManager.On("session.unset", (sender, reason) => { transportClient.Stop(); InitializeMessageList(); sessionKey = null; }); // Also stop the message client when the application is stopped #if UNITY_EDITOR UnityEditorPlayMode.OnEditorModeChanged += newState => { if (newState == EditorPlayModeState.Stopped) { transportClient.Stop(); InitializeMessageList(); sessionKey = null; } if (newState == EditorPlayModeState.Paused && transportClient.running) { transportClient.Stop(); } if (newState == EditorPlayModeState.Playing && !transportClient.running && sessionKey != null) { transportClient.Start(); } }; #endif UnityApplicationState.Instance.OnAppStateChanged += pauseStatus => { if (pauseStatus && transportClient.running) { transportClient.Stop(); } if (!pauseStatus && !transportClient.running && sessionKey != null) { transportClient.Start(); } }; // Set the selected transport client (or the default) SetTransport(transport); }