First pass at sync working. Need to ignore for special cases
This commit is contained in:
@ -23,7 +23,9 @@ namespace Aurora.RemoteImpl
|
||||
/// <param name="responseStream">The response stream</param>
|
||||
/// <param name="context">gRPC client context</param>
|
||||
/// <returns></returns>
|
||||
public async override Task GetEvents(EventsRequest request, Grpc.Core.IServerStreamWriter<BaseEvent> responseStream, Grpc.Core.ServerCallContext context)
|
||||
public async override Task GetEvents(EventsRequest request,
|
||||
Grpc.Core.IServerStreamWriter<BaseEvent> responseStream,
|
||||
Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
string peerId = Combine(new string[] { context.Peer, request.ClientId });
|
||||
Console.WriteLine(string.Format("SERVER - Events request received from peer: {0}", peerId));
|
||||
|
@ -135,24 +135,5 @@ namespace Aurora.RemoteImpl
|
||||
return Task.FromResult(mediaList);
|
||||
|
||||
}
|
||||
|
||||
public override async Task GetSongStream(SongRequest request,
|
||||
Grpc.Core.IServerStreamWriter<Chunk> responseStream,
|
||||
Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
BaseMedia song = LibraryService.Instance.GetSong(request.Id);
|
||||
await song.Load();
|
||||
|
||||
//Send stream
|
||||
Console.WriteLine("Begin sending file");
|
||||
byte[] buffer = new byte[2048]; // read in chunks of 2KB
|
||||
int bytesRead;
|
||||
while ((bytesRead = song.DataStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
Google.Protobuf.ByteString bufferByteString = Google.Protobuf.ByteString.CopyFrom(buffer);
|
||||
await responseStream.WriteAsync(new Chunk { Content = bufferByteString });
|
||||
}
|
||||
Console.WriteLine("Done sending file");
|
||||
}
|
||||
}
|
||||
}
|
33
Aurora/RemoteImpl/RemotePlaybackImpl.cs
Normal file
33
Aurora/RemoteImpl/RemotePlaybackImpl.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using Aurora.Services;
|
||||
using Aurora.Proto.Playback;
|
||||
using Aurora.Proto.General;
|
||||
using Aurora.Models.Media;
|
||||
|
||||
namespace Aurora.RemoteImpl
|
||||
{
|
||||
public class RemotePlaybackServiceImpl : RemotePlaybackService.RemotePlaybackServiceBase
|
||||
{
|
||||
public override async Task GetSongStream(SongRequest request,
|
||||
Grpc.Core.IServerStreamWriter<Chunk> responseStream,
|
||||
Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
BaseMedia song = LibraryService.Instance.GetSong(request.Id);
|
||||
await song.Load();
|
||||
|
||||
//Send stream
|
||||
Console.WriteLine("Begin sending file");
|
||||
byte[] buffer = new byte[2048]; // read in chunks of 2KB
|
||||
int bytesRead;
|
||||
while ((bytesRead = song.DataStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
Google.Protobuf.ByteString bufferByteString = Google.Protobuf.ByteString.CopyFrom(buffer);
|
||||
await responseStream.WriteAsync(new Chunk { Content = bufferByteString });
|
||||
}
|
||||
Console.WriteLine("Done sending file");
|
||||
}
|
||||
}
|
||||
}
|
48
Aurora/RemoteImpl/RemoteSyncImpl.cs
Normal file
48
Aurora/RemoteImpl/RemoteSyncImpl.cs
Normal file
@ -0,0 +1,48 @@
|
||||
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 songIsPlaying = true;
|
||||
PlaybackStateChangedEventHandler playbackStateChanged = (sender, e) =>
|
||||
{
|
||||
songIsPlaying = false;
|
||||
};
|
||||
|
||||
PlayerService.Instance.PlaybackStateChanged += playbackStateChanged;
|
||||
|
||||
while (songIsPlaying)
|
||||
{
|
||||
DateTime time = Utils.TimeUtils.GetNetworkTime();
|
||||
float position = PlayerService.Instance.CurrentMediaTime;
|
||||
float length = PlayerService.Instance.CurrentMediaLength;
|
||||
|
||||
float trackTime = length * position;
|
||||
|
||||
Sync sync = new Sync()
|
||||
{
|
||||
TrackTime = trackTime,
|
||||
ServerTime = time.Ticks
|
||||
};
|
||||
await responseStream.WriteAsync(sync);
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user