find method
Returns the record only when GET /agent/discover answers the same scheme.
Implementation
Future<AgentLinkAnnouncement?> find(final String protocolScheme) async {
final file = fileFor(protocolScheme);
if (!file.existsSync()) {
return null;
}
final Object? decoded;
try {
decoded = jsonDecode(await file.readAsString());
} on Object {
return null;
}
if (decoded is! Map) {
return null;
}
final announcement = AgentLinkAnnouncement.fromJson(
Map<String, Object?>.from(decoded),
);
if (announcement.protocolScheme != protocolScheme) {
return null;
}
final live = await _discoverLive(announcement.discover);
if (live == null || live.protocolScheme != protocolScheme) {
return null;
}
return live;
}