Esempio n. 1
0
        private async Task <WCSessionData> CreateSession()
        {
            var data = new WcSessionRequestRequest(ClientMetadata, clientId, ChainId);

            this._handshakeId = data.ID;

            await SendRequest(data, this._handshakeTopic);

            TaskCompletionSource <WCSessionData> eventCompleted =
                new TaskCompletionSource <WCSessionData>(TaskCreationOptions.None);

            //Listen for the _handshakeId response
            //The response will be of type WCSessionRequestResponse
            Events.ListenForResponse <WCSessionRequestResponse>(this._handshakeId, HandleSessionResponse);

            //Listen for the "connect" event triggered by 'HandleSessionResponse' above
            //This will have the type WCSessionData
            Events.ListenFor <WCSessionData>("connect",
                                             (sender, @event) => { eventCompleted.SetResult(@event.Response); });

            var response = await eventCompleted.Task;

            return(response);
        }
Esempio n. 2
0
        public async Task Subscribe <T>(string topic, EventHandler <JsonRpcResponseEvent <T> > callback) where T : JsonRpcResponse
        {
            await Subscribe(topic);

            _eventDelegator.ListenFor(topic, callback);
        }