From 318f5d66289a04cb03b6971e3152683ce2ef81c1 Mon Sep 17 00:00:00 2001 From: jorgesanfz <155391333+jorgesanfz@users.noreply.github.com> Date: Sun, 9 Jun 2024 14:14:58 +0200 Subject: [PATCH] fix first observe response not being handled (#195) --- lib/src/coap_client.dart | 5 +---- lib/src/coap_observe_client_relation.dart | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/coap_client.dart b/lib/src/coap_client.dart index 0c8f8f4d..8a47a521 100644 --- a/lib/src/coap_client.dart +++ b/lib/src/coap_client.dart @@ -525,10 +525,7 @@ class CoapClient { }, ); final relation = CoapObserveClientRelation(request, responseStream); - final resp = await _waitForResponse(request, responseStream); - if (!resp.hasOption()) { - relation.isCancelled = true; - } + relation.checkObserve(); isObserving = true; return relation; } diff --git a/lib/src/coap_observe_client_relation.dart b/lib/src/coap_observe_client_relation.dart index 0d1db0c7..79b268c9 100644 --- a/lib/src/coap_observe_client_relation.dart +++ b/lib/src/coap_observe_client_relation.dart @@ -55,6 +55,14 @@ class CoapObserveClientRelation extends Stream { return requestToken.equals(responseToken); } + void checkObserve() { + _filteredStream.first.then((resp) { + if (!resp.hasOption()) { + isCancelled = true; + } + }); + } + bool _cancelled = false; /// Cancelled