private IEnumerator resolveContinuously()
    {
        while (resolve)
        {
            var results = resolver.results();

            foreach (var item in knownStreams)
            {
                if (!results.Any(r => r.name().Equals(item.name())))
                {
                    OnStreamLost?.Invoke(item);
                }
            }

            // remove lost streams from cache
            knownStreams.RemoveAll(s => !results.Any(r => r.name().Equals(s.name())));

            // add new found streams to the cache
            foreach (var item in results)
            {
                if (!knownStreams.Any(s => s.name() == item.name() && s.type() == item.type()))
                {
                    knownStreams.Add(item);
                    OnStreamFound?.Invoke(item);
                }
            }

            yield return(new WaitForSecondsRealtime(0.1f));
        }
        yield return(null);
    }
Exemplo n.º 2
0
        public string macaroon; // used to call /v1/invoices/subscribe

        public async void Start()
        {
            using (var client = new HttpClient())
            {
                // The HTTP stream should stay open until closed by either server or client
                client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);

                var request = new HttpRequestMessage(HttpMethod.Get, url);
                request.Headers.Add("Grpc-Metadata-macaroon", macaroon);    // macaroon should be provided from lnd

//#if DEBUG
                // This disables SSL certificate validation
                ServicePointManager.ServerCertificateValidationCallback +=
                    (sender, cert, chain, sslPolicyErrors) => true;
//#endif
                using (var response = await client.SendAsync(
                           request,
                           HttpCompletionOption.ResponseHeadersRead))
                {
                    using (var body = await response.Content.ReadAsStreamAsync())
                        using (var reader = new StreamReader(body))
                        {
                            IsLive = true;
                            //need to read and chop message
                            try
                            {
                                while (!reader.EndOfStream)
                                {
                                    string       line = reader.ReadLine();
                                    InvoiceEvent e    = JsonSerializer.Deserialize <InvoiceEvent>(line);//SimpleJson.DeserializeObject<InvoiceEvent>(line);

                                    //Notify listeners of new invoice
                                    InvoicePaid?.Invoke(e.result);
                                }
                            }
                            catch (Exception e)
                            {
                                // TODO: check that the exception type is actually from a closed stream.
                                Debug.WriteLine(e.Message);
                                IsLive = false;
                                StreamLost?.Invoke(this);
                            }
                        }
                }
            }
        }