@@ -61,6 +61,13 @@ class DialOptions {
6161 /// Whether the connection was made using mDNS
6262 bool _usingMdns = false ;
6363
64+ /// The number of connection attempts to make when first dialing. If set to zero or a negative
65+ /// integer, will attempt to reconnect forever.
66+ int initialConnectionAttempts = 3 ;
67+
68+ // The timeout to use for initial connection attempts.
69+ Duration initialConnectionAttemptTimeout = const Duration (seconds: 10 );
70+
6471 /// Timeout is the timeout for dial.
6572 Duration timeout = const Duration (seconds: 10 );
6673
@@ -123,6 +130,35 @@ class DialWebRtcOptions {
123130 String ? signalingAccessToken;
124131}
125132
133+ /// {@category Viam SDK}
134+ /// Initial connection to a robot at the provided address with the given options, allowing for specifying of initial connection attempt count and timeout
135+ Future <ClientChannelBase > dialInitial (String address, DialOptions ? options, String Function () sessionCallback) async {
136+ final opts = options ?? DialOptions ();
137+
138+ int numAttempts = opts.initialConnectionAttempts;
139+ if (numAttempts == 0 ) {
140+ numAttempts = - 1 ;
141+ }
142+
143+ final timeout = opts.timeout;
144+ opts.timeout = opts.initialConnectionAttemptTimeout;
145+
146+ while (numAttempts != 0 ) {
147+ try {
148+ final channel = await dial (address, opts, sessionCallback);
149+ opts.timeout = timeout;
150+ return channel;
151+ } catch (e) {
152+ numAttempts -= 1 ;
153+ if (numAttempts == 0 ) {
154+ rethrow ;
155+ }
156+ }
157+ }
158+
159+ throw Exception ('unreachable' );
160+ }
161+
126162/// {@category Viam SDK}
127163/// Connect to a robot at the provided address with the given options
128164Future <ClientChannelBase > dial (String address, DialOptions ? options, String Function () sessionCallback) async {
0 commit comments