Example #1
0
        public LocalBinder(Connection connection, TObj obj)
            : base(connection)
        {
            lInvoker = new LocalInvoker <TObj>();
            Object   = obj;

            Connection.OnReceive += async d =>
            {
                var msg = Request.FromJson(d);
                if (msg.IsEmpty)
                {
                    return;
                }

                var result = await lInvoker.InvokeAsync(Object, msg);

                await Connection.SendAsync(result.ToJson());
            };

            Connection.OnClose += (s, d) =>
            {
                try { (Object as IDisposable)?.Dispose(); }
                catch (Exception ex) { Connection.InvokeOnError(ex); }

                return(Task.FromResult(true));
            };
        }
 public Task <Response> InvokeRequest(Request request)
 {
     return(lInvoker.InvokeAsync(Object, request));
 }