Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-9250] - Add stream options handlers #308

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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