smm_mobile/lib/client.dart

31 lines
885 B
Dart
Raw Permalink Normal View History

2024-11-30 19:11:03 +00:00
import 'package:grpc/grpc.dart';
import 'generated/smm_core.pbgrpc.dart';
class AuthenticationInterceptor extends ClientInterceptor {
Future<void> _provider(Map<String, String> metadata, String uri) async {
metadata['Authorization'] = "Y3JhYjpjcmFi";
}
@override
ResponseFuture<R> interceptUnary<Q, R>(
ClientMethod<Q, R> method, Q request, CallOptions options, invoker) {
return super.interceptUnary(method, request,
options.mergedWith(CallOptions(providers: [_provider])), invoker);
}
}
class SmmCoreTerminalClient {
late final ClientChannel channel;
late final SmmCoreClient stub;
SmmCoreTerminalClient() {
channel = ClientChannel(
'0.0.0.0',
port: 8080,
options: ChannelOptions(credentials: ChannelCredentials.insecure()),
);
stub = SmmCoreClient(channel, interceptors: [AuthenticationInterceptor()]);
}
}