Added GetQueue method that returns the hosts library

This commit is contained in:
watsonb8 2019-11-03 16:04:05 -05:00
parent 9a34e31f9c
commit a13e491a7e
4 changed files with 89 additions and 7 deletions

View File

@ -23,7 +23,8 @@
Members="{Binding Members}"/>
<Label
Text="Queue"/>
<qu:Queue/>
<qu:Queue
ItemsSource="{Binding Queue}"/>
</StackLayout>
<hs:HostSelector
Grid.Row="0"

View File

@ -1,16 +1,14 @@
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Threading;
using System.Linq;
using Xamarin.Forms;
using Grpc.Core;
using Aurora.Services;
using Aurora.Proto.General;
using Aurora.Proto.Party;
using Aurora.Proto.Playback;
using Aurora.Proto.Events;
using Aurora.Services.ClientService;
using Aurora.Models.Media;
namespace Aurora.Design.Views.Party
{
@ -27,12 +25,15 @@ namespace Aurora.Design.Views.Party
private string _hostname;
private ObservableCollection<PartyMember> _members;
private ObservableCollection<RemoteMediaData> _queue;
public PartyViewModel()
{
this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute);
this.HostCommand = new Command(OnHostExecute, CanHostExecute);
_members = new ObservableCollection<PartyMember>();
_queue = new ObservableCollection<RemoteMediaData>();
SetState(PartyState.SelectingHost);
@ -69,6 +70,21 @@ namespace Aurora.Design.Views.Party
get { return _state != PartyState.SelectingHost; }
}
public ObservableCollection<RemoteMediaData> Queue
{
get
{
return _queue;
}
set
{
if (value != _queue)
{
SetProperty(ref _queue, value);
}
}
}
public Command JoinCommand { get; set; }
public Command HostCommand { get; set; }
@ -189,6 +205,14 @@ namespace Aurora.Design.Views.Party
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", SettingsService.Instance.ClientId));
ClientService.Instance.RemoteEventClient.SubscribeToEvents(req);
QueueResponse queueResponse = ClientService.Instance.RemotePartyClient.GetQueue(new Empty());
Queue.Clear();
foreach (RemoteMediaData data in queueResponse.MediaList)
{
Queue.Add(data);
}
}
catch (Exception ex)
{

View File

@ -9,6 +9,7 @@ service RemotePartyService {
rpc JoinParty(JoinPartyRequest) returns (JoinPartyResponse);
rpc LeaveParty(LeavePartyRequest) returns (LeavePartyResponse);
rpc GetPartyMembers(Aurora.Proto.General.Empty) returns (MembersResponse);
rpc GetQueue(Aurora.Proto.General.Empty) returns (QueueResponse);
}
message JoinPartyRequest {
@ -34,14 +35,22 @@ message PartyMember {
string ipAddress = 3;
int32 port = 4;
}
message MembersResponse {
repeated PartyMember members = 1;
}
enum PartyJoinedStatusEnum {
Connected = 0;
Disconnected = 1;
}
message QueueResponse{
repeated RemoteMediaData mediaList = 1;
}
message RemoteMediaData {
string title = 1;
string artist = 2;
string album = 3;
string duration = 4;
}

View File

@ -5,6 +5,9 @@ using System.Linq;
using Aurora.Proto.Party;
using Aurora.Proto.Events;
using Aurora.Services.EventManager;
using Aurora.Services;
using Aurora.Models.Media;
using System.Collections;
namespace Aurora.RemoteImpl
{
@ -82,5 +85,50 @@ namespace Aurora.RemoteImpl
response.Members.AddRange(_partyMembers);
return Task.FromResult(response);
}
public override Task<QueueResponse> GetQueue(Proto.General.Empty empty, Grpc.Core.ServerCallContext context)
{
//This will change as queuing operation gets solidified
//Simply return the hosts library
ObservableCollection<BaseMedia> queue = LibraryService.Instance.GetLibrary();
QueueResponse mediaList = new QueueResponse();
foreach (BaseMedia media in queue)
{
AudioMetadata metadata = new AudioMetadata();
try
{
if (media.Metadata is AudioMetadata)
{
metadata = media.Metadata as AudioMetadata;
RemoteMediaData data = new RemoteMediaData();
data.Title = metadata.Title == null ? metadata.Title : "";
if (metadata.Artist != null)
{
data.Artist = metadata.Artist;
}
if (metadata.Album != null)
{
data.Album = metadata.Album;
}
if (metadata.Duration != null)
{
data.Duration = metadata.Duration;
}
mediaList.MediaList.Add(data);
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error preparing queue: {0}", ex.Message));
}
}
return Task.FromResult(mediaList);
}
}
}