50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Aurora.Proto.Sync;
|
|
using Aurora.Proto.General;
|
|
using Aurora.Services.PlayerService;
|
|
|
|
namespace Aurora.RemoteImpl
|
|
{
|
|
public class RemoteSyncServiceImpl : RemoteSyncService.RemoteSyncServiceBase
|
|
{
|
|
/// <summary>
|
|
/// RPC for getting a stream of media syncs
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="responseStream"></param>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
public override async Task GetMediaSync(Empty request,
|
|
Grpc.Core.IServerStreamWriter<Sync> responseStream,
|
|
Grpc.Core.ServerCallContext context)
|
|
{
|
|
bool continueSync = true;
|
|
string currentId = PlayerService.Instance.CurrentMedia.Id;
|
|
MediaChangedEventHandler mediaChanged = (sender, e) =>
|
|
{
|
|
if (e.NewId != currentId)
|
|
{
|
|
continueSync = false;
|
|
}
|
|
};
|
|
|
|
PlayerService.Instance.MediaChanged += mediaChanged;
|
|
|
|
while (continueSync)
|
|
{
|
|
Utils.Time networkTime = Utils.TimeUtils.GetNetworkTime();
|
|
float length = PlayerService.Instance.CurrentMediaLength;
|
|
|
|
Sync sync = new Sync()
|
|
{
|
|
TrackTime = length * PlayerService.Instance.CurrentMediaPosition,
|
|
ServerTime = networkTime.DateTime.Ticks + networkTime.Elapsed.Ticks
|
|
};
|
|
await responseStream.WriteAsync(sync);
|
|
Console.WriteLine("Sent Sync");
|
|
await Task.Delay(5000);
|
|
}
|
|
}
|
|
}
|
|
} |