@@ -149,19 +149,33 @@ class ThingDiscovery extends Stream<ThingDescription>
149149
150150 Stream <ThingDescription > _discoverWithCoreLinkFormat (Uri uri) async * {
151151 // TODO: Remove additional quotes once fixed in CoAP library
152- yield * _performCoreLinkFormatDiscovery ('"wot.thing"' , uri)
153- .map (_discoverDirectly)
154- .flatten ();
152+ yield * _performCoreLinkFormatDiscovery ('"wot.thing"' , uri).transform (
153+ StreamTransformer .fromBind (
154+ (stream) async * {
155+ await for (final uris in stream) {
156+ final futures = uris.map (_servient.requestThingDescription);
157+ yield * Stream .fromFutures (futures);
158+ }
159+ },
160+ ),
161+ );
155162 }
156163
157164 Stream <ThingDescription > _discoverfromCoreResourceDirectory (Uri uri) async * {
158165 // TODO: Remove additional quotes once fixed in CoAP library
159166 yield * _performCoreLinkFormatDiscovery ('"core.rd-lookup-res"' , uri)
160- .map (_discoverWithCoreLinkFormat)
161- .flatten ();
167+ .transform (
168+ StreamTransformer .fromBind ((stream) async * {
169+ await for (final uris in stream) {
170+ for (final uri in uris) {
171+ yield * _discoverWithCoreLinkFormat (uri);
172+ }
173+ }
174+ }),
175+ );
162176 }
163177
164- Stream <Uri > _performCoreLinkFormatDiscovery (
178+ Stream <Iterable < Uri > > _performCoreLinkFormatDiscovery (
165179 String resourceType,
166180 Uri uri,
167181 ) async * {
@@ -171,24 +185,13 @@ class ThingDiscovery extends Stream<ThingDescription>
171185
172186 await for (final coreWebLink
173187 in client.discoverWithCoreLinkFormat (discoveryUri)) {
174- final Iterable <Uri > parsedUris;
175-
176188 try {
177- parsedUris = await _filterCoreWebLinks (resourceType, coreWebLink);
189+ final parsedUris = await _filterCoreWebLinks (resourceType, coreWebLink);
190+ yield parsedUris.where (discoveredUris.add);
178191 } on Exception catch (exception) {
179192 yield * Stream .error (exception);
180193 continue ;
181194 }
182-
183- for (final parsedUri in parsedUris) {
184- final uriAdded = discoveredUris.add (parsedUri);
185-
186- if (! uriAdded) {
187- continue ;
188- }
189-
190- yield parsedUri;
191- }
192195 }
193196 }
194197
0 commit comments