Skip to content

Commit

Permalink
Merge pull request #207 from GreenTeaProgrammers/fix/frontend/nursery…
Browse files Browse the repository at this point in the history
…/stream

Fix/frontend/nursery/stream
  • Loading branch information
lovelovetrb authored Feb 23, 2024
2 parents f58ae55 + 1a060a6 commit 9d1c929
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions frontend/where_child_bus/lib/pages/camera_page/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class _CameraPageState extends State<CameraPage> {
VehicleEvent _vehicleEvent = VehicleEvent.VEHICLE_EVENT_GET_ON;
final Location location = Location();

ClientChannel? _videoChannel;
ClientChannel? _locationChannel;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -70,35 +73,35 @@ class _CameraPageState extends State<CameraPage> {

Future<void> streamBusVideo(
Stream<StreamBusVideoRequest> requestStream) async {
final channel = ClientChannel(
_videoChannel = ClientChannel(
appConfig.grpcEndpoint,
port: appConfig.grpcPort,
options: const ChannelOptions(),
);
final grpcClient = BusServiceClient(channel);
final grpcClient = BusServiceClient(_videoChannel!);
developer.log("ServiceClient created");
final res = grpcClient.streamBusVideo(requestStream);

try {
await for (var response in res.asStream()) {
await for (var response in res) {
developer.log("Received response: $response", name: "CameraPage");
await _playAudio(response);
}
} catch (error) {
developer.log("Caught Error:", error: error, name: "StreamBusVideo");
} finally {
await channel.shutdown();
await _videoChannel!.shutdown();
}
}

Future<void> _streamCoordinate(
Stream<SendLocationContinuousRequest> requestStream) async {
final channel = ClientChannel(
_locationChannel = ClientChannel(
appConfig.grpcEndpoint,
port: appConfig.grpcPort,
options: const ChannelOptions(),
);
final grpcClient = BusServiceClient(channel);
final grpcClient = BusServiceClient(_locationChannel!);
developer.log("ServiceClient created");
final res = grpcClient.sendLocationContinuous(requestStream);

Expand All @@ -109,7 +112,7 @@ class _CameraPageState extends State<CameraPage> {
} catch (error) {
developer.log("Caught Error:", error: error);
} finally {
await channel.shutdown();
await _locationChannel!.shutdown();
}
}

Expand Down Expand Up @@ -282,6 +285,8 @@ class _CameraPageState extends State<CameraPage> {
_controller.dispose();
_streamController.close();
_locationStream.close();
_videoChannel?.shutdown();
_locationChannel?.shutdown();
super.dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/where_child_bus/lib/util/api/bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Future<void> streamBusVideo(Stream<StreamBusVideoRequest> requestStream) async {

try {
developer.log("Streamed video to server");
await for (var response in res.asStream()) {
await for (var response in res) {
developer.log("Received response: $response");
}
} catch (error) {
Expand Down

0 comments on commit 9d1c929

Please sign in to comment.