atAddress static method

Future<RobotClient> atAddress(
  1. String url,
  2. RobotClientOptions options
)

Connect to a robot at the specified address with the provided options.

// Example usage; see your machine's CONNECT tab for your machine's address and API key.

Future<void> connectToViam() async {
  const host = '<YOUR ROBOT ADDRESS>.viam.cloud';
  // Replace "<API-KEY-ID>" (including brackets) with your machine's API key ID
  const apiKeyID = '<API-KEY-ID>';
  // Replace "<API-KEY>" (including brackets) with your machine's API key
  const apiKey = '<API-KEY>';

  final machine = await RobotClient.atAddress(
    host,
    RobotClientOptions.withApiKey(apiKeyID, apiKey),
  );
}

Implementation

static Future<RobotClient> atAddress(String url, RobotClientOptions options) async {
  Logger.level = options.logLevel;
  final client = RobotClient._();
  client._address = url;
  client._options = options;
  client._channel = await dial(url, options.dialOptions, () => client._sessionsClient.metadata());
  client._sessionsClient = SessionsClient(client._channel, options.enableSessions);
  client._sessionsClient.start();
  client._client = rpb.RobotServiceClient(client._channel);
  client._streamManager = StreamManager(client._channel as WebRtcClientChannel);
  await client.refresh();
  client._startCheckConnectionTask();
  return client;
}