示例#1
0
        public static string getPlayListResponse(string token)
        {
            User user = User.getAutentification(token);

            if (user == null)
            {
                return(new ErrorResponse(300, Constants.NetMsg.FORBIDDEN).ToJson());
            }

            Player      player   = Realtime.getInstance().getPlayer(user.id.ToString());
            List <long> playlist = Realtime.getInstance().getPlayList(user.id.ToString());

            if (player == null || playlist == null)
            {
                return(new ErrorResponse(300, Constants.NetMsg.FORBIDDEN).ToJson());
            }

            List <PlaylistEntry> playlistForResponse = playlist.ConvertAll <PlaylistEntry>(el => {
                Track track = player.tracks[el];
                return(new PlaylistEntry()
                {
                    artist = track.artist,
                    dislikes = track.dislikes,
                    duration = track.duration,
                    id = el,
                    likes = track.likes,
                    publisher = track.publisher.name,
                    title = track.title
                });
            });

            return(new PlaylistResponse(playlistForResponse).ToJson());
        }
示例#2
0
        public static string tryConnect(string hubId, string token)
        {
            try {
                User user = User.getAutentification(token);
                Hub  hub  = Hub.get(hubId);

                if (user == null)
                {
                    return(new ErrorResponse(300, Constants.NetMsg.FORBIDDEN).ToJson());
                }
                if (hub == null)
                {
                    return(new ErrorResponse(300, Constants.NetMsg.KEY_NOT_FOUND).ToJson());
                }

                if (Realtime.getInstance().isUserConnected(user.id.ToString()))
                {
                    return(new ErrorResponse(300, Constants.NetMsg.ALREADY_CONNECTED).ToJson());
                }

                Realtime.getInstance().connectToHub(user.id.ToString(), hubId);

                return(new EmptyResponse().ToJson());
            } catch {
                return(new ErrorResponse(210, Constants.NetMsg.KEY_NOT_FOUND).ToJson());
            }
        }
示例#3
0
        public static string getUsers(string token)
        {
            User user = User.getAutentification(token);

            if (user == null)
            {
                return(new ErrorResponse(300, Constants.NetMsg.FORBIDDEN).ToJson());
            }

            string hub = Realtime.getInstance().getUserHub(user.id.ToString());

            if (hub != null)
            {
                return(new ErrorResponse(300, Constants.NetMsg.NOT_CONNECTED).ToJson());
            }

            List <string> hubUserIDs = Realtime.getInstance().getHubUsers(hub);
            List <User>   hubUsers   = hubUserIDs.ConvertAll(User.get);

            return(new UsersResponse(hubUsers).ToJson());
        }
示例#4
0
        public static string tryDisconnect(string token)
        {
            try {
                User user = User.getAutentification(token);

                if (user == null)
                {
                    return(new ErrorResponse(300, Constants.NetMsg.FORBIDDEN).ToJson());
                }

                if (Realtime.getInstance().isUserConnected(user.id.ToString()))
                {
                    return(new ErrorResponse(300, Constants.NetMsg.NOT_CONNECTED).ToJson());
                }

                Realtime.getInstance().disconnect(user.id.ToString());

                return(new EmptyResponse().ToJson());
            } catch {
                return(new ErrorResponse(210, Constants.NetMsg.KEY_NOT_FOUND).ToJson());
            }
        }