More organized communication strategy.

This commit is contained in:
2021-02-13 19:14:43 -06:00
parent 1826c07601
commit d76e4f7a8b
13 changed files with 212 additions and 173 deletions

View File

@@ -28,7 +28,6 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
public async Task Handle(WebSocket socket, string json, string userName)
{
logger.LogInformation("Socket Request \n{0}\n", new[] { json });
var request = JsonConvert.DeserializeObject<JoinByCode>(json);
var joinGameResponse = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
{
@@ -46,9 +45,8 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
PlayerName = userName,
GameName = gameName
};
var serialized = JsonConvert.SerializeObject(response);
await communicationManager.BroadcastToGame(gameName, serialized);
communicationManager.SubscribeToGame(socket, gameName, userName);
// At this time, userName hasn't subscribed and won't receive this broadcasted messages.
await communicationManager.BroadcastToGame(gameName, response);
// But the player joining sees the JoinByCode occur.
response = new JoinGameResponse(ClientAction.JoinByCode)
@@ -56,7 +54,8 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
PlayerName = userName,
GameName = gameName
};
serialized = JsonConvert.SerializeObject(response);
var serialized = JsonConvert.SerializeObject(response);
logger.LogInformation("Response to {0} \n{1}\n", userName, serialized);
await socket.SendTextAsync(serialized);
}
else
@@ -67,7 +66,7 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
Error = "Error joining game."
};
var serialized = JsonConvert.SerializeObject(response);
logger.LogInformation("Socket Response \n{0}\n", new[] { serialized });
logger.LogInformation("Response to {0} \n{1}\n", userName, serialized);
await socket.SendTextAsync(serialized);
}
}