Ejemplo n.º 1
0
        public async Task SocketDisconnected(WebSocket socket)
        {
            var mySocket = GetMySocket(socket);

            var sessionId = mySocket.SessionId;
            var userId    = mySocket.UserId;

            var remainingSocketsInSession = RemoveSocketFromDataStructures(mySocket);

            var updatedSession = await _db.RemoveUserFromSessionAsync(sessionId, userId);

            // TODO: inneficient, everything with this db access layer is inneficient
            var user = _db.GetUser(userId);

            if (user.Temporary)
            {
                await _db.DeleteUserAsync(userId);
            }

            var sessionV1 = updatedSession.ToContract();

            if (remainingSocketsInSession.Count > 0)
            {
                await _wsSender.clientUpdateUsersList(sessionV1.Users, remainingSocketsInSession);
            }
            else
            {
                DeactiveSession(sessionId);
            }
        }
Ejemplo n.º 2
0
        public async Task JoinSession(MySocket socket, string sessionName)
        {
            Session session      = null;
            bool    sessionFound = _db.GetSessionByName(sessionName, out session);

            if (!sessionFound)
            {
                session = await _db.CreateSessionAsync(sessionName);
            }
            var userName = "******";
            var user     = await _db.AddNewUserToSessionAsync(userName, session);

            var sessionId = session.SessionID;

            _myContext.SocketJoinSession(socket, sessionId, user.MyUserId);

            var sessionV1 = session.ToContract();
            await _sender.clientSessionReady(sessionV1, user.ToContract(), socket);

            await _sender.clientUpdateUsersList(sessionV1.Users, _myContext.GetSocketsInSession(sessionId));
        }