2023-09-17 15:45:28 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2023-09-28 20:35:50 -07:00
|
|
|
//import 'package:grpc/grpc_web.dart';
|
|
|
|
|
import 'package:grpc/grpc.dart';
|
|
|
|
|
import 'package:logger/logger.dart';
|
2023-09-17 15:45:28 -07:00
|
|
|
import 'package:ui/call.dart';
|
2023-09-28 20:35:50 -07:00
|
|
|
import 'package:ui/gen/signaler_service.pbgrpc.dart';
|
|
|
|
|
import 'package:ui/session_service.dart';
|
2023-09-17 15:45:28 -07:00
|
|
|
|
2023-09-28 20:35:50 -07:00
|
|
|
void main() async {
|
|
|
|
|
Logger logger = Logger();
|
|
|
|
|
logger.i("Establishing connection...");
|
|
|
|
|
final channel = ClientChannel(
|
2023-10-03 16:17:34 -07:00
|
|
|
'home.chathaway.codes',
|
2024-01-10 21:39:06 -08:00
|
|
|
//port: 8080,
|
2023-10-03 16:17:34 -07:00
|
|
|
//options: const ChannelOptions(credentials: ChannelCredentials.insecure()),
|
2023-09-28 20:35:50 -07:00
|
|
|
channelShutdownHandler: () {
|
|
|
|
|
logger.e("Channel shutdown unexpectedly");
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-01-10 21:39:06 -08:00
|
|
|
logger.i("Have connection, making stub");
|
2023-09-28 20:35:50 -07:00
|
|
|
final stub = SignalerServiceClient(channel);
|
2024-01-10 21:39:06 -08:00
|
|
|
final sessionService = SessionService(stub);
|
|
|
|
|
logger.i("Have stub, starting app");
|
|
|
|
|
runApp(MyApp(
|
|
|
|
|
stub,
|
|
|
|
|
sessionService,
|
|
|
|
|
));
|
2023-09-17 15:45:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2023-09-28 20:35:50 -07:00
|
|
|
final SignalerServiceClient client;
|
|
|
|
|
final SessionService sessionService;
|
|
|
|
|
const MyApp(this.client, this.sessionService, {super.key});
|
2023-09-17 15:45:28 -07:00
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'Flutter Demo',
|
|
|
|
|
theme: ThemeData(
|
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
),
|
2023-09-28 20:35:50 -07:00
|
|
|
home: MyHomePage(
|
|
|
|
|
client,
|
|
|
|
|
sessionService,
|
|
|
|
|
title: 'Home Sensors',
|
2023-10-03 16:17:34 -07:00
|
|
|
home: "Sunnyvale",
|
2023-09-28 20:35:50 -07:00
|
|
|
),
|
2023-09-17 15:45:28 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
2023-09-28 20:35:50 -07:00
|
|
|
final SignalerServiceClient client;
|
|
|
|
|
final SessionService sessionService;
|
|
|
|
|
final String home;
|
|
|
|
|
const MyHomePage(this.client, this.sessionService,
|
|
|
|
|
{super.key, required this.title, required this.home});
|
2023-09-17 15:45:28 -07:00
|
|
|
|
|
|
|
|
// This widget is the home page of your application. It is stateful, meaning
|
|
|
|
|
// that it has a State object (defined below) that contains fields that affect
|
|
|
|
|
// how it looks.
|
|
|
|
|
|
|
|
|
|
// This class is the configuration for the state. It holds the values (in this
|
|
|
|
|
// case the title) provided by the parent (in this case the App widget) and
|
|
|
|
|
// used by the build method of the State. Fields in a Widget subclass are
|
|
|
|
|
// always marked "final".
|
|
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2023-09-28 20:35:50 -07:00
|
|
|
String topMessage = "Creating session...";
|
|
|
|
|
List<Call> camerasToRender = [];
|
2023-10-03 16:17:34 -07:00
|
|
|
List<Widget> samples = [];
|
2023-09-28 20:35:50 -07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_getSession();
|
|
|
|
|
_listCameras();
|
2023-10-03 16:17:34 -07:00
|
|
|
_listSensors();
|
2023-09-28 20:35:50 -07:00
|
|
|
}
|
2023-09-17 15:45:28 -07:00
|
|
|
|
2023-09-28 20:35:50 -07:00
|
|
|
_getSession() async {
|
|
|
|
|
var token = await widget.sessionService.getAuthToken(widget.home);
|
|
|
|
|
topMessage = "Created session $token";
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 16:17:34 -07:00
|
|
|
_listSensors() async {
|
|
|
|
|
var callOptions = CallOptions(metadata: {
|
|
|
|
|
'Authorization': await widget.sessionService.getAuthToken(widget.home)
|
|
|
|
|
});
|
|
|
|
|
var resp = await widget.client
|
|
|
|
|
.listSamples(ListSamplesRequest(), options: callOptions);
|
|
|
|
|
|
|
|
|
|
for (var sample in resp.samples) {
|
|
|
|
|
samples
|
|
|
|
|
.add(Text("${sample.type}: ${sample.reading} on ${sample.cameraId}"));
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 20:35:50 -07:00
|
|
|
_listCameras() async {
|
|
|
|
|
var callOptions = CallOptions(metadata: {
|
|
|
|
|
'Authorization': await widget.sessionService.getAuthToken(widget.home)
|
2023-09-17 15:45:28 -07:00
|
|
|
});
|
2023-09-28 20:35:50 -07:00
|
|
|
var cameras = await widget.client
|
|
|
|
|
.listCameras(ListCamerasRequest(), options: callOptions);
|
|
|
|
|
|
|
|
|
|
for (var camera in cameras.cameras) {
|
|
|
|
|
camerasToRender.add(Call(
|
|
|
|
|
widget.client,
|
|
|
|
|
widget.sessionService,
|
|
|
|
|
cameraID: camera.identifier,
|
|
|
|
|
home: widget.home,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
2023-09-17 15:45:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
// This method is rerun every time setState is called, for instance as done
|
|
|
|
|
// by the _incrementCounter method above.
|
|
|
|
|
//
|
|
|
|
|
// The Flutter framework has been optimized to make rerunning build methods
|
|
|
|
|
// fast, so that you can just rebuild anything that needs updating rather
|
|
|
|
|
// than having to individually change instances of widgets.
|
|
|
|
|
return Scaffold(
|
2023-10-03 16:17:34 -07:00
|
|
|
appBar: AppBar(
|
|
|
|
|
// TRY THIS: Try changing the color here to a specific color (to
|
|
|
|
|
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
|
|
|
|
// change color while the other colors stay the same.
|
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
|
// Here we take the value from the MyHomePage object that was created by
|
|
|
|
|
// the App.build method, and use it to set our appbar title.
|
|
|
|
|
title: Text(widget.title),
|
|
|
|
|
),
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
// Center is a layout widget. It takes a single child and positions it
|
|
|
|
|
// in the middle of the parent.
|
|
|
|
|
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Text(topMessage),
|
|
|
|
|
] +
|
|
|
|
|
samples +
|
|
|
|
|
camerasToRender,
|
|
|
|
|
),
|
|
|
|
|
));
|
2023-09-17 15:45:28 -07:00
|
|
|
}
|
|
|
|
|
}
|