dial function Viam SDK
Connect to a robot at the provided address with the given options
Implementation
Future<ClientChannelBase> dial(String address, DialOptions? options, String Function() sessionCallback) async {
final opts = options ?? DialOptions();
_logger = _newDialLogger(opts.logOutput);
final dialSW = Stopwatch()..start();
_logger.i('Connecting to address $address');
if (opts.attemptMdns) {
final mdnsSW = Stopwatch()..start();
try {
final mdnsUri = await _searchMdns(address);
// Let downstream calls know when mdns was used. This is helpful to inform
// when determining if we want to use the external auth credentials for the signaling
// in cases where the external signaling is the same as the external auth. For mdns
// this isn't the case.
final dialOptsCopy = opts.._usingMdns = true;
dialOptsCopy.webRtcOptions ??= DialWebRtcOptions();
dialOptsCopy.webRtcOptions?.signalingServerAddress = mdnsUri;
return await _dialWebRtc(address, dialOptsCopy, sessionCallback);
} on NotLocalAddressException catch (e) {
_logger.d(e.toString());
} catch (e) {
_logger.d('Error dialing with mDNS; falling back to other methods', error: e);
}
mdnsSW.stop();
_logger.d('STATS: mDNS discovery took ${mdnsSW.elapsed}');
}
bool disableWebRtc = opts.webRtcOptions?.disable ?? false;
if (address.contains('.local.') || address.contains('localhost')) {
disableWebRtc = true;
}
final Future<ClientChannelBase> chan;
if (disableWebRtc) {
chan = _dialDirectGrpc(address, opts, sessionCallback);
} else {
chan = _dialWebRtc(address, opts, sessionCallback);
}
dialSW.stop();
_logger.d('STATS: dial function took ${dialSW.elapsed}');
return chan.timeout(opts.timeout);
}