Skip to content

Commit 725c24e

Browse files
committed
feat: create a gRPC-Web Flutter
1 parent 52b8ef6 commit 725c24e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

client/lib/grpc_channel_native.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'package:grpc/grpc.dart';
2+
3+
ClientChannel getKkweonOktetoChannel() {
4+
return ClientChannel('ingress-kkweon.cloud.okteto.net');
5+
}

client/lib/grpc_channel_web.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import 'package:grpc/grpc_web.dart';
2+
3+
GrpcWebClientChannel getKkweonOktetoChannel() {
4+
// return GrpcWebClientChannel.xhr(Uri.parse("https://envoy-kkweon.cloud.okteto.net"));
5+
return GrpcWebClientChannel.xhr(Uri.parse("https://envoy-kkweon.cloud.okteto.net/"));
6+
}

client/lib/service.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:grpc/grpc.dart';
2+
import 'package:pr12er/grpc_channel_native.dart'
3+
if (dart.library.js) 'package:pr12er/grpc_channel_web.dart';
24
import 'package:pr12er/protos/pkg/pr12er/messages.pb.dart';
35

46
import 'protos/pkg/pr12er/service.pbgrpc.dart';
@@ -7,7 +9,7 @@ class GrpcClient {
79
// Use _getLocalhostChannel(port: 9000) to use the localhost version.
810
// NOTE: localhost only works in iOS.
911
final Pr12erServiceClient _client =
10-
Pr12erServiceClient(_getKkweonOktetoChannel());
12+
Pr12erServiceClient(getKkweonOktetoChannel());
1113

1214
Future<String> sendMessage(String message) async {
1315
final request = HelloRequest()..body = message;
@@ -31,15 +33,11 @@ class GrpcClient {
3133
}
3234
}
3335

34-
ClientChannel _getKkweonOktetoChannel() {
35-
return ClientChannel('ingress-kkweon.cloud.okteto.net');
36-
}
37-
3836
// ignore: unused_element
3937
ClientChannel _getLocalhostChannel({required int port}) {
4038
return ClientChannel(
4139
'localhost',
4240
port: port,
4341
options: const ChannelOptions(credentials: ChannelCredentials.insecure()),
4442
);
45-
}
43+
}

0 commit comments

Comments
 (0)