diff --git a/YJMPD-UWP/Model/ApiHandler.cs b/YJMPD-UWP/Model/ApiHandler.cs index 4bcd1b3..fad2095 100644 --- a/YJMPD-UWP/Model/ApiHandler.cs +++ b/YJMPD-UWP/Model/ApiHandler.cs @@ -20,6 +20,7 @@ namespace YJMPD_UWP.Model Hi, Name, Picture, + Msg, GameFound, PlayerJoined } @@ -31,6 +32,7 @@ namespace YJMPD_UWP.Model public void HandleMessage(JObject o) { + Debug.WriteLine("Reached HandleMessage in API"); Command c = (Command)Enum.Parse(typeof(Command), o["command"].ToString()); switch(c) @@ -39,7 +41,8 @@ namespace YJMPD_UWP.Model GameFound(); break; case Command.PlayerJoined: - PlayerJoined(o["msg"].ToString()); + Debug.WriteLine("Played joined"); + PlayerJoined(o[Command.PlayerJoined.ToString()].ToString()); break; default: //Do nothing @@ -50,7 +53,6 @@ namespace YJMPD_UWP.Model private void PlayerJoined(string username) { - throw new NotImplementedException(); //Event will be handled by the game manager App.Game.AddPlayer(username); } diff --git a/YJMPD-UWP/Model/NetworkHandler.cs b/YJMPD-UWP/Model/NetworkHandler.cs index abe0ba1..f5a4a04 100644 --- a/YJMPD-UWP/Model/NetworkHandler.cs +++ b/YJMPD-UWP/Model/NetworkHandler.cs @@ -83,12 +83,12 @@ namespace YJMPD_UWP.Model BackgroundReader = Windows.System.Threading.ThreadPool.RunAsync(async (workItem) => { - while (workItem.Status == AsyncStatus.Started) + while (true) { Debug.WriteLine("Awaiting incoming data..."); string data = await App.Network.Read(); App.Network.HandleMessage(data); - Task.Delay(TimeSpan.FromMilliseconds(50)); + await Task.Delay(TimeSpan.FromMilliseconds(50)); } }); @@ -114,10 +114,8 @@ namespace YJMPD_UWP.Model { Debug.WriteLine(data); JObject o = JObject.Parse(data); - if (o["msg"].ToString() == "ok") - { - App.Api.HandleMessage(o); - } + App.Api.HandleMessage(o); + } } }