using System; using System.Threading.Tasks; using System.Threading; using Aurora.Proto.Party; using Aurora.Utils; namespace Aurora.Services.Server.Controllers { public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase { public override Task GetEvents(GetEventsRequest request, Grpc.Core.IServerStreamWriter responseStream, Grpc.Core.ServerCallContext context) { 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 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(null); } } }