Skip to content

Commit

Permalink
Add stream options handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery committed Nov 27, 2024
1 parent c9bc4fa commit bba1a32
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/src/media/stream/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,43 @@ class StreamManager {
return client;
}

Future<List<Resolution>> getStreamOptions(String name) async {
final sanitizedName = _getValidSDPTrackName(name);
try {
final response = await _client.getStreamOptions(GetStreamOptionsRequest()..name = sanitizedName);
_logger.d('Got options for stream named $name');
return response.resolutions;
} catch (e) {
_logger.e('Failed to get options for stream named $name');
return [];
}
}

Future<void> setStreamOptions(String name, int width, int height) async {
final sanitizedName = _getValidSDPTrackName(name);
final resolution = Resolution()
..width = width
..height = height;
try {
await _client.setStreamOptions(SetStreamOptionsRequest()
..name = sanitizedName
..resolution = resolution);
_logger.d('Set options for stream named $name');
} catch (e) {
_logger.e('Failed to set options for stream named $name');
}
}

Future<void> resetStreamOptions(String name) async {
final sanitizedName = _getValidSDPTrackName(name);
try {
await _client.setStreamOptions(SetStreamOptionsRequest()..name = sanitizedName);
_logger.d('Reset options for stream named $name');
} catch (e) {
_logger.e('Failed to reset options for stream named $name');
}
}

/// Request that a stream get added to the WebRTC channel
Future<void> _add(String name) async {
final sanitizedName = _getValidSDPTrackName(name);
Expand Down
16 changes: 16 additions & 0 deletions lib/src/robot/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:logger/logger.dart';
import '../gen/common/v1/common.pb.dart';
import '../gen/google/protobuf/struct.pb.dart';
import '../gen/robot/v1/robot.pbgrpc.dart' as rpb;
import '../gen/stream/v1/stream.pbgrpc.dart';
import '../media/stream/client.dart';
import '../resource/base.dart';
import '../resource/manager.dart';
Expand Down Expand Up @@ -299,6 +300,21 @@ class RobotClient {
return _streamManager.getStreamClient(name);
}

/// Get the stream options for a stream with the given name.
Future<List<Resolution>> getStreamOptions(String name) async {
return _streamManager.getStreamOptions(name);
}

/// Set the options for a stream with the given name.
Future<void> setStreamOptions(String name, int width, int height) {
return _streamManager.setStreamOptions(name, width, height);
}

// Reset the options for a stream with the given name.
Future<void> resetStreamOptions(String name) {
return _streamManager.resetStreamOptions(name);
}

/// Get app-related information about the machine.
///
/// ```
Expand Down

0 comments on commit bba1a32

Please sign in to comment.