announce method
Registers (or re-registers) an endpoint and returns its hub slot.
Set publish false for a consumer-only endpoint: it still needs a slot
and a routing identity so the hub can deliver to it, but it must not
appear in publisher discovery.
Implementation
Future<int> announce(PeerDescriptor descriptor, {bool publish = true}) async {
final endpointId = descriptor.endpointId;
final known = _slots[endpointId];
_send(
WsFrame(known == null ? WsControl.hello : WsControl.update, {
'peer': descriptor.toJson(),
'publish': publish,
}).encode(),
);
if (known != null) return known;
final completer = _pendingSlots.putIfAbsent(endpointId, Completer<int>.new);
return completer.future.timeout(const Duration(seconds: 10));
}