Skip to content

Commit

Permalink
fix first observe response not being handled (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgesanfz authored Jun 9, 2024
1 parent 0a536ce commit 318f5d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/src/coap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,7 @@ class CoapClient {
},
);
final relation = CoapObserveClientRelation(request, responseStream);
final resp = await _waitForResponse(request, responseStream);
if (!resp.hasOption<ObserveOption>()) {
relation.isCancelled = true;
}
relation.checkObserve();
isObserving = true;
return relation;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/src/coap_observe_client_relation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class CoapObserveClientRelation extends Stream<CoapResponse> {
return requestToken.equals(responseToken);
}

void checkObserve() {
_filteredStream.first.then((resp) {
if (!resp.hasOption<ObserveOption>()) {
isCancelled = true;
}
});
}

bool _cancelled = false;

/// Cancelled
Expand Down

0 comments on commit 318f5d6

Please sign in to comment.