import 'package:grpc/grpc_or_grpcweb.dart';
import 'package:ui/gen/signaler_service.pbgrpc.dart';

class SessionService {
  final SignalerServiceClient _stub;
  final Map<String, ResponseFuture<AuthToken>> _authTokens = {};

  SessionService(this._stub);

  Future<String> getAuthToken(String cameraID) async {
    var val = await _authTokens.putIfAbsent(cameraID,
        () => _stub.createAuthToken(CreateAuthTokenRequest(home: cameraID)));
    return "Bearer ${val.token}";
  }
}
