using System;
using System.Threading.Tasks;
using Aurora.Proto.Sync;
using Aurora.Proto.General;
using Aurora.Services.Player;
using Aurora;
using Autofac;
namespace Aurora.RemoteImpl
{
public class RemoteSyncServiceImpl : RemoteSyncService.RemoteSyncServiceBase
{
///
/// RPC for getting a stream of media syncs
///
///
///
///
///
public override async Task GetMediaSync(Empty request,
Grpc.Core.IServerStreamWriter responseStream,
Grpc.Core.ServerCallContext context)
{
using (var scope = App.Container.BeginLifetimeScope())
{
IPlayer player = scope.Resolve();
bool continueSync = true;
string currentId = player.CurrentMedia.Id;
MediaChangedEventHandler mediaChanged = (sender, e) =>
{
if (e.NewId != currentId)
{
continueSync = false;
}
};
player.MediaChanged += mediaChanged;
while (continueSync)
{
float length = player.CurrentMediaLength;
Sync sync = new Sync()
{
TrackPosition = player.CurrentMediaPosition,
ServerTimeTicks = Utils.TimeUtils.GetNetworkTime().DateTime.Ticks
};
await responseStream.WriteAsync(sync);
Console.WriteLine("Sent Sync");
await Task.Delay(5000);
}
}
}
}
}