Skip to content

Commit

Permalink
DOCS-2592: Add RobotClient example snippets (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
JessamyT authored Jul 10, 2024
1 parent eda8b8c commit 1fe01eb
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/src/robot/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ class RobotClient {
RobotClient._();

/// 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),
/// );
/// }
/// ```
static Future<RobotClient> atAddress(String url, RobotClientOptions options) async {
Logger.level = options.logLevel;
final client = RobotClient._();
Expand All @@ -85,6 +102,10 @@ class RobotClient {
}

/// Refresh the resources of this robot
///
/// ```
/// await machine.refresh();
/// ```
Future<void> refresh() async {
final ResourceNamesResponse response = await _client.resourceNames(ResourceNamesRequest());
if (setEquals(response.resources.toSet(), resourceNames.toSet())) {
Expand Down Expand Up @@ -201,6 +222,10 @@ class RobotClient {
}

/// Close the connection to the Robot. This should be done to release resources on the robot.
///
/// ```
/// await machine.close();
/// ```
Future<void> close() async {
_logger.d('Closing RobotClient connection');
try {
Expand All @@ -219,16 +244,21 @@ class RobotClient {
}
}

/// Get a connected resource by its [ResourceName]
/// Get a connected resource by its [ResourceName].
T getResource<T>(ResourceName name) {
return _manager.getResource<T>(name);
}

/// Get a WebRTC stream client with the given name
/// Get a WebRTC stream client with the given name.
StreamClient getStream(String name) {
return _streamManager.getStreamClient(name);
}

/// Get app-related information about the machine.
///
/// ```
/// var metadata = await machine.getCloudMetadata();
/// ```
Future<CloudMetadata> getCloudMetadata() async {
return await _client.getCloudMetadata(GetCloudMetadataRequest());
}
Expand Down

0 comments on commit 1fe01eb

Please sign in to comment.