using System;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using Grpc.Core;
using Xamarin.Forms;
using Aurora.Services.EventManager;
using Aurora.Services.Library;
using Aurora.Services.Settings;
using Aurora.Services;
using Aurora.Proto.Party;
using Aurora.Models.Media;
using Aurora.Services.Controllers;
using Aurora.Utils;
namespace Aurora.Design.Views.Party
{
public class HostPartyViewModel : BasePartyViewModel
{
private IEventManager _eventManager;
private ILibraryService _libraryService;
private Grpc.Core.Server _server;
private RemotePartyController _remotePartyController;
private Channel _channel;
private int _port = 8080;
private bool _isServerStarted = false;
public HostPartyViewModel(
ISettingsService settingsService,
IEventManager eventManager,
ILibraryService libraryService,
Global global
): base(settingsService, global)
{
this._eventManager = eventManager;
this._global.State = PartyState.Hosting;
this._libraryService = libraryService;
// Create and start grpc server
string host = IpUtil.GetLocalIPAddress();
if(string.IsNullOrWhiteSpace(host))
{
// TODO display error to screen
throw new System.Exception("This device does not have a valid IP address");
}
this._hostname = IpUtil.GetLocalIPAddress();
this.StartServer("test", "test description");
// TODO assign members
// TODO assign songList
// Register commands
PlayCommand = new Command(OnDoubleClickCommandExecute, CanDoubleClickCommandExecute);
LeavePartyCommand = new Command(OnLeavePartyCommandExecute, CanLeavePartyCommandExecute);
}
#region Properties
///
/// Public property for playing media command
///
///
public Command PlayCommand { get; private set; }
///
/// Public property for leave party command
///
///
public Command LeavePartyCommand { get; private set; }
#endregion Properties
///
/// Called by framework when view becomes active
///
///
public override Task OnActive()
{
// Start server if not already started
if(!this._isServerStarted)
{
this._hostname = IpUtil.GetLocalIPAddress();
this.StartServer("test", "test description");
}
return Task.FromResult