2020-01-20 21:55:12 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
2020-02-02 15:26:47 +00:00
|
|
|
using System.Threading;
|
2020-02-02 21:49:01 +00:00
|
|
|
using Aurora.Proto.Party;
|
2020-02-02 15:26:47 +00:00
|
|
|
using Aurora.Utils;
|
2020-01-20 21:55:12 +00:00
|
|
|
|
|
|
|
namespace Aurora.Services.Server.Controllers
|
|
|
|
{
|
|
|
|
public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase
|
|
|
|
{
|
|
|
|
public override Task GetEvents(GetEventsRequest request, Grpc.Core.IServerStreamWriter<BaseEvent> responseStream, Grpc.Core.ServerCallContext context)
|
|
|
|
{
|
2020-02-02 15:26:47 +00:00
|
|
|
string peerId = Misc.Combine(new string[] { context.Peer, request.Parent });
|
|
|
|
Console.WriteLine(string.Format("SERVER - Events request received from peer: {0}", peerId));
|
|
|
|
|
|
|
|
AutoResetEvent are = new AutoResetEvent(false);
|
|
|
|
Action<BaseEvent> callback = (BaseEvent bEvent) =>
|
|
|
|
{
|
|
|
|
Console.WriteLine(string.Format("SERVER - Event fired for peer: {0}", peerId));
|
|
|
|
//TODO need to remove callback if stream no longer exists IE. Client crashed or stopped
|
|
|
|
responseStream.WriteAsync(bEvent);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Action cancelled = () =>
|
|
|
|
{
|
|
|
|
are.Set();
|
|
|
|
};
|
|
|
|
|
|
|
|
this._eventManager.AddEventHandler(callback, cancelled, Misc.Combine(new string[] { context.Peer, request.Parent }));
|
|
|
|
are.WaitOne();
|
|
|
|
return Task.FromResult<object>(null);
|
2020-01-20 21:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|