Exemplo n.º 1
0
        public async Task JoinSession(string sessionId, string userId, bool sync)
        {
            if (sessionId == null)
            {
                sessionId = "null";
            }
            if (userId == null)
            {
                userId = "null";
            }

            if (SessionHandler.IsValidSession(sessionId) && SessionHandler.GetUsersSession(userId) != sessionId)
            {
                userId = SessionHandler.CreateAndAddUser(sessionId);
                await Groups.AddToGroupAsync(Context.ConnectionId, sessionId);

                await Clients.Caller.SendAsync("SessionJoined", true, sessionId, userId, SessionHandler.GetPermissions(sessionId).PermissionsToDict());
            }
            else if (SessionHandler.GetUsersSession(userId) == sessionId && sessionId != "")
            {
                await Groups.AddToGroupAsync(Context.ConnectionId, sessionId);

                await Clients.Caller.SendAsync("SessionJoined", true, sessionId, userId, SessionHandler.GetPermissions(sessionId).PermissionsToDict(), SessionHandler.IsHostUser(sessionId, userId));
            }
            else if (!sync)
            {
                await Clients.Caller.SendAsync("SessionJoined", false);
            }
        }
Exemplo n.º 2
0
        public async Task CreateSession(string userId, bool[] permissions)
        {
            if (SessionHandler.GetUsersSession(userId) == "")
            {
                string sessionId = SessionHandler.CreateSession(permissions);
                userId = SessionHandler.CreateAndAddUser(sessionId);
                SessionHandler.AddHostUser(sessionId, userId);
                await Groups.AddToGroupAsync(Context.ConnectionId, sessionId);

                await Clients.Caller.SendAsync("SessionCreated", sessionId, userId);
            }
        }