Skip to content

Commit

Permalink
fix:チャンネルを閉じるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
KikyoNanakusa committed Feb 23, 2024
1 parent fd6ed0e commit 1a060a6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 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,12 +73,12 @@ 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);

Expand All @@ -87,18 +90,18 @@ class _CameraPageState extends State<CameraPage> {
} 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

0 comments on commit 1a060a6

Please sign in to comment.