viewing of others code working

This commit is contained in:
2021-07-22 20:41:12 -04:00
parent 59e5bf2585
commit 2d36f0d2f6
6 changed files with 75 additions and 24 deletions

View File

@ -7,38 +7,51 @@ namespace BinaryDad.Coding.Hubs
{
public class CodeHub : Hub
{
private static readonly IDictionary<string, User> users = new Dictionary<string, User>(StringComparer.OrdinalIgnoreCase);
public Task UpdateCode(string user, int index, string code)
public Task UpdateCode(string user, int index, string code, bool isTeacher)
{
return Clients.All.SendAsync("ReceiveCode", user, index, code);
if (index == 0)
{
Users.Sessions[Context.ConnectionId].Html = code;
}
else if (index == 1)
{
Users.Sessions[Context.ConnectionId].Css = code;
}
if (isTeacher)
{
return Clients.All.SendAsync("ReceiveCode", user, index, code);
}
return null;
}
public async Task SaveName(string name, string color)
{
users[Context.ConnectionId].Name = name;
users[Context.ConnectionId].Color = color;
Users.Sessions[Context.ConnectionId].Id = Context.ConnectionId;
Users.Sessions[Context.ConnectionId].Name = name;
Users.Sessions[Context.ConnectionId].Color = color;
await Clients.All.SendAsync("UsersList", users);
await Clients.All.SendAsync("UsersList", Users.Sessions);
}
public override async Task OnConnectedAsync()
{
users[Context.ConnectionId] = new User
Users.Sessions[Context.ConnectionId] = new User
{
Name = ""
};
await Clients.All.SendAsync("UsersList", users);
await Clients.All.SendAsync("UsersList", Users.Sessions);
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
users.Remove(Context.ConnectionId);
Users.Sessions.Remove(Context.ConnectionId);
await Clients.All.SendAsync("UsersList", users);
await Clients.All.SendAsync("UsersList", Users.Sessions);
await base.OnDisconnectedAsync(exception);
}