diff --git a/lib/src/hub_client.dart b/lib/src/hub_client.dart index 0f06397..b8173c5 100644 --- a/lib/src/hub_client.dart +++ b/lib/src/hub_client.dart @@ -50,38 +50,23 @@ class HubClient { final grpc_hub.HubClient _hub; final grpc_hub.HubAdminClient _admin; - HubClient({this.endpoint = const HubEndpoint()}) - : _channel = ClientChannel( - endpoint.host, - port: endpoint.port, - options: ChannelOptions( - credentials: endpoint.secure - ? const ChannelCredentials.secure() - : const ChannelCredentials.insecure(), - ), - ), - _hub = grpc_hub.HubClient( - ClientChannel( - endpoint.host, - port: endpoint.port, - options: ChannelOptions( - credentials: endpoint.secure - ? const ChannelCredentials.secure() - : const ChannelCredentials.insecure(), - ), - ), - ), - _admin = grpc_hub.HubAdminClient( - ClientChannel( - endpoint.host, - port: endpoint.port, - options: ChannelOptions( - credentials: endpoint.secure - ? const ChannelCredentials.secure() - : const ChannelCredentials.insecure(), - ), - ), - ); + HubClient._(this.endpoint, this._channel) + : _hub = grpc_hub.HubClient(_channel), + _admin = grpc_hub.HubAdminClient(_channel); + + factory HubClient({HubEndpoint endpoint = const HubEndpoint()}) { + final channel = ClientChannel( + endpoint.host, + port: endpoint.port, + options: ChannelOptions( + credentials: endpoint.secure + ? const ChannelCredentials.secure() + : const ChannelCredentials.insecure(), + idleTimeout: const Duration(minutes: 5), + ), + ); + return HubClient._(endpoint, channel); + } /// Liveness probe. Returns true when the hub responds with /// SERVING. False on any failure (includes connection refused).