public async Task ConnectAsync(string mothershipName, Action onNameAssignedAction)
        {
            m_onNameAssignedAction   = onNameAssignedAction;
            m_deviceSocketConnection = await DeviceSocketConnection.CreateAsync(WebUrls.ClientSocketUrl(mothershipName));

            m_deviceSocketConnection.OnMessageReceived += M_deviceSocketConnection_OnMessageReceived;
            m_deviceSocketConnection.OnSocketClosed    += M_deviceSocketConnection_OnSocketClosed;
            m_deviceSocketConnection.RunReceiveLoop();
        }
        public static async Task <MainViewModel> CreateAsync(ConnectingToWebAppPage connectingPage)
        {
            connectingPage.WriteLog("Loading host config...");
            CardViewModel.HOST_CONFIG_JSON = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///HostConfigs/HostConfig.json")));

            DeviceSocketConnection deviceSocketConnection;

            try
            {
                connectingPage.WriteLog("Connecting to socket...");
                deviceSocketConnection = await DeviceSocketConnection.CreateAsync(WebUrls.MOTHERSHIP_SOCKET_URL);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to connect to the web server: " + WebUrls.MOTHERSHIP_SOCKET_URL + "\n\n" + ex.ToString());
            }

            connectingPage.WriteLog("Socket connected!");

            var mainViewModel = new MainViewModel(deviceSocketConnection);

            connectingPage.WriteLog("Getting cards folder...");
            var cardsFolder = await Package.Current.InstalledLocation.GetFolderAsync("Cards");

            connectingPage.WriteLog("Enumerating cards...");
            foreach (var file in await cardsFolder.GetFilesAsync())
            {
                if (file.FileType.ToLower().Equals(".json"))
                {
                    connectingPage.WriteLog("Loading card payload...");
                    mainViewModel.GalleryCards.Add(new CardViewModel()
                    {
                        Name     = file.DisplayName,
                        CardJson = await FileIO.ReadTextAsync(file)
                    });
                }
            }

            mainViewModel.QueuedAndCurrentCards.Add(mainViewModel.FindNewCardFromGallery());
            mainViewModel.QueuedAndCurrentCards.Add(mainViewModel.FindNewCardFromGallery());
            mainViewModel.CurrentCard = mainViewModel.QueuedAndCurrentCards.Last();

            // Start the loop
            connectingPage.WriteLog("Starting the card loop...");
            mainViewModel.CycleLoop();

            return(mainViewModel);
        }