add: basic webrtc is working
This commit is contained in:
+68
-23
@@ -1,12 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
//import 'package:grpc/grpc_web.dart';
|
||||
import 'package:grpc/grpc.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:ui/call.dart';
|
||||
import 'package:ui/gen/signaler_service.pbgrpc.dart';
|
||||
import 'package:ui/session_service.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
void main() async {
|
||||
Logger logger = Logger();
|
||||
logger.i("Establishing connection...");
|
||||
final channel = ClientChannel(
|
||||
'192.168.0.65',
|
||||
port: 8080,
|
||||
options: const ChannelOptions(credentials: ChannelCredentials.insecure()),
|
||||
channelShutdownHandler: () {
|
||||
logger.e("Channel shutdown unexpectedly");
|
||||
},
|
||||
);
|
||||
final stub = SignalerServiceClient(channel);
|
||||
runApp(MyApp(stub, SessionService(stub)));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
final SignalerServiceClient client;
|
||||
final SessionService sessionService;
|
||||
const MyApp(this.client, this.sessionService, {super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
@@ -32,13 +50,22 @@ class MyApp extends StatelessWidget {
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
home: MyHomePage(
|
||||
client,
|
||||
sessionService,
|
||||
title: 'Home Sensors',
|
||||
home: "home1234",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final SignalerServiceClient client;
|
||||
final SessionService sessionService;
|
||||
final String home;
|
||||
const MyHomePage(this.client, this.sessionService,
|
||||
{super.key, required this.title, required this.home});
|
||||
|
||||
// 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
|
||||
@@ -56,17 +83,38 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
String topMessage = "Creating session...";
|
||||
List<Call> camerasToRender = [];
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_getSession();
|
||||
_listCameras();
|
||||
}
|
||||
|
||||
_getSession() async {
|
||||
var token = await widget.sessionService.getAuthToken(widget.home);
|
||||
topMessage = "Created session $token";
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_listCameras() async {
|
||||
var callOptions = CallOptions(metadata: {
|
||||
'Authorization': await widget.sessionService.getAuthToken(widget.home)
|
||||
});
|
||||
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(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -87,18 +135,15 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: const Center(
|
||||
body: Column(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Call(
|
||||
host: '',
|
||||
),
|
||||
|
||||
children: <Widget>[
|
||||
Text(topMessage),
|
||||
] +
|
||||
camerasToRender,
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user