import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:grpc/grpc_web.dart';

final grpcChannelProvider = Provider<GrpcWebClientChannel>((ref) {
  String backendURL = dotenv.env['SOFTPLAYER_BACKEND_URL']!;
  final GrpcWebClientChannel channel = GrpcWebClientChannel.xhr(
    Uri.parse(backendURL),
  );

  ref.onDispose(() async {
    await channel.shutdown();
  });

  return channel;
});
